Exemple #1
0
 def test_handle_notification_no_timestamp(self):
     # raises exception because does not have "timestamp"
     with pytest.raises(Exception):
         p = Persister()
         message = json.dumps(
             {"ts": 1567704621, "metaAttrsFilter": {"shouldPersist": False}})
         p.handle_notification('admin', message)
Exemple #2
0
 def test_handle_notification_persisting(self):
     p = Persister()
     message = json.dumps({
         "timestamp": 1567704621,
         "metaAttrsFilter": {
             "shouldPersist": True
         }
     })
     p.handle_notification('admin', message)
def setup(transaction):

    _create_device = {
        "event": "create",
        "meta": {
            "service": "admin"
        },
        "data": {
            "id": "labtemp",
            "label": "Device 1",
            "templates": [1, 2, 3],
            "attrs": {},
            "created": "2018-02-06T10:43:40.890330+00:00"
        }
    }
    persister = Persister()
    persister.init_mongodb()
    persister.handle_event_devices("admin", json.dumps(_create_device))

    _update_data = {
        "metadata": {
            "deviceid": "labtemp",
            "protocol": "mqtt",
            "payload": "json",
            "timestamp": 1528226137452
        },
        "attrs": {
            "temperature": "22.12"
        }
    }
    persister.handle_event_data("admin", json.dumps(_update_data))

    _update_data['attrs']['temperature'] = "23.12"
    persister.handle_event_data("admin", json.dumps(_update_data))

    _new_tenant = {"tenant": "admin"}

    persister.handle_new_tenant("admin", json.dumps(_new_tenant))

    _notification = {
        "msgID": "12345",
        "timestamp": 1551111524,
        "metaAttrsFilter": {
            "level": 1,
            "shouldPersist": "True"
        },
        "message": "DEU ALGUMA COISA MUITO ERRADO",
        "subject": "debug"
    }

    persister.handle_notification("admin", json.dumps(_notification))
Exemple #4
0
 def test_handle_notification_invalid_json(self):
     p = Persister()
     message = "This is a string"
     assert p.handle_notification('admin', message) is None
Exemple #5
0
def setup(transaction):

    _create_device = {
        "event": "create",
        "meta": {
            "service": "admin"
        },
        "data": {
            "id": "b374a5",
            "label": "Device 1",
            "templates": [1, 2, 3],
            "attrs": {},
            "created": "2018-02-06T10:43:40.890330+00:00"
        }
    }
    persister = Persister()
    persister.init_mongodb()
    persister.handle_event_devices("admin", json.dumps(_create_device))

    _update_data = {
        "metadata": {
            "deviceid": "b374a5",
            "protocol": "mqtt",
            "payload": "json",
            "timestamp": 1528226137452
        },
        "attrs": {
            "temperature": "22.12",
            "pressure": "1013"
        }
    }
    persister.handle_event_data("admin", json.dumps(_update_data))

    _update_data['attrs']['temperature'] = "23.12"
    persister.handle_event_data("admin", json.dumps(_update_data))

    _update_data['attrs']['temperature'] = "24.10"
    persister.handle_event_data("admin", json.dumps(_update_data))

    _update_data['attrs']['pressure'] = "1033"
    persister.handle_event_data("admin", json.dumps(_update_data))

    _update_data['attrs']['pressure'] = "1053"
    persister.handle_event_data("admin", json.dumps(_update_data))

    _new_tenant = {"tenant": "admin"}

    persister.handle_new_tenant("admin", json.dumps(_new_tenant))

    _notification = {
        "msgID": "12345",
        "timestamp": 1550693872863,
        "metaAttrsFilter": {
            "level": 3,
            "shouldPersist": True
        },
        "message": "Something went wrong.",
        "subject": "user_notification",
    }

    persister.handle_notification("admin", json.dumps(_notification))