示例#1
0
    def setUp(self):
        user_details = {
            'username': '******',
            'password': '******',
            'email': '*****@*****.**'
        }
        self.user = User.objects.create_user(**user_details)
        self.user.generate_key()
        self.org = Organization.objects.create()
        OrganizationUser.objects.create(user=self.user, organization=self.org)

        cb = CanonicalBuilding(active=True)
        cb.save()
        b = SEEDFactory.building_snapshot(canonical_building=cb,
                                          property_name='ADMIN BUILDING',
                                          address_line_1='100 Admin St')
        cb.canonical_snapshot = b
        cb.save()
        b.super_organization = self.org
        b.save()
        self.building = b

        self.api_url = reverse_lazy('seed:get_building')
        self.params = {
            'building_id': b.pk,
            'organization_id': self.org.pk,
        }
        self.auth_string = '%s:%s' % (self.user.username, self.user.api_key)
示例#2
0
    def setUp(self):
        user_details = {
            'username': '******',
            'password': '******',
            'email': '*****@*****.**'
        }
        self.user = User.objects.create_user(**user_details)
        self.user.generate_key()
        self.org = Organization.objects.create()
        OrganizationUser.objects.create(user=self.user, organization=self.org)

        cb = CanonicalBuilding(active=True)
        cb.save()
        b = SEEDFactory.building_snapshot(canonical_building=cb,
                                          property_name='ADMIN BUILDING',
                                          address_line_1='100 Admin St')
        cb.canonical_snapshot = b
        cb.save()
        b.super_organization = self.org
        b.save()
        self.building = b

        self.api_url = reverse_lazy('api:v1:get_building')
        self.params = {
            'building_id': cb.pk,
            'organization_id': self.org.pk,
        }
        auth_string = base64.urlsafe_b64encode('{}:{}'.format(
            self.user.username, self.user.api_key))
        self.auth_string = 'Basic {}'.format(auth_string)
示例#3
0
 def setUp(self):
     self.snapshots = []
     for x in range(50):
         cb = CanonicalBuilding()
         cb.save()
         b = SEEDFactory.building_snapshot(canonical_building=cb)
         b.extra_data = {'my new field': 'something extra'}
         b.save()
         self.snapshots.append(b)
示例#4
0
 def setUp(self):
     self.snapshots = []
     for x in range(50):
         cb = CanonicalBuilding()
         cb.save()
         b = SEEDFactory.building_snapshot(canonical_building=cb)
         b.extra_data = {
             'my new field': 'something extra'
         }
         b.save()
         self.snapshots.append(b)
示例#5
0
    def test_seach_active_canonicalbuildings(self):
        """ tests the search_buidlings method used throughout the app for only
            returning active CanonicalBuilding BuildingSnapshot insts.
        """
        # arrange
        NUMBER_ACTIVE = 50
        NUMBER_INACTIVE = 25
        NUMBER_WITHOUT_CANONICAL = 5
        NUMBER_PER_PAGE = 10
        for i in range(NUMBER_ACTIVE):
            cb = CanonicalBuilding(active=True)
            cb.save()
            b = SEEDFactory.building_snapshot(canonical_building=cb)
            cb.canonical_snapshot = b
            cb.save()
            b.super_organization = self.org
            b.save()
        for i in range(NUMBER_INACTIVE):
            cb = CanonicalBuilding(active=False)
            cb.save()
            b = SEEDFactory.building_snapshot(canonical_building=cb)
            cb.canonical_snapshot = b
            cb.save()
            b.super_organization = self.org
            b.save()
        for i in range(NUMBER_WITHOUT_CANONICAL):
            b = SEEDFactory.building_snapshot()
            b.super_organization = self.org
            b.save()
        url = reverse_lazy("seed:search_buildings")
        post_data = {
            'filter_params': {},
            'number_per_page': NUMBER_PER_PAGE,
            'order_by': '',
            'page': 1,
            'q': '',
            'sort_reverse': False,
            'project_id': None,
        }

        # act
        response = self.client.post(
            url,
            content_type='application/json',
            data=json.dumps(post_data)
        )
        json_string = response.content
        data = json.loads(json_string)

        # assert
        self.assertEqual(
            BuildingSnapshot.objects.all().count(),
            NUMBER_ACTIVE + NUMBER_INACTIVE + NUMBER_WITHOUT_CANONICAL
        )
        self.assertEqual(data['status'], 'success')
        self.assertEqual(data['number_matching_search'], NUMBER_ACTIVE)
        self.assertEqual(data['number_returned'], NUMBER_PER_PAGE)
        self.assertEqual(len(data['buildings']), NUMBER_PER_PAGE)
