def setUp(self): user_details = { 'username': '******', 'password': '******', 'email': '*****@*****.**', 'first_name': 'Test', 'last_name': 'User', } self.user = User.objects.create_user(**user_details) self.org_a, _, _ = create_organization(self.user) self.org_b, _, _ = create_organization(self.user) cycle_a = FakeCycleFactory(organization=self.org_a, user=self.user).get_cycle(name="Cycle Org A") cycle_b = FakeCycleFactory(organization=self.org_b, user=self.user).get_cycle(name="Cycle Org B") self.analysis_a = ( FakeAnalysisFactory(organization=self.org_a, user=self.user).get_analysis( name='Quite neat', service=Analysis.BSYNCR, ) ) view_factory_a = FakePropertyViewFactory(cycle=cycle_a, organization=self.org_a, user=self.user) self.property_views_a = [ view_factory_a.get_property_view( # override unitted fields so that hashes are correct site_eui=ureg.Quantity( float(view_factory_a.fake.random_int(min=50, max=600)), "kilobtu / foot ** 2 / year" ), gross_floor_area=ureg.Quantity( float(view_factory_a.fake.random_number(digits=6)), "foot ** 2" ), ) for i in range(2)] view_factory_b = FakePropertyViewFactory(cycle=cycle_b, organization=self.org_b, user=self.user) self.property_views_b = [ view_factory_b.get_property_view( # override unitted fields so that hashes are correct site_eui=ureg.Quantity( float(view_factory_b.fake.random_int(min=50, max=600)), "kilobtu / foot ** 2 / year" ), gross_floor_area=ureg.Quantity( float(view_factory_b.fake.random_number(digits=6)), "foot ** 2" ), ) for i in range(2)]
def setUp(self): self.properties = [] self.maxDiff = None user_details = { 'username': '******', 'password': '******', } self.user = User.objects.create_superuser(email='*****@*****.**', **user_details) self.org, _, _ = create_organization(self.user) # create a default cycle self.cycle = Cycle.objects.filter(organization_id=self.org).first() self.property_factory = FakePropertyFactory( organization=self.org ) self.property_state_factory = FakePropertyStateFactory( organization=self.org ) self.property_view_factory = FakePropertyViewFactory( organization=self.org, user=self.user ) self.label_factory = FakeStatusLabelFactory( organization=self.org ) self.property_view = self.property_view_factory.get_property_view() self.urls = ['http://example.com', 'http://example.org'] self.client.login(**user_details)
def setUp(self): self.maxDiff = None user_details = { 'username': '******', 'password': '******', } self.user = User.objects.create_superuser(email='*****@*****.**', **user_details) self.org, _, _ = create_organization(self.user) self.property_view_factory = FakePropertyViewFactory( organization=self.org, user=self.user) self.ga_factory = FakeGreenAssessmentFactory(organization=self.org) self.gap_factory = FakeGreenAssessmentPropertyFactory( organization=self.org, user=self.user) self.assessment = self.ga_factory.get_green_assessment() self.property_view = self.property_view_factory.get_property_view() self.data = { 'source': 'test', 'status': 'complete', 'status_date': '2017-01-01', 'metric': 5, 'version': '0.1', 'date': '2016-01-01', 'eligibility': True, 'assessment': self.assessment, 'view': self.property_view, } self.urls = ['http://example.com', 'http://example.org']
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) # Fake Factories self.property_view_factory = FakePropertyViewFactory( organization=self.org) self.taxlot_view_factory = FakeTaxLotViewFactory(organization=self.org) self.note_factory = FakeNoteFactory(organization=self.org, user=self.user) self.client.login(**user_details) # create a property view with some notes self.pv = self.property_view_factory.get_property_view( organization=self.org) self.note1 = self.note_factory.get_note() self.note2 = self.note_factory.get_log_note() self.pv.notes.add(self.note1) self.pv.notes.add(self.note2) # create a taxlot with some views self.tl = self.taxlot_view_factory.get_taxlot_view( organization=self.org) self.note3 = self.note_factory.get_note() self.note4 = self.note_factory.get_log_note() self.tl.notes.add(self.note3) self.tl.notes.add(self.note4)
def setUp(self): self.maxDiff = None user_details = { 'username': '******', 'password': '******', } self.user = User.objects.create_superuser(email='*****@*****.**', **user_details) self.org = Organization.objects.create() OrganizationUser.objects.create(user=self.user, organization=self.org) self.audit_log_factory = FakePropertyAuditLogFactory( organization=self.org, user=self.user) self.property_factory = FakePropertyFactory(organization=self.org) self.property_state_factory = FakePropertyStateFactory( organization=self.org) self.property_view_factory = FakePropertyViewFactory( organization=self.org, user=self.user) self.ga_factory = FakeGreenAssessmentFactory(organization=self.org) self.gap_factory = FakeGreenAssessmentPropertyFactory( organization=self.org, user=self.user) self.label_factory = FakeStatusLabelFactory(organization=self.org) self.assessment = self.ga_factory.get_green_assessment() self.property_view = self.property_view_factory.get_property_view() self.gap_data = { 'source': 'test', 'status': 'complete', 'status_date': datetime.date(2017, 0o1, 0o1), 'metric': 5, 'version': '0.1', 'date': datetime.date(2016, 0o1, 0o1), 'eligibility': True, 'assessment': self.assessment, 'view': self.property_view, } self.urls = ['http://example.com', 'http://example.org']
def setUp(self): self.maxDiff = None user_details = { 'username': '******', 'password': '******', } self.user = User.objects.create_superuser(email='*****@*****.**', **user_details) self.org = Organization.objects.create() OrganizationUser.objects.create(user=self.user, organization=self.org) self.audit_log_factory = FakePropertyAuditLogFactory( organization=self.org, user=self.user) self.cycle_factory = FakeCycleFactory(organization=self.org, user=self.user) self.property_state_factory = FakePropertyStateFactory( organization=self.org) self.property_view_factory = FakePropertyViewFactory( organization=self.org, user=self.user) self.ga_factory = FakeGreenAssessmentFactory(organization=self.org) self.gap_factory = FakeGreenAssessmentPropertyFactory( organization=self.org, user=self.user) self.taxlot_property_factory = FakeTaxLotPropertyFactory( organization=self.org, user=self.user) self.taxlot_state_factory = FakeTaxLotStateFactory( organization=self.org) self.taxlot_view_factory = FakeTaxLotViewFactory(organization=self.org, user=self.user) self.assessment = self.ga_factory.get_green_assessment() self.cycle = self.cycle_factory.get_cycle() self.property_state = self.property_state_factory.get_property_state() self.property_view = self.property_view_factory.get_property_view( state=self.property_state, cycle=self.cycle) self.taxlot_state = self.taxlot_state_factory.get_taxlot_state() self.taxlot_view = self.taxlot_view_factory.get_taxlot_view( state=self.taxlot_state, cycle=self.cycle) self.audit_log = self.audit_log_factory.get_property_audit_log( state=self.property_state, view=self.property_view, record_type=AUDIT_USER_EDIT, description=json.dumps(['a', 'b'])) self.audit_log2 = self.audit_log_factory.get_property_audit_log( view=self.property_view) self.gap_data = { 'source': 'test', 'status': 'complete', 'status_date': datetime.date(2017, 0o1, 0o1), 'metric': 5, 'version': '0.1', 'date': datetime.date(2016, 0o1, 0o1), 'eligibility': True, 'assessment': self.assessment, 'view': self.property_view, } self.urls = ['http://example.com', 'http://example.org'] self.gap = self.gap_factory.get_green_assessment_property( **self.gap_data) self.serializer = PropertyViewAsStateSerializer( instance=self.property_view)
def setUp(self): selfvars = self.set_up(ASSESSED_RAW) self.user, self.org, self.import_file, self.import_record, self.cycle = selfvars self.property_factory = FakePropertyFactory(organization=self.org) self.property_state_factory = FakePropertyStateFactory( organization=self.org) self.property_view_factory = FakePropertyViewFactory( organization=self.org)
def setUp(self): self.maxDiff = None user_details = { 'username': '******', 'password': '******', } self.user = User.objects.create_superuser(email='*****@*****.**', **user_details) self.org, _, _ = create_organization(self.user) self.property_view_factory = FakePropertyViewFactory( organization=self.org, user=self.user)
def setUp(self): self.user = User.objects.create_superuser('*****@*****.**', '*****@*****.**', 'test_pass') self.org, _, _ = create_organization(self.user) # Fake Factories self.property_view_factory = FakePropertyViewFactory( organization=self.org) self.note_factory = FakeNoteFactory(organization=self.org, user=self.user)
def setUp(self): user_details = { 'username': '******', 'password': '******', } self.user = User.objects.create_superuser(email='*****@*****.**', **user_details) self.org = Organization.objects.create() OrganizationUser.objects.create(user=self.user, organization=self.org) # Fake Factories self.property_view_factory = FakePropertyViewFactory( organization=self.org) self.note_factory = FakeNoteFactory(organization=self.org, user=self.user)
def setUp(self): user_details = { 'username': '******', 'password': '******', } self.user = User.objects.create_superuser( email='*****@*****.**', **user_details ) self.org, _, _ = create_organization(self.user) self.client.login(**user_details) self.property_state_factory = FakePropertyStateFactory(organization=self.org) self.tax_lot_state_factory = FakeTaxLotStateFactory(organization=self.org) self.property_view_factory = FakePropertyViewFactory(organization=self.org) self.taxlot_view_factory = FakeTaxLotViewFactory(organization=self.org)
def setUp(self): user_details = { 'username': '******', 'password': '******', 'email': '*****@*****.**' } self.user = User.objects.create_superuser(**user_details) self.org, self.org_user, _ = create_organization(self.user) self.column_factory = FakeColumnFactory(organization=self.org) self.cycle_factory = FakeCycleFactory(organization=self.org, user=self.user) self.property_factory = FakePropertyFactory(organization=self.org) self.property_state_factory = FakePropertyStateFactory(organization=self.org) self.property_view_factory = FakePropertyViewFactory(organization=self.org) self.taxlot_state_factory = FakeTaxLotStateFactory(organization=self.org) self.cycle = self.cycle_factory.get_cycle( start=datetime(2010, 10, 10, tzinfo=timezone.get_current_timezone())) self.client.login(**user_details)
def test_task_create_analysis_property_views_creates_messages_for_failed_property_views( self): # Setup property_view = (FakePropertyViewFactory( organization=self.org, user=self.user).get_property_view()) bogus_property_view_id = -1 property_view_ids = [bogus_property_view_id, property_view.id] # Act task_create_analysis_property_views(self.analysis.id, property_view_ids) # Assert # a message for the bad property view should have been created message = AnalysisMessage.objects.get(analysis=self.analysis) self.assertTrue( f'Failed to copy property data for PropertyView ID {bogus_property_view_id}' in message.user_message)
def test_labels_inventory_specific_filter_endpoint_provides_IDs_for_records_where_label_is_applied(self): user = User.objects.create_superuser( email='*****@*****.**', username='******', password='******', ) organization_a, _, _ = create_organization(user, "test-organization-a") # Ensures that at least a single label exists to ensure that we are not # relying on auto-creation of labels for this test to pass. new_label = Label.objects.create( color="red", name="test_label-a", super_organization=organization_a, ) # Create 2 properties and 2 tax lots. Then, apply that label to one of each property_view_factory = FakePropertyViewFactory(organization=organization_a, user=user) p_view_1 = property_view_factory.get_property_view() p_view_1.labels.add(new_label) property_view_factory.get_property_view() taxlot_view_factory = FakeTaxLotViewFactory(organization=organization_a, user=user) tl_view_1 = taxlot_view_factory.get_taxlot_view() tl_view_1.labels.add(new_label) taxlot_view_factory.get_taxlot_view() client = APIClient() client.login(username=user.username, password='******') url = reverse('api:v3:properties-labels') response_a = client.post(url + '?organization_id={}'.format(organization_a.pk)) data = json.loads(response_a.content) for label in data: if label.get('name') != 'test_label-a': self.assertCountEqual(label.get('is_applied'), []) else: self.assertCountEqual(label.get('is_applied'), [p_view_1.id])
def setUp(self): user_details = { 'username': '******', 'password': '******', 'email': '*****@*****.**' } self.user = User.objects.create_superuser(**user_details) self.org, self.org_user, _ = create_organization(self.user) self.cycle_factory = FakeCycleFactory(organization=self.org, user=self.user) self.cycle = self.cycle_factory.get_cycle( start=datetime(2010, 10, 10, tzinfo=timezone.get_current_timezone()) ) self.property_factory = FakePropertyFactory(organization=self.org) self.property_state_factory = FakePropertyStateFactory(organization=self.org) self.property_view_factory = FakePropertyViewFactory(organization=self.org, cycle=self.cycle) self.taxlot_state_factory = FakeTaxLotStateFactory(organization=self.org) self.taxlot_view_factory = FakeTaxLotViewFactory(organization=self.org, cycle=self.cycle) # create 10 addresses that are exactly the same import_record = ImportRecord.objects.create(super_organization=self.org) self.import_file = ImportFile.objects.create( import_record=import_record, cycle=self.cycle, )
def setUp(self): user_details = { 'username': '******', 'password': '******', 'email': '*****@*****.**', 'first_name': 'Test', 'last_name': 'User', } self.user = User.objects.create_user(**user_details) self.org, _, _ = create_organization(self.user) property_state = ( FakePropertyStateFactory(organization=self.org).get_property_state( # fields required for analysis latitude=39.76550841416409, longitude=-104.97855661401148)) self.analysis_property_view = ( FakeAnalysisPropertyViewFactory( organization=self.org, user=self.user).get_analysis_property_view( property_state=property_state, # analysis args name='Quite neat', service=Analysis.BSYNCR, )) self.meter = Meter.objects.create( property=self.analysis_property_view.property, source=Meter.PORTFOLIO_MANAGER, source_id="Source ID", type=Meter.ELECTRICITY_GRID, ) tz_obj = timezone(TIME_ZONE) self.meter_reading = MeterReading.objects.create( meter=self.meter, start_time=make_aware(datetime(2018, 1, 1, 0, 0, 0), timezone=tz_obj), end_time=make_aware(datetime(2018, 1, 2, 0, 0, 0), timezone=tz_obj), reading=12345, source_unit='kWh', conversion_factor=1.00) # # Setup more properties with linked meters with 12 valid meter readings. # These properties, unmodified, should successfully run thorugh the bsyncr pipeline # property_view_factory = FakePropertyViewFactory(organization=self.org) self.good_property_views = [] self.num_good_property_views = 3 for i in range(self.num_good_property_views): pv = property_view_factory.get_property_view( # fields required for analysis latitude=39.76550841416409, longitude=-104.97855661401148, # override unitted fields so that hashes are correct site_eui=ureg.Quantity( float( property_view_factory.fake.random_int(min=50, max=600)), "kilobtu / foot ** 2 / year"), gross_floor_area=ureg.Quantity( float(property_view_factory.fake.random_number(digits=6)), "foot ** 2"), ) self.good_property_views.append(pv) self.analysis_b = (FakeAnalysisFactory(organization=self.org, user=self.user).get_analysis( name='Good Analysis', service=Analysis.BSYNCR)) self.good_meters = [] for i in range(self.num_good_property_views): self.good_meters.append( Meter.objects.create( property=self.good_property_views[i].property, source=Meter.PORTFOLIO_MANAGER, source_id="Source ID", type=Meter.ELECTRICITY_GRID, )) tz_obj = timezone(TIME_ZONE) for j in range(1, 13): MeterReading.objects.create( meter=self.good_meters[i], start_time=make_aware(datetime(2019, j, 1, 0, 0, 0), timezone=tz_obj), end_time=make_aware(datetime(2019, j, 28, 0, 0, 0), timezone=tz_obj), reading=12345, source_unit='kWh', conversion_factor=1.00)