Exemplo n.º 1
0
 def setUp(self):
     self.counts = ImportCounters()
     self.task_id = 'the-task-id'
     self.english_task_name = a_string()
     self.english_task_description = a_string()
     self.one_task = {
         'taskMap': {
             'the-task-id': {
                 'id': 'the-task-id',
                 'title': {
                     'en': self.english_task_name,
                 },
                 'description': {
                     'en': self.english_task_description,
                 },
                 'taxonomyTerms': [
                     {
                         'taxonomyId': 'colour',
                         'taxonomyTermId': 'blue',
                     },
                     {
                         'taxonomyId': 'size',
                         'taxonomyTermId': 'large',
                     }
                 ],
             }
         }
     }
Exemplo n.º 2
0
 def test_parse_task_files_includes_article_content(self):
     task_path = 'some/path/chapter/topics/To_learn_english/en.Learn_english.txt'
     article_path = 'some/path/chapter/topics/Human_rights/en.Human_rights.txt'
     result = parse_task_files([[task_path, a_string()],
                                [article_path, a_string()]])
     self.assertIn('to_learn_english', result['taskMap'])
     self.assertIn('human_rights', result['taskMap'])
Exemplo n.º 3
0
 def __init__(self, organization):
     self.location_id = a_string()
     self.organization = organization
     self.name = a_string()
     self.latitude = a_float()
     self.longitude = a_float()
     self.description = a_string()
Exemplo n.º 4
0
 def __init__(self, organization):
     self.service_id = a_string()
     self.organization = organization
     self.name = a_string()
     self.description = a_string()
     self.taxonomy_terms = []
     self.location_ids = []
Exemplo n.º 5
0
 def test_can_create_with_none_value_for_services(self):
     services = None
     location = dtos.Location(id=a_string(),
                              name=a_string(),
                              organization_id=a_string(),
                              services=services)
     self.assertEqual(location.services, services)
Exemplo n.º 6
0
 def test_throws_on_list_of_wrong_type_for_phone_numbers(self):
     phone_numbers = [a_string()]
     with self.assertRaises(exceptions.InvalidTypeXmlParseException):
         dtos.Location(id=a_string(),
                       name=a_string(),
                       organization_id=a_string(),
                       phone_numbers=phone_numbers)
Exemplo n.º 7
0
 def test_throws_on_list_of_wrong_type_for_services(self):
     services = [a_string()]
     with self.assertRaises(exceptions.InvalidTypeXmlParseException):
         dtos.Location(id=a_string(),
                       name=a_string(),
                       organization_id=a_string(),
                       services=services)
Exemplo n.º 8
0
 def test_can_create_with_none_value_for_phone_numbers(self):
     phone_numbers = None
     location = dtos.Location(id=a_string(),
                              name=a_string(),
                              organization_id=a_string(),
                              phone_numbers=phone_numbers)
     self.assertEqual(location.services, phone_numbers)
Exemplo n.º 9
0
    def test_returns_services_ordered_by_score(self):
        task_id = a_string()
        task = Task(id=task_id, name=a_string(), description=a_string())
        task.save()

        organization = OrganizationBuilder().create()
        more_related_service = ServiceBuilder(organization).create()
        less_related_service = ServiceBuilder(organization).create()

        higher_score = 0.9
        lower_score = 0.1
        TaskServiceSimilarityScore(task=task,
                                   service=more_related_service,
                                   similarity_score=higher_score).save()

        TaskServiceSimilarityScore(task=task,
                                   service=less_related_service,
                                   similarity_score=lower_score).save()

        url = '/v1/tasks/{}/related_services/'.format(task_id)
        response = self.client.get(url)

        self.assertEqual(response.json()[0]['service_id'],
                         more_related_service.id)
        self.assertEqual(response.json()[1]['service_id'],
                         less_related_service.id)
Exemplo n.º 10
0
 def test_parses_phone_phone_number(self):
     site_id = a_string()
     phone_type = a_string()
     phone_number = a_phone_number()
     xml = self.build_phone_xml(phone_number, phone_type)
     root = etree.fromstring(xml)
     phone_number_list = parser.parse_site_phone_number_list(root, site_id)
     self.assertEqual(phone_number_list[0].phone_number, phone_number)
Exemplo n.º 11
0
 def test_parses_phone_into_expected_dto_object(self):
     site_id = a_string()
     phone_type = a_string()
     phone_number = a_phone_number()
     xml = self.build_phone_xml(phone_number, phone_type)
     root = etree.fromstring(xml)
     phone_number_list = parser.parse_site_phone_number_list(root, site_id)
     self.assertIsInstance(phone_number_list[0], dtos.PhoneAtLocation)
