示例#1
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)
 def test_saves_multiple_taxonomy_terms(self):
     save_topics(self.one_task, self.counts)
     record = Task.objects.all()[0]
     self.assertEqual(record.taxonomy_terms.all()[0].taxonomy_id, 'colour')
     self.assertEqual(record.taxonomy_terms.all()[1].taxonomy_id, 'size')
 def test_saves_taxonomy_term(self):
     save_topics(self.one_task, self.counts)
     record = Task.objects.all()[0]
     self.assertEqual(record.taxonomy_terms.all()[0].name, 'blue')
 def test_saves_task_description_in_english(self):
     save_topics(self.one_task, self.counts)
     records = Task.objects.all()
     self.assertEqual(records[0].description, self.english_task_description)
 def test_saves_task_title_in_english(self):
     save_topics(self.one_task, self.counts)
     records = Task.objects.all()
     self.assertEqual(records[0].name, self.english_task_name)
 def test_saves_task_id(self):
     save_topics(self.one_task, self.counts)
     records = Task.objects.all()
     self.assertEqual(records[0].id, self.task_id)
    def test_deletes_existing_records(self):
        two_preexisting_tasks = [a_string(), a_string()]
        helpers.create_tasks(two_preexisting_tasks)

        save_topics(self.one_task, self.counts)
        self.assertEqual(Task.objects.count(), 1)