예제 #1
0
 async def test_render_post_reading_not_dict(self, loop):
     data = """{
         "timestamp": "2017-01-02T01:02:03.23232Z-05:00",
         "asset": "sensor2",
         "key": "80a43623-ebe5-40d6-8d80-3f892da9b3b4",
         "readings": "500"
     }"""
     with patch.object(coap_listen._LOGGER, "exception") as log_exception:
         with patch.object(Ingest, 'increment_discarded_readings', return_value=True) as ingest_discarded:
             with patch.object(Ingest, 'is_available', return_value=True) as is_ingest_available:
                 with pytest.raises(aiocoap.error.BadRequest) as excinfo:
                     request = message.Message(payload=cbor2.dumps(json.loads(data)), code=numbers.codes.Code.POST)
                     r = await CoAPIngest.render_post(request)
                 assert str(excinfo).endswith('readings must be a dictionary')
             assert 1 == ingest_discarded.call_count
             assert 1 == is_ingest_available.call_count
             assert 1 == log_exception.call_count
 async def test_render_post_sensor_values_ok(self):
     data = """{
         "timestamp": "2017-01-02T01:02:03.23232Z-05:00",
         "asset": "sensor1",
         "key": "80a43623-ebe5-40d6-8d80-3f892da9b3b4",
         "sensor_values": {
             "velocity": "500",
             "temperature": {
                 "value": "32",
                 "unit": "kelvin"
             }
         }
     }"""
     with patch.object(async_ingest,
                       'ingest_callback') as ingest_add_readings:
         request = message.Message(payload=cbor2.dumps(json.loads(data)),
                                   code=numbers.codes.Code.POST)
         r = await CoAPIngest.render_post(request)
         assert numbers.codes.Code.VALID == r.code
         assert '' == r.payload.decode()
         assert 1 == ingest_add_readings.call_count
예제 #3
0
 async def test_render_post_is_available_false(self, loop):
     data = """{
         "timestamp": "2017-01-02T01:02:03.23232Z-05:00",
         "asset": "sensor1",
         "key": "80a43623-ebe5-40d6-8d80-3f892da9b3b4",
         "readings": {
             "velocity": "500",
             "temperature": {
                 "value": "32",
                 "unit": "kelvin"
             }
         }
     }"""
     with patch.object(coap_listen._LOGGER, "exception") as log_exception:
         with patch.object(Ingest, 'increment_discarded_readings', return_value=True) as ingest_discarded:
             with patch.object(Ingest, 'is_available', return_value=False) as is_ingest_available:
                 with pytest.raises(aiocoap.error.ConstructionRenderableError) as excinfo:
                     request = message.Message(payload=cbor2.dumps(json.loads(data)), code=numbers.codes.Code.POST)
                     r = await CoAPIngest.render_post(request)
                 assert str(excinfo).endswith('{"busy": true}')
             assert 1 == ingest_discarded.call_count
             assert 1 == is_ingest_available.call_count
             assert 1 == log_exception.call_count
예제 #4
0
 async def test_render_post_sensor_values_ok(self, loop):
     data = """{
         "timestamp": "2017-01-02T01:02:03.23232Z-05:00",
         "asset": "sensor1",
         "key": "80a43623-ebe5-40d6-8d80-3f892da9b3b4",
         "sensor_values": {
             "velocity": "500",
             "temperature": {
                 "value": "32",
                 "unit": "kelvin"
             }
         }
     }"""
     with patch.object(Ingest, 'increment_discarded_readings', return_value=True) as ingest_discarded:
         with patch.object(Ingest, 'add_readings', return_value=asyncio.sleep(.1)) as ingest_add_readings:
             with patch.object(Ingest, 'is_available', return_value=True) as is_ingest_available:
                 request = message.Message(payload=cbor2.dumps(json.loads(data)), code=numbers.codes.Code.POST)
                 r = await CoAPIngest.render_post(request)
                 assert numbers.codes.Code.VALID == r.code
                 assert '' == r.payload.decode()
         assert 0 == ingest_discarded.call_count
         assert 1 == ingest_add_readings.call_count
         assert 1 == is_ingest_available.call_count