示例#1
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()]])
示例#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'])
示例#3
0
    def handle(self, *args, **options):
        root_folder = options['path']
        is_updating_db = options['save_topics_to_db']

        self.stdout.write(
            'Reading Newcomers Guide data from {}'.format(root_folder))

        taxonomy_data = read_taxonomy_data(root_folder)
        taxonomies = parse_taxonomy_files(taxonomy_data)

        task_data = read_task_data(root_folder)
        tasks = parse_task_files(task_data)
        set_taxonomy_term_references_on_content(taxonomies, tasks['taskMap'])

        log_taxonomies(self.stdout, tasks['taskMap'])
        log_locales(self.stdout, tasks['taskMap'])

        with open('tasks.ts', 'w') as file:
            file.write(generate_task_fixture(tasks))

        with open('taxonomies.ts', 'w') as file:
            file.write(generate_taxonomy_fixture(taxonomies))

        if is_updating_db:
            counts = ImportCounters()
            save_topics(tasks, counts)
示例#4
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')
示例#5
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')
示例#6
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)
示例#7
0
    def test_includes_related_topics_from_database_in_order_of_declining_similarity_score(
            self):
        task_id = a_string()
        similar_task_id = a_string()
        create_tasks([task_id, similar_task_id])

        a_high_score = 0.9
        TaskSimilarityScore(first_task_id=task_id,
                            second_task_id=similar_task_id,
                            similarity_score=a_high_score).save()

        dissimilar_task_id = a_string()
        create_tasks([dissimilar_task_id])
        a_low_score = 0.1
        TaskSimilarityScore(first_task_id=task_id,
                            second_task_id=dissimilar_task_id,
                            similarity_score=a_low_score).save()

        path = 'some/path/chapter/topics/{0}/en.Learn_english.txt'.format(
            task_id)
        result = parse_task_files([[path, a_string()]])
        self.assertEqual(result['taskMap'][task_id]['relatedTasks'],
                         [similar_task_id, dissimilar_task_id])
示例#8
0
 def test_clean_up_content_links(self):
     result = parse_task_files(
         [[self.english_path, 'abc http://example.com def']])
     description = result['taskMap']['to_learn_english']['description'][
         'en']
     self.assertEqual(description, 'abc [link](http://example.com) def')
示例#9
0
 def test_clean_up_content_linebreaks(self):
     result = parse_task_files([[self.english_path, 'abc\ndef']])
     description = result['taskMap']['to_learn_english']['description'][
         'en']
     self.assertEqual(description, 'abc def')
示例#10
0
 def test_handles_unicode_in_title(self):
     self.english_path = "some/path/chapter/topics/the_id/fr.Système_d'éducation.txt"
     self.result = parse_task_files([[self.english_path, a_string()]])
     self.assertEqual(self.result['taskMap']['the_id']['title']['fr'],
                      "Système_d'éducation")
示例#11
0
    def setUp(self):
        self.english_path = 'some/path/chapter/topics/To_learn_english/en.Learn_english.txt'

        self.content = a_string()
        self.result = parse_task_files([[self.english_path, self.content]])
示例#12
0
def read_task_descriptions(root_folder):
    task_data = read_task_data(root_folder)
    return parse_task_files(task_data)