class TestServiceLocationModel(TestCase): def setUp(self): self.organization = OrganizationBuilder().build() self.organization.save() self.service = ServiceBuilder(self.organization).build() self.service.save() self.location = LocationBuilder(self.organization).build() self.location.save() def test_has_service_field(self): service_at_location = ServiceLocationBuilder(self.service, self.location).build() service_location_from_db = validate_save_and_reload( service_at_location) self.assertEqual(service_location_from_db.service, self.service) def test_service_cannot_be_none(self): service_at_location = ServiceLocationBuilder(None, self.location).build() with self.assertRaises(exceptions.ValidationError): service_at_location.full_clean() def test_has_location_field(self): service_at_location = ServiceLocationBuilder(self.service, self.location).build() service_location_from_db = validate_save_and_reload( service_at_location) self.assertEqual(service_location_from_db.location, self.location) def test_location_cannot_be_none(self): service_at_location = ServiceLocationBuilder(self.service, None).build() with self.assertRaises(exceptions.ValidationError): service_at_location.full_clean()
def test_can_filter_by_taxonomy(self): taxonomy_terms = TaxonomyTermBuilder().create_many() service = ServiceBuilder( self.organization).with_taxonomy_terms(taxonomy_terms).create() location = LocationBuilder(self.organization).create() expected_service_at_location = ServiceAtLocation.objects.create( service=service, location=location) response = (self.client.get( '/v1/services_at_location/?taxonomy_terms={0}.{1}'.format( taxonomy_terms[0].taxonomy_id, taxonomy_terms[0].name))) json = response.json() self.assertEqual(len(json), 1) self.assertEqual(json[0]['location']['name'], expected_service_at_location.location.name) self.assertEqual(json[0]['service']['name'], expected_service_at_location.service.name)
def setUp(self): self.organization = OrganizationBuilder().create() self.service = ServiceBuilder(self.organization).create() self.location = LocationBuilder(self.organization).create()
def test_only_longitude_cannot_be_null(self): location = (LocationBuilder( self.organization).with_latitude(0.0).with_longitude(None).build()) with self.assertRaises(exceptions.ValidationError): location.full_clean()
def test_latitude_and_longitude_can_both_be_null(self): location = (LocationBuilder(self.organization).with_latitude( None).with_longitude(None).build()) location_from_db = validate_save_and_reload(location) self.assertEqual(location_from_db.latitude, None) self.assertEqual(location_from_db.longitude, None)
def test_has_longitude(self): longitude = 234.567 location = LocationBuilder( self.organization).with_longitude(longitude).build() location_from_db = validate_save_and_reload(location) self.assertAlmostEqual(location_from_db.longitude, longitude)
def test_has_latitude(self): latitude = 123.456 location = LocationBuilder( self.organization).with_latitude(latitude).build() location_from_db = validate_save_and_reload(location) self.assertAlmostEqual(location_from_db.latitude, latitude)
def test_cannot_be_empty(self): name = '' location = LocationBuilder(self.organization).with_name(name).build() with self.assertRaises(exceptions.ValidationError): location.full_clean()
def test_has_name(self): name = 'The location name' location = LocationBuilder(self.organization).with_name(name).build() location_from_db = validate_save_and_reload(location) self.assertEqual(location_from_db.name, name)
def test_id_cannot_contain_space(self): location_id = 'the id' location = LocationBuilder( self.organization).with_id(location_id).build() with self.assertRaises(exceptions.ValidationError): location.full_clean()
def test_id_cannot_be_none(self): null_id = None location = LocationBuilder(self.organization).with_id(null_id).build() with self.assertRaises(exceptions.ValidationError): location.full_clean()
def test_has_id_field(self): location_id = 'the_id' location = LocationBuilder( self.organization).with_id(location_id).build() location_from_db = validate_save_and_reload(location) self.assertEqual(location_from_db.id, location_id)
def test_description_can_be_none(self): null_description = None location = LocationBuilder( self.organization).with_description(null_description).build() location_from_db = validate_save_and_reload(location) self.assertEqual(location_from_db.description, null_description)
def test_can_set_description(self): description = 'The location description' location = LocationBuilder( self.organization).with_description(description).build() location_from_db = validate_save_and_reload(location) self.assertEqual(location_from_db.description, description)
def test_can_create_and_retrieve_point(self): location = LocationBuilder(self.organization).with_long_lat( a_float(), a_float()).build() location_from_db = validate_save_and_reload(location) self.assertEqual(location_from_db.point, location.point)