Skip to content

Commit

Permalink
Update landing page (index).
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Heinz committed Apr 15, 2019
1 parent 070ed70 commit 85add6f
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 97 deletions.
8 changes: 0 additions & 8 deletions app/app/api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@
from app.utils import http_json_response, check_missing_request_argument, is_valid_uuid, format_topic, validate_broker_password, is_number, create_payload


@api.route('/publish', methods=['POST'])
def publish_message():
message = request.args.get("ciphertext") + " " + request.args.get("tag")
topic = request.args.get("topic")
client.publish(topic, str(message))
return http_json_response()


@api.route('/user/broker_register', methods=['POST'])
@require_api_token()
def register_to_broker():
Expand Down
2 changes: 1 addition & 1 deletion app/app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% endif %}
</head>
<body>
<div>Home <a href="/">Home</a></div>
<div><a href="/">Home</a></div>
<hr>
{% block content %}{% endblock %}
</body>
Expand Down
8 changes: 7 additions & 1 deletion app/app/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{% extends "base.html" %}

{% block content %}
<h1>Hi from app!</h1>
<h1>This is IoT Cloud Framework</h1>
<p> This application doesn't have web interface and it uses browser only for registration: </p>
<ul>
<li><a href="https://{{ request.base_url.split(',')[1] }}login">https://{{ request.base_url.split(",")[1] }}login</a></li>
<li><a href="https://{{ request.base_url.split(',')[1] }}attr_auth/login">https://{{ request.base_url.split(",")[1] }}attr_auth/login</a></li>
</ul>
<p>For all other functions of application and more information, please take a look at <a href="https://github.com/MartinHeinz/IoT-Cloud">GitHub repository of the project</a></p>
{% if error %}
<p class=error><strong>Error: </strong> {{ error }}
{% endif %}
Expand Down
28 changes: 0 additions & 28 deletions app/app/templates/publish.html

This file was deleted.

9 changes: 0 additions & 9 deletions app/app/web/forms.py
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired


class PublishForm(FlaskForm):
topic = StringField('Topic', validators=[DataRequired()])
message = StringField('Message', validators=[DataRequired()])
submit = SubmitField('Publish')
18 changes: 1 addition & 17 deletions app/app/web/views.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
from flask import render_template, request, flash, redirect, url_for

from app.app_setup import client
from flask import render_template

from app.web import web
from app.web.forms import PublishForm


@web.route('/')
def index():
return render_template('index.html', title='Home')


@web.route('/publish', methods=['GET', 'POST'])
def publish():
form = PublishForm(request.form)
error = None
if request.method == 'POST':
if form.validate():
client.publish(form.topic.data, form.message.data)
flash('Message Send.')
return redirect(url_for('web.index', _scheme="https", _external=True))
error = "Incorrect Topic or Message."
return render_template('publish.html', title='Publish to Topic', form=form, error=error)
34 changes: 1 addition & 33 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_mqtt_client(app_and_ctx):

def test_index(client):
response = client.get('/')
assert "Hi from app!" in str(response.data)
assert "This is IoT Cloud Framework" in str(response.data)


def test_error_handler(client):
Expand All @@ -47,38 +47,6 @@ def test_error_handler(client):
assert (json_data["error"]) == SOMETHING_WENT_WRONG_MSG


def test_publish(client):
response = client.get('/publish')
assert response.status_code == 200

response = client.post('/publish', data=dict(
topic="",
message=""
), follow_redirects=False)
assert response.status_code == 200

response = client.post('/publish', data=dict(
topic="flask_test",
message="message"
), follow_redirects=False)
assert response.status_code == 302


def test_api_publish(client):
iv, ciphertext, tag = encrypt(
b'f\x9c\xeb Lj\x13n\x84B\xf5S\xb5\xdfnl53d\x10\x12\x92\x82\xe1\xe3~\xc8*\x16\x9f\xd69',
b"{\"data\": \"secret\"}",
b"authenticated but not encrypted payload"
)
response = client.post('/api/publish', query_string=dict(
ciphertext=str(base64.b64encode(ciphertext), 'utf-8'),
tag=str(base64.b64encode(tag), 'utf-8'),
topic="flask_test"
), follow_redirects=True)

assert response.status_code == 200


def test_api_user_register_broker(client, app_and_ctx, access_token_three):
data = {
"not-password": "non-empty",
Expand Down

0 comments on commit 85add6f

Please sign in to comment.