def test_dict_org(self): """_dict_org turns our org structure into a json payload.""" expected_single_org_payload = { 'sub_orgs': [], 'owners': [{ 'first_name': 'Johnny', 'last_name': 'Energy', 'email': '*****@*****.**', 'id': self.user.pk}], 'number_of_users': 1, 'name': 'my org', 'display_significant_figures': 2, 'display_units_area': 'ft**2', 'display_units_eui': 'kBtu/ft**2/year', 'user_role': 'owner', 'is_parent': True, 'mapquest_api_key': '', 'display_meter_units': Organization._default_display_meter_units, 'thermal_conversion_assumption': Organization.US, 'parent_id': self.org.pk, 'org_id': self.org.pk, 'id': self.org.pk, 'user_is_owner': True, 'cycles': [{ 'num_taxlots': 0, 'num_properties': 0, 'name': str(self.cal_year_name), 'cycle_id': self.cycle.pk }], 'created': self.org.created.strftime('%Y-%m-%d'), 'comstock_enabled': False, } org_payload = _dict_org(self.fake_request, [self.org]) self.assertEqual(len(org_payload), 1) self.assertDictEqual(org_payload[0], expected_single_org_payload) # Now let's make sure that we pick up related buildings correctly. for x in range(10): ps = PropertyState.objects.create(organization=self.org) ps.promote(self.cycle) ps.save() for x in range(5): ts = TaxLotState.objects.create(organization=self.org) ts.promote(self.cycle) ts.save() expected_single_org_payload['cycles'] = [{ 'num_taxlots': 5, 'num_properties': 10, 'name': self.cal_year_name, 'cycle_id': self.cycle.pk }] self.assertDictEqual( _dict_org(self.fake_request, [self.org])[0], expected_single_org_payload )
def test_dict_org(self): """_dict_org turns our org structure into a json payload.""" expected_single_org_payload = { 'sub_orgs': [], 'owners': [{ 'first_name': u'Johnny', 'last_name': u'Energy', 'email': u'*****@*****.**', 'id': self.user.pk}], 'number_of_users': 1, 'name': 'my org', 'user_role': 'owner', 'is_parent': True, 'parent_id': self.org.pk, 'org_id': self.org.pk, 'id': self.org.pk, 'user_is_owner': True, 'cycles': [{ 'num_taxlots': 0, 'num_properties': 0, 'name': self.cal_year_name, 'cycle_id': self.cycle.pk }], 'created': self.org.created.strftime('%Y-%m-%d'), } org_payload = _dict_org(self.fake_request, [self.org]) self.assertEqual(len(org_payload), 1) self.assertDictEqual(org_payload[0], expected_single_org_payload) # Now let's make sure that we pick up related buildings correctly. for x in range(10): ps = PropertyState.objects.create(organization=self.org) ps.promote(self.cycle) ps.save() for x in range(5): ts = TaxLotState.objects.create(organization=self.org) ts.promote(self.cycle) ts.save() expected_single_org_payload['cycles'] = [{ 'num_taxlots': 5, 'num_properties': 10, 'name': self.cal_year_name, 'cycle_id': self.cycle.pk }] self.assertDictEqual( _dict_org(self.fake_request, [self.org])[0], expected_single_org_payload )
def test_dic_org_w_member_in_parent_and_child(self): """What happens when a user has a role in parent and child.""" new_org = Organization.objects.create(name="sub") new_org.parent_org = self.org new_org.save() new_org.add_member(self.user) new_cycle = Cycle.objects.filter(organization=new_org).first() expected_multiple_org_payload = { 'sub_orgs': [{ 'sub_orgs': [], 'owners': [{ 'first_name': u'Johnny', 'last_name': u'Energy', 'email': u'*****@*****.**', 'id': self.user.pk}], 'number_of_users': 1, 'name': 'sub', 'user_role': 'owner', 'is_parent': False, 'parent_id': self.org.pk, 'org_id': new_org.pk, 'id': new_org.pk, 'user_is_owner': True, 'cycles': [{ 'num_taxlots': 0, 'num_properties': 0, 'name': self.cal_year_name, 'cycle_id': new_cycle.pk }], 'created': self.org.created.strftime('%Y-%m-%d'), }], 'owners': [{ 'first_name': u'Johnny', 'last_name': u'Energy', 'email': u'*****@*****.**', 'id': self.user.pk}], 'number_of_users': 1, 'name': 'my org', 'user_role': 'owner', 'is_parent': True, 'parent_id': self.org.pk, 'org_id': self.org.pk, 'id': self.org.pk, 'user_is_owner': True, 'cycles': [{ 'num_taxlots': 0, 'num_properties': 0, 'name': self.cal_year_name, 'cycle_id': self.cycle.pk }], 'created': self.org.created.strftime('%Y-%m-%d'), } org_payload = _dict_org(self.fake_request, Organization.objects.all()) self.assertEqual(len(org_payload), 2) self.assertDictEqual(org_payload[0], expected_multiple_org_payload)
def test_dic_org_w_member_in_parent_and_child(self): """What happens when a user has a role in parent and child.""" new_org, _, _ = create_organization(self.user, "sub") new_org.parent_org = self.org new_org.save() new_cycle = Cycle.objects.filter(organization=new_org).first() expected_multiple_org_payload = { 'sub_orgs': [{ 'sub_orgs': [], 'owners': [{ 'first_name': 'Johnny', 'last_name': 'Energy', 'email': '*****@*****.**', 'id': self.user.pk }], 'number_of_users': 1, 'name': 'sub', 'user_role': 'owner', 'is_parent': False, 'mapquest_api_key': '', 'display_meter_units': Organization._default_display_meter_units, 'thermal_conversion_assumption': Organization.US, 'parent_id': self.org.pk, 'org_id': new_org.pk, 'id': new_org.pk, 'user_is_owner': True, 'display_units_area': 'ft**2', 'display_units_eui': 'kBtu/ft**2/year', 'display_significant_figures': 2, 'cycles': [{ 'num_taxlots': 0, 'num_properties': 0, 'name': str(self.cal_year_name), 'cycle_id': new_cycle.pk }], 'created': self.org.created.strftime('%Y-%m-%d'), }], 'owners': [{ 'first_name': 'Johnny', 'last_name': 'Energy', 'email': '*****@*****.**', 'id': self.user.pk }], 'number_of_users': 1, 'name': 'my org', 'user_role': 'owner', 'is_parent': True, 'mapquest_api_key': '', 'display_meter_units': Organization._default_display_meter_units, 'thermal_conversion_assumption': Organization.US, 'parent_id': self.org.pk, 'org_id': self.org.pk, 'id': self.org.pk, 'user_is_owner': True, 'display_significant_figures': 2, 'display_units_area': 'ft**2', 'display_units_eui': 'kBtu/ft**2/year', 'cycles': [{ 'num_taxlots': 0, 'num_properties': 0, 'name': str(self.cal_year_name), 'cycle_id': self.cycle.pk }], 'created': self.org.created.strftime('%Y-%m-%d'), } org_payload = _dict_org(self.fake_request, Organization.objects.all()) self.assertEqual(len(org_payload), 2) self.assertDictEqual(org_payload[0], expected_multiple_org_payload)