Beispiel #1
0
    def test_taxonomy_search_with_wrong_taxonomy_term_returns_empty_array(self):
        taxonomy_term = TaxonomyTermBuilder().create()
        wrong_taxonomy_term = TaxonomyTermBuilder().create()
        ServiceBuilder(self.organization).with_taxonomy_terms([taxonomy_term]).create()

        url = '/v1/services/?taxonomy_terms={0}.{1}'.format(taxonomy_term.taxonomy_id,
                                                           wrong_taxonomy_term.name)
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.json()), 0)
Beispiel #2
0
    def test_saving_two_taxonomies_with_same_name_and_different_taxonomy_id(
            self):
        taxonomy_id_1 = 'the_taxonomy_id_1'
        taxonomy_id_2 = 'the_taxonomy_id_2'
        name = 'the_name'

        taxonomy_term1 = TaxonomyTermBuilder().with_name(name).build()
        taxonomy_term1.taxonomy_id = taxonomy_id_1
        taxonomy_term1.save()

        taxonomy_term2 = TaxonomyTermBuilder().with_name(name).build()
        taxonomy_term2.taxonomy_id = taxonomy_id_2
        taxonomy_term2.save()

        self.assertNotEqual(taxonomy_term1.pk, taxonomy_term2.pk)
Beispiel #3
0
    def test_saving_two_taxonomies_with_same_taxonomy_id_and_different_name(
            self):
        taxonomy_id = 'the_taxonomy_id'
        name_1 = 'the_name_1'
        name_2 = 'the_name_2'

        taxonomy_term1 = TaxonomyTermBuilder().with_taxonomy_id(
            taxonomy_id).build()
        taxonomy_term1.name = name_1
        taxonomy_term1.save()

        taxonomy_term2 = TaxonomyTermBuilder().with_taxonomy_id(
            taxonomy_id).build()
        taxonomy_term2.name = name_2
        taxonomy_term2.save()

        self.assertNotEqual(taxonomy_term1.pk, taxonomy_term2.pk)
Beispiel #4
0
    def test_saving_two_taxonomies_with_same_name_and_taxonomy_id_fails_with_integrity_error(
            self):
        taxonomy_id = 'the_taxonomy_id'
        name = 'the_name'

        taxonomy_term1 = TaxonomyTermBuilder().with_taxonomy_id(
            taxonomy_id).with_name(name).build()
        taxonomy_term1.save()

        taxonomy_term2 = TaxonomyTermBuilder().with_taxonomy_id(
            taxonomy_id).with_name(name).build()
        with self.assertRaises(IntegrityError):
            taxonomy_term2.save()
Beispiel #5
0
    def test_taxonomy_search_returns_service(self):
        taxonomy_term = TaxonomyTermBuilder().create()
        service = ServiceBuilder(self.organization).with_taxonomy_terms([taxonomy_term]).create()

        url = '/v1/services/?taxonomy_terms={0}.{1}'.format(taxonomy_term.taxonomy_id,
                                                           taxonomy_term.name)
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.json()), 1)
        self.assertEqual(response.json()[0]['id'], service.id)
Beispiel #6
0
    def test_search_with_two_taxonomy_terms_returns_service_labelled_with_both_terms(self):
        first_taxonomy_term = TaxonomyTermBuilder().create()
        second_taxonomy_term = TaxonomyTermBuilder().create()

        ServiceBuilder(self.organization).with_taxonomy_terms([first_taxonomy_term]).create()
        ServiceBuilder(self.organization).with_taxonomy_terms([second_taxonomy_term]).create()

        service_with_both_terms = (ServiceBuilder(self.organization).
                                   with_taxonomy_terms([
                                       first_taxonomy_term, second_taxonomy_term
                                   ]).
                                   create())

        argument = '{first_id}.{first_name},{second_id}.{second_name}'.format(
                                                        first_id=first_taxonomy_term.taxonomy_id,
                                                        first_name=first_taxonomy_term.name,
                                                        second_id=second_taxonomy_term.taxonomy_id,
                                                        second_name=second_taxonomy_term.name)

        response = self.client.get('/v1/services/?taxonomy_terms={}'.format(argument))

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.json()), 1)
        self.assertEqual(response.json()[0]['id'], service_with_both_terms.id)
Beispiel #7
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)
Beispiel #8
0
    def test_can_combine_taxonomic_search_and_full_text_search(self):
        the_search_term = a_string()
        the_taxonomy_term = TaxonomyTermBuilder().create()

        a_service = (ServiceBuilder(self.organization).
                     with_name(the_search_term + a_string()).
                     with_taxonomy_terms([the_taxonomy_term]).
                     create())

        ServiceBuilder(self.organization).with_taxonomy_terms([the_taxonomy_term]).create()
        ServiceBuilder(self.organization).with_name(the_search_term + a_string()).create()

        url = '/v1/services/?search={0}&taxonomy_terms={1}.{2}'.format(the_search_term,
                                                                      the_taxonomy_term.taxonomy_id,
                                                                      the_taxonomy_term.name)
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.json()), 1)
        self.assertEqual(response.json()[0]['name'], a_service.name)
Beispiel #9
0
 def test_name_cannot_contain_space(self):
     name = 'the name'
     taxonomy_term = TaxonomyTermBuilder().with_name(name).build()
     with self.assertRaises(exceptions.ValidationError):
         taxonomy_term.full_clean()
Beispiel #10
0
 def test_name_cannot_be_empty(self):
     name = ''
     taxonomy_term = TaxonomyTermBuilder().with_name(name).build()
     with self.assertRaises(exceptions.ValidationError):
         taxonomy_term.full_clean()
Beispiel #11
0
 def test_has_name_field(self):
     name = 'the_name'
     taxonomy_term = TaxonomyTermBuilder().with_name(name).build()
     taxonomy_term_from_db = validate_save_and_reload(taxonomy_term)
     self.assertEqual(taxonomy_term_from_db.name, name)
Beispiel #12
0
 def test_taxonomy_id_cannot_contain_space(self):
     taxonomy_id = 'the taxonomy_id'
     taxonomy_term = TaxonomyTermBuilder().with_taxonomy_id(
         taxonomy_id).build()
     with self.assertRaises(exceptions.ValidationError):
         taxonomy_term.full_clean()
Beispiel #13
0
 def test_taxonomy_id_cannot_be_none(self):
     taxonomy_id = None
     taxonomy_term = TaxonomyTermBuilder().with_taxonomy_id(
         taxonomy_id).build()
     with self.assertRaises(exceptions.ValidationError):
         taxonomy_term.full_clean()
Beispiel #14
0
 def test_has_taxonomy_id_field(self):
     taxonomy_id = 'the_taxonomy_id'
     taxonomy_term = TaxonomyTermBuilder().with_taxonomy_id(
         taxonomy_id).build()
     taxonomy_term_from_db = validate_save_and_reload(taxonomy_term)
     self.assertEqual(taxonomy_term_from_db.taxonomy_id, taxonomy_id)