def test_add_timeseries(self): """Adding time series works.""" meter = Meter.objects.create( name='test', energy_type=ELECTRICITY, energy_units=KILOWATT_HOURS ) fake_request = FakeRequest( method='POST', user=self.fake_user, body=json.dumps({ 'meter_id': meter.pk, 'organization_id': self.org.pk, 'timeseries': [ { 'begin_time': '2014-07-10T18:14:54.726', 'end_time': '2014-07-10T18:14:54.726', 'cost': 345, 'reading': 23.0, }, { 'begin_time': '2014-07-09T18:14:54.726', 'end_time': '2014-07-09T18:14:54.726', 'cost': 33, 'reading': 11.0, } ] }) ) self.assertEqual(TimeSeries.objects.all().count(), 0) resp = json.loads(meters.add_timeseries(fake_request).content) self.assertEqual(resp, {'status': 'success'}) self.assertEqual(TimeSeries.objects.all().count(), 2)
def test_add_timeseries(self): """Adding timeseries works.""" meter = Meter.objects.create( name='test', energy_type=ELECTRICITY, energy_units=KILOWATT_HOURS ) fake_request = FakeRequest( method='POST', user=self.fake_user, body=json.dumps({ 'meter_id': meter.pk, 'organization_id': self.org.pk, 'timeseries': [ { 'begin_time': '2014-07-10T18:14:54.726', 'end_time': '2014-07-10T18:14:54.726', 'cost': 345, 'reading': 23.0, }, { 'begin_time': '2014-07-09T18:14:54.726', 'end_time': '2014-07-09T18:14:54.726', 'cost': 33, 'reading': 11.0, } ] }) ) self.assertEqual(TimeSeries.objects.all().count(), 0) resp = json.loads(meters.add_timeseries(fake_request).content) self.assertEqual(resp, {'status': 'success'}) self.assertEqual(TimeSeries.objects.all().count(), 2)