Exemplo n.º 12
0
    def test_full_text_search_ignores_empty_search_term(self):
        ServiceBuilder(self.organization).create()

        url = '/v1/services/?search={0},{1},{2}'.format('', a_string(), a_string())
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.json()), 0)
Exemplo n.º 13
0
 def test_throw_on_same_task_id_in_different_chapters(self):
     first_path = 'some/path/chapter1/topics/Registering_child_in_school/en.InEnglish.md'
     second_path = 'some/path/chapter2/topics/Registering_child_in_school/fr.InFrench.md'
     error_message = 'registering_child_in_school: don\'t use the same task id in different chapters'
     with self.assertRaisesMessage(exceptions.ValidationError,
                                   error_message):
         parse_task_files([[first_path, a_string()],
                           [second_path, a_string()]])
Exemplo n.º 14
0
 def test_getting_description_for_service_returns_name_and_description(
         self):
     name = a_string()
     description = a_string()
     ServiceBuilder(self.organization).with_name(name).with_description(
         description).create()
     _, descriptions = to_service_ids_and_descriptions(
         Service.objects.all())
     self.assertEqual(descriptions[0], name + ' ' + description)
Exemplo n.º 15
0
 def test_handle_localized_titles_when_processing_the_same_content_in_different_locales(
         self):
     french_path = 'some/path/chapter/topics/To_learn_english/fr.Apprendre_l_anglais.txt'
     result = parse_task_files([[self.english_path,
                                 a_string()], [french_path,
                                               a_string()]])
     self.assertEqual(result['taskMap']['to_learn_english']['title']['en'],
                      'Learn_english')
     self.assertEqual(result['taskMap']['to_learn_english']['title']['fr'],
                      'Apprendre_l_anglais')
Exemplo n.º 16
0
 def test_throws_on_single_phone_at_location_for_phone_numbers(self):
     phone_at_location = dtos.PhoneAtLocation(
         location_id=a_string(),
         phone_number_type_id=a_string(),
         phone_number=a_phone_number())
     with self.assertRaises(exceptions.InvalidTypeXmlParseException):
         dtos.Location(id=a_string(),
                       name=a_string(),
                       organization_id=a_string(),
                       phone_numbers=phone_at_location)
Exemplo n.º 17
0
 def test_combine_files_for_different_content(self):
     secondary_path = 'some/path/chapter/topics/Registering_child_in_school/en.Registering_in_public_school.txt'
     result = parse_task_files([[self.english_path,
                                 a_string()], [secondary_path,
                                               a_string()]])
     self.assertEqual(result['taskMap']['to_learn_english']['title']['en'],
                      'Learn_english')
     self.assertEqual(
         result['taskMap']['registering_child_in_school']['title']['en'],
         'Registering_in_public_school')
Exemplo n.º 18
0
    def test_returns_tasks_ordered_by_score(self):
        the_task = Task(id=a_string(), name=a_string(), description=a_string())
        more_related_task = Task(id=a_string(),
                                 name=a_string(),
                                 description=a_string())
        less_related_task = Task(id=a_string(),
                                 name=a_string(),
                                 description=a_string())

        the_task.save()
        more_related_task.save()
        less_related_task.save()

        high_score = 0.9
        low_score = 0.1

        TaskSimilarityScore(first_task=the_task,
                            second_task=more_related_task,
                            similarity_score=high_score).save()

        TaskSimilarityScore(first_task=the_task,
                            second_task=less_related_task,
                            similarity_score=low_score).save()

        url = '/v1/tasks/{}/related_tasks/'.format(the_task.id)
        response = self.client.get(url)
        self.assertEqual(response.json()[0]['task_id'], more_related_task.id)
        self.assertEqual(response.json()[1]['task_id'], less_related_task.id)
Exemplo n.º 19
0
    def test_full_text_search_returns_service_with_substring_match_to_description(self):
        part_of_the_description = a_string()
        the_description = part_of_the_description + a_string()
        ServiceBuilder(self.organization).with_description(the_description).create()

        url = '/v1/services/?search={0}'.format(part_of_the_description)
        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]['description'], the_description)
