def setUpClass(cls): # Set global collection for sort tests cls.collection = StoresCollection([ Store(postcode="ZXDT 333", name="AB", lon=2, lat=2), Store(postcode="ASFR 333", name="aA", lon=1, lat=1), Store(postcode="UYEE 222", name="AC", lon=3, lat=3), ])
def test_name_type_setter(self): # Init setter StoreInvalidDefinitionError postcode = Store(postcode="SN25 2EG", name="Shop") # Expect type error with self.assertRaises(StoreInvalidDefinitionError): postcode.name = 1234
def test_setter_update(self): test_postcode = "SN25 XXX" # Init the class postcode = Store(postcode="SN25 2EG", name="Shop") postcode.postcode = test_postcode # Check assertion self.assertEqual(postcode.postcode, test_postcode)
def test_setter_update(self): test_name = "Some Name" # Init the class postcode = Store(postcode="SN25 2EG", name=test_name) postcode.name = test_name # Check assertion self.assertEqual(postcode.name, test_name)
def test_setter_update(self): test_lat = 12.34 # Init the class postcode = Store(postcode="SN25 2EG", name="Shop", lat=test_lat) postcode.lat = test_lat # Check assertion self.assertEqual(postcode.lat, test_lat)
def test_init_set(self): test_lon = 12.34 # Init the class postcode = Store(postcode="SN25 2EG", name="Shop", lon=test_lon) # Check assertion self.assertEqual(postcode.lon, test_lon)
def test_init_set(self): test_postcode = "SN25 2EG" # Init the class postcode = Store(postcode=test_postcode, name="Shop") # Check assertion self.assertEqual(postcode.postcode, test_postcode)
def test_append_stores(self): # Append stores store2 = Store(postcode="SN22 222", name="Store 2", lon=2, lat=2) store3 = Store(postcode="SN33 333", name="Store 3", lon=3, lat=3) # Append from constructor as array with mixed types collection = StoresCollection(stores=[{ "postcode": "SN25 2EG", "name": "Store 1", "lon": 1, "lat": 1 }, store2]) # Append single record collection.append(store3) # Check assertion self.assertEqual(collection.stores[0].name, "Store 1") self.assertEqual(collection.stores[1].name, "Store 2") self.assertEqual(collection.stores[2].name, "Store 3") # Instance compare self.assertEqual(collection.stores[1], store2)
def test_name_length(self): # Expect constructor StoreInvalidDefinitionError with self.assertRaises(StoreInvalidDefinitionError): Store(postcode="SN25 2EG", name="")
def test_name_type_init(self): # Exception constructor StoreInvalidDefinitionError with self.assertRaises(StoreInvalidDefinitionError): Store(postcode="SN25 2EG", name=1234)
def test_init_required_param(self): # Expect type error with self.assertRaises(TypeError): Store(postcode="SN25 2EG")
def test_lat_min(self): # Expect StoreInvalidDefinitionError about out of range with self.assertRaises(StoreInvalidDefinitionError): Store(postcode="SN25 2EG", name="Shop", lat=-100)
def test_lat_type_number(self): # Init without exception try: Store(postcode="SN25 2EG", name="Shop", lat=12) except IndexError: self.fail("Exception raised")
def test_lat_type_init(self): # Exception constructor StoreInvalidDefinitionError with self.assertRaises(StoreInvalidDefinitionError): Store(postcode="SN25 2EG", name="Shop", lat="12.34")
def test_init_required_param(self): # Expect type error with self.assertRaises(TypeError): Store(name="Shop")