Exemple #1
0
    def test_get_timeseries_w_offset_and_num(self):
        """"make sure we support offsets and number of results."""
        meter = Meter.objects.create(
            name='test', energy_type=ELECTRICITY, energy_units=KILOWATT_HOURS
        )

        now = datetime.datetime.utcnow()
        for i in range(100):
            TimeSeries.objects.create(
                begin_time=now,
                end_time=now,
                cost=23,
                meter=meter
            )

        fake_request = FakeRequest(
            {'meter_id': meter.pk, 'offset': 20, 'num': '5'},
            method='GET',
            user=self.fake_user,
            body=json.dumps({
                'organization_id': self.org.pk,
            })
        )

        resp = json.loads(meters.get_timeseries(fake_request).content)

        first_timeseries_pk = TimeSeries.objects.all()[0].pk
        # Make sure that our offset worked properly
        self.assertEqual(
            resp['timeseries'][0]['pk'], 20 + first_timeseries_pk
        )
        self.assertEqual(len(resp['timeseries']), 5)
Exemple #2
0
    def test_get_timeseries(self):
        """We get all the times series for a meter."""
        meter = Meter.objects.create(
            name='test', energy_type=ELECTRICITY, energy_units=KILOWATT_HOURS
        )

        now = datetime.datetime.utcnow()
        for i in range(100):
            TimeSeries.objects.create(
                begin_time=now,
                end_time=now,
                cost=23,
                meter=meter
            )

        fake_request = FakeRequest(
            data={'meter_id': meter.pk},
            method='GET',
            user=self.fake_user,
            body=json.dumps({
                'organization_id': self.org.pk,
            })
        )

        resp = json.loads(meters.get_timeseries(fake_request).content)

        smallest_pk = TimeSeries.objects.all()[0].pk
        self.assertEqual(resp['timeseries'][0]['pk'], smallest_pk)
        self.assertEqual(len(resp['timeseries']), 12)
Exemple #3
0
    def test_get_timeseries(self):
        """We get all the times series for a meter."""
        meter = Meter.objects.create(
            name='test', energy_type=ELECTRICITY, energy_units=KILOWATT_HOURS
        )

        now = datetime.datetime.utcnow()
        for i in range(100):
            TimeSeries.objects.create(
                begin_time=now,
                end_time=now,
                cost=23,
                meter=meter
            )

        fake_request = FakeRequest(
            data={'meter_id': meter.pk},
            method='GET',
            user=self.fake_user,
            body=json.dumps({
                'organization_id': self.org.pk,
            })
        )

        resp = json.loads(meters.get_timeseries(fake_request).content)

        smallest_pk = TimeSeries.objects.all()[0].pk
        self.assertEqual(resp['timeseries'][0]['pk'], smallest_pk)
        self.assertEqual(len(resp['timeseries']), 12)
Exemple #4
0
    def test_get_timeseries_w_offset_and_num(self):
        """"make sure we support offsets and number of results."""
        meter = Meter.objects.create(
            name='test', energy_type=ELECTRICITY, energy_units=KILOWATT_HOURS
        )

        now = datetime.datetime.utcnow()
        for i in range(100):
            TimeSeries.objects.create(
                begin_time=now,
                end_time=now,
                cost=23,
                meter=meter
            )

        fake_request = FakeRequest(
            {'meter_id': meter.pk, 'offset': 20, 'num': '5'},
            method='GET',
            user=self.fake_user,
            body=json.dumps({
                'organization_id': self.org.pk,
            })
        )

        resp = json.loads(meters.get_timeseries(fake_request).content)

        first_timeseries_pk = TimeSeries.objects.all()[0].pk
        # Make sure that our offset worked properly
        self.assertEqual(
            resp['timeseries'][0]['pk'], 20 + first_timeseries_pk
        )
        self.assertEqual(len(resp['timeseries']), 5)