Exemplo n.º 20
0
 def test_can_create_with_list_of_phone_at_location_dtos_for_phone_numbers(
         self):
     phone_at_location = dtos.PhoneAtLocation(
         location_id=a_string(),
         phone_number_type_id=a_string(),
         phone_number=a_phone_number())
     phones_at_location = [phone_at_location]
     location = dtos.Location(id=a_string(),
                              name=a_string(),
                              organization_id=a_string(),
                              phone_numbers=phones_at_location)
     self.assertEqual(location.phone_numbers, phones_at_location)
    def test_deletes_existing_records(self):
        first_task_id = a_string()
        second_task_id = a_string()
        create_tasks([first_task_id, second_task_id])
        record = TaskSimilarityScore(first_task_id=first_task_id,
                                     second_task_id=second_task_id,
                                     similarity_score=a_float())
        record.save()

        save_task_similarities([], [], 0)

        self.assertEqual(TaskSimilarityScore.objects.count(), 0)
Exemplo n.º 22
0
 def test_can_create(self):
     location_id = a_string()
     phone_number_type_id = a_string()
     phone_number = a_phone_number()
     phone_at_location = dtos.PhoneAtLocation(
         location_id=location_id,
         phone_number_type_id=phone_number_type_id,
         phone_number=phone_number)
     self.assertEqual(phone_at_location.location_id, location_id)
     self.assertEqual(phone_at_location.phone_number_type_id,
                      phone_number_type_id)
     self.assertEqual(phone_at_location.phone_number, phone_number)
    def test_deletes_existing_records(self):
        task_id = a_string()
        Task(id=task_id, name=a_string(), description=a_string()).save()
        service = ServiceBuilder(self.organization).create()
        record = TaskServiceSimilarityScore(task_id=task_id,
                                            service=service,
                                            similarity_score=a_float())
        record.save()

        save_task_service_similarity_scores([], [], [], 0)

        self.assertEqual(TaskServiceSimilarityScore.objects.count(), 0)
Exemplo n.º 24
0
    def test_can_create_row(self):
        first_id = a_string()
        second_id = a_string()
        score = a_float()
        create_tasks([first_id, second_id])
        score_record = TaskSimilarityScore(first_task_id=first_id,
                                           second_task_id=second_id,
                                           similarity_score=score)
        score_record_from_db = validate_save_and_reload(score_record)

        self.assertEqual(score_record_from_db.first_task_id, first_id)
        self.assertEqual(score_record_from_db.second_task_id, second_id)
        self.assertAlmostEqual(score_record_from_db.similarity_score, score)
Exemplo n.º 25
0
 def test_handle_localized_description_when_processing_the_same_content_in_different_locales(
         self):
     french_path = 'some/path/chapter/topics/To_learn_english/fr.Apprendre_l_anglais.txt'
     english_description = a_string()
     french_description = a_string()
     result = parse_task_files([[self.english_path, english_description],
                                [french_path, french_description]])
     self.assertEqual(
         result['taskMap']['to_learn_english']['description']['en'],
         english_description)
     self.assertEqual(
         result['taskMap']['to_learn_english']['description']['fr'],
         french_description)
    def test_full_text_search_with_two_search_terms_implies_logical_and(self):
        first_name = a_string()
        second_name = a_string()
        combined_name = first_name + second_name
        ServiceBuilder(self.organization).with_name(first_name).create()
        ServiceBuilder(self.organization).with_name(second_name).create()
        ServiceBuilder(self.organization).with_name(combined_name).create()

        url = '/v1/services/?search={0}+{1}'.format(first_name, second_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'], combined_name)
Exemplo n.º 27
0
    def setUp(self):
        translation.activate('en')
        self.task_id = a_string()

        self.task = Task(id=self.task_id,
                         name=a_string(),
                         description=a_string())
        self.task.save()

        organization = OrganizationBuilder().create()
        self.service = ServiceBuilder(organization).create()

        self.similarity_score = a_float()
        TaskServiceSimilarityScore(
            task=self.task,
            service=self.service,
            similarity_score=self.similarity_score).save()
    def test_full_text_search_with_no_match_returns_empty_array(self):
        service = ServiceBuilder(self.organization).create()

        url = '/v1/services/?search={0}'.format(a_string())
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.json()), 0)
    def setUp(self):
        self.organization = OrganizationBuilder().create()
        self.three_task_ids = [a_string() for i in range(3)]
        create_tasks(self.three_task_ids)

        services = [
            ServiceBuilder(self.organization).create() for i in range(3)
        ]
        self.three_service_ids = [service.id for service in services]
Exemplo n.º 30
0
 def test_parses_phone_type_and_converts_to_id(self):
     site_id = a_string()
     phone_type = 'A phone TYPE'
     phone_number = a_phone_number()
     xml = self.build_phone_xml(phone_number, phone_type)
     root = etree.fromstring(xml)
     phone_number_list = parser.parse_site_phone_number_list(root, site_id)
     self.assertEqual(phone_number_list[0].phone_number_type_id,
                      'a_phone_type')