示例#6
0
文件: test_api.py 项目: wanghp18/seed
    def setUp(self):
        user_details = {"username": "******", "password": "******", "email": "*****@*****.**"}
        self.user = User.objects.create_user(**user_details)
        self.user.generate_key()
        self.org = Organization.objects.create()
        OrganizationUser.objects.create(user=self.user, organization=self.org)

        cb = CanonicalBuilding(active=True)
        cb.save()
        b = SEEDFactory.building_snapshot(
            canonical_building=cb, property_name="ADMIN BUILDING", address_line_1="100 Admin St"
        )
        cb.canonical_snapshot = b
        cb.save()
        b.super_organization = self.org
        b.save()
        self.building = b

        self.api_url = reverse_lazy("seed:get_building")
        self.params = {"building_id": cb.pk, "organization_id": self.org.pk}
        self.auth_string = "%s:%s" % (self.user.username, self.user.api_key)
示例#7
0
    def setUp(self):
        user_details = {
            'username': '******',
            'password': '******',
            'email': '*****@*****.**'
        }
        self.user = User.objects.create_superuser(**user_details)
        self.org = Organization.objects.create()
        OrganizationUser.objects.create(user=self.user, organization=self.org)
        self.client.login(**user_details)

        import_record = ImportRecord.objects.create()
        import_file_1 = ImportFile.objects.create(
            import_record=import_record,
        )
        import_file_1.save()
        import_file_2 = ImportFile.objects.create(
            import_record=import_record,
        )
        import_file_2.save()
        cb = CanonicalBuilding(active=True)
        cb.save()
        parent_1 = SEEDFactory.building_snapshot(
            canonical_building=cb,
            gross_floor_area=None
        )
        cb.canonical_snapshot = parent_1
        cb.save()
        parent_1.super_organization = self.org
        parent_1.import_file = import_file_1
        parent_1.source_type = 2
        parent_1.save()

        cb = CanonicalBuilding(active=True)
        cb.save()
        parent_2 = SEEDFactory.building_snapshot(canonical_building=cb)
        cb.canonical_snapshot = parent_2
        cb.save()
        parent_2.super_organization = self.org
        parent_2.import_file = import_file_2
        parent_2.source_type = 3
        parent_2.save()

        self.import_record = import_record
        self.import_file_1 = import_file_1
        self.import_file_2 = import_file_2
        self.parent_1 = parent_1
        self.parent_2 = parent_2
