import os from application import Application app = Application.get_instance('test') app.drop_db_if_exist() app.init_db() from data_models import Picture, Algorithm, Prediction from controllers import flask_app import pytest from freezegun import freeze_time import datetime import tempfile import json class TestPicture(): @pytest.fixture def image_id(self): return '234567890' @pytest.fixture def image_path(self): return '20181011/234567890.jpg' def test_picture_init(self, image_id): assert Picture(image_id=image_id).image_id == image_id def test_picture_create_image_id(self, image_id): assert Picture.create(image_id=image_id).image_id == image_id def test_picture_create_image_path(self, image_path): assert Picture.create(image_path=image_path).image_path == image_path
''' Mosquitto consumer. Read message from message queue new_prediction and save the data in the database. ''' import paho.mqtt.client as mqtt from application import Application from data_models import Prediction app = Application.get_instance() app.init_db() # The callback for when the client receives a CONNACK response from the server. def on_connect(client, userdata, flags, rc): print("Connected with result code " + str(rc)) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. client.subscribe('new_prediction') # The callback for when a PUBLISH message is received from the server. def on_message(client, userdata, msg): print('New message: %s' % msg.payload) Prediction.create_from_mq(msg.payload) client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message