diff --git a/app/app/api/endpoints.py b/app/app/api/endpoints.py index 69f15ff..2182f7a 100644 --- a/app/app/api/endpoints.py +++ b/app/app/api/endpoints.py @@ -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(): diff --git a/app/app/templates/base.html b/app/app/templates/base.html index 5089365..bf22c19 100644 --- a/app/app/templates/base.html +++ b/app/app/templates/base.html @@ -7,7 +7,7 @@ {% endif %} -
Home Home
+
Home

{% block content %}{% endblock %} diff --git a/app/app/templates/index.html b/app/app/templates/index.html index 14ade2c..530f350 100644 --- a/app/app/templates/index.html +++ b/app/app/templates/index.html @@ -1,7 +1,13 @@ {% extends "base.html" %} {% block content %} -

Hi from app!

+

This is IoT Cloud Framework

+

This application doesn't have web interface and it uses browser only for registration:

+ +

For all other functions of application and more information, please take a look at GitHub repository of the project

{% if error %}

Error: {{ error }} {% endif %} diff --git a/app/app/templates/publish.html b/app/app/templates/publish.html deleted file mode 100644 index fd81031..0000000 --- a/app/app/templates/publish.html +++ /dev/null @@ -1,28 +0,0 @@ -{% extends "base.html" %} - -{% block content %} -

- {{ form.hidden_tag() }} -

- {{ form.topic.label }}
- {{ form.topic(size=32) }} -

-

- {{ form.message.label }}
- {{ form.message(size=32) }} -

-

{{ form.submit() }}

-
- {% if error %} -

Error: {{ error }} - {% endif %} - {% with messages = get_flashed_messages() %} - {% if messages %} -

- {% endif %} - {% endwith %} -{% endblock %} \ No newline at end of file diff --git a/app/app/web/forms.py b/app/app/web/forms.py index e73d5fb..e69de29 100644 --- a/app/app/web/forms.py +++ b/app/app/web/forms.py @@ -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') diff --git a/app/app/web/views.py b/app/app/web/views.py index d31f550..e0a21a5 100644 --- a/app/app/web/views.py +++ b/app/app/web/views.py @@ -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) diff --git a/tests/test_basic.py b/tests/test_basic.py index 492e4d7..295c266 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -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): @@ -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",