コード例 #1
0
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()
コード例 #2
0
 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)
コード例 #3
0
 def setUp(self):
     self.organization = OrganizationBuilder().create()
     self.service = ServiceBuilder(self.organization).create()
     self.location = LocationBuilder(self.organization).create()
コード例 #4
0
 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()
コード例 #5
0
 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)
コード例 #6
0
 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)
コード例 #7
0
 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)
コード例 #8
0
 def test_cannot_be_empty(self):
     name = ''
     location = LocationBuilder(self.organization).with_name(name).build()
     with self.assertRaises(exceptions.ValidationError):
         location.full_clean()
コード例 #9
0
 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)
コード例 #10
0
 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()
コード例 #11
0
 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()
コード例 #12
0
 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)
コード例 #13
0
 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)
コード例 #14
0
 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)
コード例 #15
0
 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)