def test_unicode_with_no_name_returns_street_address(self): building = Building( street="St Mary's Street", number="37a", postcode="CF5 1QE", ) self.assertEqual(building.__unicode__(), "37a St Mary's Street")
def test_unicode_with_name_returns_name(self): building = Building( name="Main Building", street="St Mary's Street", number="37a", postcode="CF5 1QE", ) self.assertEqual(building.__unicode__(), "Main Building")
def test_building_but_no_map_settings_no_maps(self): # add a Building self.main_building = Building( name="Main Building", street="St Mary's Street", site=self.cardiff, ) self.main_building.save() self.assertEquals(self.cardiff.maps, [])
def test_admin_identifier(self): building = Building( name="Main Building", site=Site() ) self.assertEqual( building.admin_identifier, u"%s (%s)" % (building.__unicode__(), unicode(building.site)) )
def test_get_absolute_url(self): # give the building a map self.main_building = Building( name="Main Building", street="St Mary's Street", site=self.cardiff, ) self.main_building.save() self.assertEquals(self.main_building.get_absolute_url(), "/place/main-building/")
def test_set_items_for_place(self): s = Site(id=1) p = Building(site=s) p.save() self.item1.building = p self.item1.save() self.itemlist.place = s self.itemlist.set_items_for_place() self.assertEqual(list(self.itemlist.items), [self.item1])
def test_buildings_property(self): # add a Building self.main_building = Building( name="Main Building", street="St Mary's Street", site=self.cardiff, ) self.main_building.save() self.assertEquals( self.cardiff.buildings(), 1, )
def test_building_and_map_settings(self): # give the building a map self.main_building = Building( name="Main Building", street="St Mary's Street", site=self.cardiff, map=True, latitude=10, longitude=10, zoom=10, ) self.main_building.save() self.assertEquals(self.cardiff.maps, [self.main_building])
def test_set_items_for_place(self): s = Site(id=1) p = Building(site=s) p.save() self.item1.building = p self.item1.save() self.itemlist.place = s self.itemlist.set_items_for_place() self.assertEqual( list(self.itemlist.items), [self.item1] )
def test_get_postal_address_with_missing_components(self): building = Building( site=self.cardiff ) self.assertEqual( ['Cardiff'], building.get_postal_address )
def test_get_postal_address_with_name_includes_name(self): building = Building( name="Main Building", street="St Mary's Street", number="37a", postcode="CF5 1QE", site=self.cardiff ) self.assertEqual( ['Main Building', "37a St Mary's Street", 'Cardiff CF5 1QE'], building.get_postal_address )
def test_get_absolute_url(self): # give the building a map self.main_building = Building( name="Main Building", street="St Mary's Street", site=self.cardiff, ) self.main_building.save() self.assertEquals( self.main_building.get_absolute_url(), "/place/main-building-main-site/" )
class SiteTests(TestCase): def setUp(self): # a geographical Site self.cardiff = Site( site_name="Main site", post_town="Cardiff", country="UK", ) self.cardiff.save() def test_no_building_no_maps(self): """ test Site.maps property """ # no Buildings on this site, should be an empty list self.assertEquals(self.cardiff.maps, []) def test_building_but_no_map_settings_no_maps(self): # add a Building self.main_building = Building( name="Main Building", street="St Mary's Street", site=self.cardiff, ) self.main_building.save() self.assertEquals(self.cardiff.maps, []) def test_building_and_map_settings(self): # give the building a map self.main_building = Building( name="Main Building", street="St Mary's Street", site=self.cardiff, map=True, latitude=10, longitude=10, zoom=10, ) self.main_building.save() self.assertEquals(self.cardiff.maps, [self.main_building]) def test_get_absolute_url(self): # give the building a map self.main_building = Building( name="Main Building", street="St Mary's Street", site=self.cardiff, ) self.main_building.save() self.assertEquals( self.main_building.get_absolute_url(), "/place/main-building-main-site/" )
def test_save(self): site = Site( site_name="Main site", post_town="Cardiff", country="UK", ) site.save() building = Building( name="Main Building", site=site, slug="main-building" ) building.save() # slug has been manually-set self.assertEqual(building.slug, "main-building") # a blank slug will be automatically regenerated building.slug = "" building.save() self.assertEqual(building.slug, "main-building")
def test_has_map_is_always_boolean(self): building = Building( latitude=None, longitude=None, zoom=17, map=False ) self.assertFalse(building.has_map()) building.map = True self.assertFalse(building.has_map()) building.longitude = 0 building.latitude = 0 self.assertTrue(building.has_map()) building.longitude = 1 building.latitude = 1 self.assertTrue(building.has_map())
def setUp(self): # a geographical Site self.cardiff = Site( site_name="Main site", post_town="Cardiff", country="UK", ) self.cardiff.save() # a couple of Buildings on the Site self.main_building = Building( name="Main Building", street="St Mary's Street", site=self.cardiff, ) self.main_building.save() self.heart_testing_centre = Building( name="Heart Testing Centre", street="Queen Street", site=self.cardiff, ) self.heart_testing_centre.save() # create some Entities in a hierarchy # School of Medicine # Departments (an abstract entity) # Department of Cardiology # Section of Heart Research # Heart Testing Centre # Department of Cardiology Student Centre # Web editors (an abstract entity) self.school = Entity( name="School of Medicine", building=self.main_building, slug="medicine", ) self.school.save() self.departments = Entity( name="departments", parent=self.school, slug="departments", abstract_entity=True, building=self.heart_testing_centre, # this should be ignored by everything! ) self.departments.save() self.department = Entity( name="Department of Cardiology", parent=self.departments, slug="cardiology", ) self.department.save() self.section = Entity( name="Section of Heart Research", parent=self.department, slug="heart-research", ) self.section.save() self.testing_centre = Entity( name="Testing Centre", parent=self.department, slug="testing-centre", building_recapitulates_entity_name=True, building=self.heart_testing_centre, ) self.testing_centre.save() self.student_centre = Entity( name="Department of Cardiology Student Centre", parent=self.department, slug="student-centre", display_parent=False, ) self.student_centre.save() self.web_editors = Entity( name="Group of web editors", parent=self.school, slug="web-editors", abstract_entity=True, ) self.web_editors.save() # set up a Person - we will add memberships later in the tests self.smith = Person(slug="smith") self.smith.save()
class SiteTests(TestCase): def setUp(self): # a geographical Site self.cardiff = Site( site_name="Main site", post_town="Cardiff", country="UK", ) self.cardiff.save() def test_no_building_no_maps(self): """ test Site.maps property """ # no Buildings on this site, should be an empty list self.assertEquals(self.cardiff.maps, []) def test_building_but_no_map_settings_no_maps(self): # add a Building self.main_building = Building( name="Main Building", street="St Mary's Street", site=self.cardiff, ) self.main_building.save() self.assertEquals(self.cardiff.maps, []) def test_building_and_map_settings(self): # give the building a map self.main_building = Building( name="Main Building", street="St Mary's Street", site=self.cardiff, map=True, latitude=10, longitude=10, zoom=10, ) self.main_building.save() self.assertEquals(self.cardiff.maps, [self.main_building]) def test_get_absolute_url(self): # give the building a map self.main_building = Building( name="Main Building", street="St Mary's Street", site=self.cardiff, ) self.main_building.save() self.assertEquals(self.main_building.get_absolute_url(), "/place/main-building/") def test_buildings_property(self): # add a Building self.main_building = Building( name="Main Building", street="St Mary's Street", site=self.cardiff, ) self.main_building.save() self.assertEquals( self.cardiff.buildings(), 1, )
def test_unicode_with_no_name_or_street_returns_postcode(self): building = Building( postcode="CF5 1QE", ) self.assertEqual(building.__unicode__(), "CF5 1QE")