def test_source_attributions(self): """Test that we can point back to an attribute's source. This is explicitly just testing the low-level data model, none of the convenience functions. """ bs1 = seed_models.BuildingSnapshot() bs1.save() bs1.year_ending = datetime.utcnow() bs1.year_ending_source = bs1 bs1.property_name = 'Test 1234' bs1.property_name_source = bs1 bs1.save() bs2 = seed_models.BuildingSnapshot() bs2.save() bs2.property_name = 'Not Test 1234' bs2.property_name_source = bs2 bs2.year_ending = bs1.year_ending bs2.year_ending_source = bs1 bs2.save() self.assertEqual(bs2.year_ending_source, bs1) self.assertEqual(bs2.property_name_source, bs2) # We don't inherit.
def test_clean(self): """Make sure we convert datestrings properly.""" bs_model = seed_models.BuildingSnapshot() date_str = u'12/31/2013' bs_model.year_ending = date_str bs_model.release_date = date_str bs_model.generation_date = date_str expected_value = datetime(year=2013, month=12, day=31) bs_model.clean() self._test_year_month_day_equal(bs_model.year_ending, expected_value) self._test_year_month_day_equal(bs_model.release_date, expected_value) self._test_year_month_day_equal(bs_model.generation_date, expected_value)
def test_repr(self): c = seed_models.CanonicalBuilding() c.save() self.assertTrue('pk: %s' % c.pk in str(c)) self.assertTrue('snapshot: None' in str(c)) self.assertTrue('- active: True' in str(c)) c.active = False c.save() self.assertTrue('- active: False' in str(c)) b = seed_models.BuildingSnapshot() c.canonical_snapshot = b c.save() self.assertTrue('snapshot: %s' % b.pk in str(c)) self.assertEqual( 'pk: %s - snapshot: %s - active: False' % (c.pk, b.pk), str(c))