def create__device(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" }, "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))
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))
def test_enable_collection_sharding(self, mock_command, mock_create_index): p = Persister() p.init_mongodb() p.enable_collection_sharding('admin_notifications') mock_create_index.assert_called_once() assert mock_command.call_count == 2
def test_init_mongodb_create_index(self, mock_create_index): p = Persister() p.init_mongodb('admin_notifications') assert mock_create_index.call_count == 3
def test_init_mongodb(self, mock_create_indexes): p = Persister() p.init_mongodb('admin_notifications') assert mock_create_indexes.called
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))