Пример #1
0
    def test_get_meters_no_building(self):
        """We throw an error when there's no building id passed in."""
        expected = {"status": "error", "message": "No building id specified"}
        fake_request = FakeRequest({'building_id': None},
                                   user=self.fake_user,
                                   method='GET',
                                   body=json.dumps(
                                       {'organization_id': self.org.pk}))
        resp = meters.get_meters(fake_request)

        self.assertDictEqual(json.loads(resp.content), expected)
Пример #2
0
    def test_get_meters_no_building(self):
        """We throw an error when there's no building id passed in."""
        expected = {"status": "error", "message": "No building id specified"}
        fake_request = FakeRequest(
            {'building_id': None},
            user=self.fake_user,
            method='GET',
            body=json.dumps({'organization_id': self.org.pk})
        )
        resp = meters.get_meters(fake_request)

        self.assertDictEqual(json.loads(resp.content), expected)
Пример #3
0
    def test_get_meters(self):
        """We get a meter that we saved back."""
        bs = BuildingSnapshot.objects.create()
        bs.super_organization = self.org
        bs.save()

        meter = Meter.objects.create(
            name='tester', energy_type=ELECTRICITY, energy_units=KILOWATT_HOURS
        )
        meter.building_snapshot.add(bs)

        # NL Added custom_meter_id and canonical building.
        # TODO: Why is canonical building an array?
        expected = {
            'status': 'success',
            'building_id': bs.pk,
            'meters': [
                {
                    'name': meter.name,
                    'building_snapshot': [bs.pk],
                    'energy_units': KILOWATT_HOURS,
                    'energy_type': ELECTRICITY,
                    'pk': meter.pk,
                    'model': 'seed.meter',
                    'id': meter.pk,
                    'custom_meter_id': '',
                    'canonical_building': [],
                }
            ]
        }

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

        resp = meters.get_meters(fake_request)

        self.assertDictEqual(json.loads(resp.content), expected)
Пример #4
0
    def test_get_meters(self):
        """We get a meter that we saved back."""
        bs = BuildingSnapshot.objects.create()
        bs.super_organization = self.org
        bs.save()

        meter = Meter.objects.create(
            name='tester', energy_type=ELECTRICITY, energy_units=KILOWATT_HOURS
        )
        meter.building_snapshot.add(bs)

        expected = {
            'status': 'success',
            'building_id': bs.pk,
            'meters': [
                {
                    'name': meter.name,
                    'building_snapshot': [bs.pk],
                    'energy_units': KILOWATT_HOURS,
                    'energy_type': ELECTRICITY,
                    'pk': meter.pk,
                    'model': 'seed.meter',
                    'id': meter.pk
                }
            ]
        }

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

        resp = meters.get_meters(fake_request)

        self.assertDictEqual(json.loads(resp.content), expected)