示例#8
0
 def setUp(self):
     user_details = {
         'username': '******',
         'password': '******',
         'email': '*****@*****.**',
         'first_name': 'Johnny',
         'last_name': 'Energy',
     }
     self.user = User.objects.create_user(**user_details)
     self.org = Organization.objects.create(name='my org')
     self.org.add_member(self.user)
     self.client.login(**user_details)
     self.fake_request = FakeRequest(user=self.user)
     # arrange
     self.NUMBER_ACTIVE = 50
     NUMBER_INACTIVE = 25
     NUMBER_WITHOUT_CANONICAL = 5
     for i in range(self.NUMBER_ACTIVE):
         cb = CanonicalBuilding(active=True)
         cb.save()
         b = SEEDFactory.building_snapshot(canonical_building=cb)
         cb.canonical_snapshot = b
         cb.save()
         b.super_organization = self.org
         b.save()
     for i in range(NUMBER_INACTIVE):
         cb = CanonicalBuilding(active=False)
         cb.save()
         b = SEEDFactory.building_snapshot(canonical_building=cb)
         cb.canonical_snapshot = b
         cb.save()
         b.super_organization = self.org
         b.save()
     for i in range(NUMBER_WITHOUT_CANONICAL):
         b = SEEDFactory.building_snapshot()
         b.super_organization = self.org
         b.save()
 def setUp(self):
     user_details = {
         'username': '******',
         'password': '******',
         'email': '*****@*****.**',
         'first_name': 'Johnny',
         'last_name': 'Energy',
     }
     self.user = User.objects.create_user(**user_details)
     self.org = Organization.objects.create(name='my org')
     self.org.add_member(self.user)
     self.client.login(**user_details)
     self.fake_request = FakeRequest(user=self.user)
     # arrange
     self.NUMBER_ACTIVE = 50
     NUMBER_INACTIVE = 25
     NUMBER_WITHOUT_CANONICAL = 5
     for i in range(self.NUMBER_ACTIVE):
         cb = CanonicalBuilding(active=True)
         cb.save()
         b = SEEDFactory.building_snapshot(canonical_building=cb)
         cb.canonical_snapshot = b
         cb.save()
         b.super_organization = self.org
         b.save()
     for i in range(NUMBER_INACTIVE):
         cb = CanonicalBuilding(active=False)
         cb.save()
         b = SEEDFactory.building_snapshot(canonical_building=cb)
         cb.canonical_snapshot = b
         cb.save()
         b.super_organization = self.org
         b.save()
     for i in range(NUMBER_WITHOUT_CANONICAL):
         b = SEEDFactory.building_snapshot()
         b.super_organization = self.org
         b.save()
示例#10
0
 def setUp(self):
     self.snapshots = []
     for x in range(50):
         cb = CanonicalBuilding()
         cb.save()
         self.snapshots.append(SEEDFactory.building_snapshot(canonical_building=cb))
示例#11
0
    def _create_buildings(self):
        """
        Create 10 buildings in each child org.

        Also set one shared and one unshared field to a known value.
        """
        for _ in range(10):
            cb = CanonicalBuilding(active=True)
            cb.save()
            b = SEEDFactory.building_snapshot(canonical_building=cb,
                                              property_name='ADMIN BUILDING',
                                              address_line_1='100 Admin St')
            cb.canonical_snapshot = b
            cb.save()
            b.super_organization = self.parent_org
            b.save()
        for _ in range(10):
            cb = CanonicalBuilding(active=True)
            cb.save()
            b = SEEDFactory.building_snapshot(canonical_building=cb,
                                              property_name='ENG BUILDING',
                                              address_line_1='100 Eng St')
            cb.canonical_snapshot = b
            cb.save()
            b.super_organization = self.eng_org
            b.save()
        for _ in range(10):
            cb = CanonicalBuilding(active=True)
            cb.save()
            b = SEEDFactory.building_snapshot(canonical_building=cb,
                                              property_name='DES BUILDING',
                                              address_line_1='100 Des St')
            cb.canonical_snapshot = b
            cb.save()
            b.super_organization = self.des_org
            b.save()
示例#12
0
    def _create_buildings(self):
        """
        Create 10 buildings in each child org.

        Also set one shared and one unshared field to a known value.
        """
        for _ in range(10):
            cb = CanonicalBuilding(active=True)
            cb.save()
            b = SEEDFactory.building_snapshot(canonical_building=cb,
                                              property_name='ADMIN BUILDING',
                                              address_line_1='100 Admin St')
            cb.canonical_snapshot = b
            cb.save()
            b.super_organization = self.parent_org
            b.save()
        for _ in range(10):
            cb = CanonicalBuilding(active=True)
            cb.save()
            b = SEEDFactory.building_snapshot(canonical_building=cb,
                                              property_name='ENG BUILDING',
                                              address_line_1='100 Eng St')
            cb.canonical_snapshot = b
            cb.save()
            b.super_organization = self.eng_org
            b.save()
        for _ in range(10):
            cb = CanonicalBuilding(active=True)
            cb.save()
            b = SEEDFactory.building_snapshot(canonical_building=cb,
                                              property_name='DES BUILDING',
                                              address_line_1='100 Des St')
            cb.canonical_snapshot = b
            cb.save()
            b.super_organization = self.des_org
            b.save()