コード例 #1
0
 def test_temperature_history_non_empty_db(self):
     mock_temperature_store = mock.Mock(spec_set=db_store.TemperatureStore)
     mock_temperature_store.get.return_value = [
         db_store.TemperatureRecord(timestamp=datetime.datetime(
             2017, 4, 15, 10, 51, 0, tzinfo=pytz.utc),
                                    temperature=57.3),
         db_store.TemperatureRecord(timestamp=datetime.datetime(
             2017, 4, 15, 11, 39, 0, tzinfo=pytz.utc),
                                    temperature=68.2),
     ]
     app_client = app.create(image_indexer=None,
                             temperature_store=mock_temperature_store,
                             light_store=None,
                             soil_moisture_store=None,
                             humidity_store=None).test_client(self)
     response = app_client.get('/temperatureHistory.json')
     self.assertEqual(200, response.status_code)
     self.assertJsonEqual(
         """
         [
             {
                 "timestamp": "20170415T1051Z",
                 "temperature": 57.3
             },
             {
                 "timestamp": "20170415T1139Z",
                 "temperature": 68.2
             }
         ]
         """, response.data)
コード例 #2
0
 def test_light_history_empty_db(self):
     mock_light_store = mock.Mock(spec_set=db_store.LightStore)
     mock_light_store.get.return_value = []
     app_client = app.create(image_indexer=None,
                             temperature_store=None,
                             light_store=mock_light_store,
                             soil_moisture_store=None,
                             humidity_store=None).test_client(self)
     response = app_client.get('/lightHistory.json')
     self.assertEqual(200, response.status_code)
     self.assertJsonEqual("[]", response.data)
コード例 #3
0
 def test_images_empty_index(self):
     mock_image_indexer = mock.Mock(spec_set=images.Indexer)
     mock_image_indexer.index.return_value = []
     app_client = app.create(image_indexer=mock_image_indexer,
                             temperature_store=None,
                             light_store=None,
                             soil_moisture_store=None,
                             humidity_store=None).test_client(self)
     response = app_client.get('/images.json')
     self.assertEqual(200, response.status_code)
     self.assertJsonEqual("[]", response.data)
コード例 #4
0
 def test_images_non_empty_index(self):
     mock_image_indexer = mock.Mock(spec_set=images.Indexer)
     mock_image_indexer.index.return_value = [
         {
             'timestamp':
             datetime.datetime(2017, 4, 1, 18, 51, 0, tzinfo=pytz.utc),
             'filename':
             '2017-04-01T1851Z.jpg',
         },
         {
             'timestamp':
             datetime.datetime(2017, 4, 1, 18, 53, 0, tzinfo=pytz.utc),
             'filename':
             '2017-04-01T1853Z.jpg',
         },
     ]
     app_client = app.create(image_indexer=mock_image_indexer,
                             temperature_store=None,
                             light_store=None,
                             soil_moisture_store=None,
                             humidity_store=None).test_client(self)
     response = app_client.get('/images.json')
     self.assertEqual(200, response.status_code)
     self.assertJsonEqual(
         """
         [
           {
             "timestamp": "20170401T1851Z",
             "filename": "2017-04-01T1851Z.jpg"
           },
           {
             "timestamp": "20170401T1853Z",
             "filename": "2017-04-01T1853Z.jpg"
           }
         ]
         """, response.data)