def setUp(self): file = open(MULTI_AGENCY_FIXTURE, 'r') self.counts = ImportCounters() save_records_to_database(read_records_from_file(file), self.counts) self.all_locations = Location.objects.all() self.all_organizations = Organization.objects.all() self.all_taxonomy_terms = TaxonomyTerm.objects.all()
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', } ], } } }
def handle(self, *args, **options): counts = ImportCounters() file = options['file'] nodes = etree.iterparse(file, events=('end', )) organization_id = '' for _, elem in nodes: if elem.tag == 'Agency': try: organization = parse_agency(elem) organization_id = organization.id save_organization(organization, counts) except XmlParseException as error: error = 'Parser exception caught when importing the organization immediately after the one with id "{the_id}": {error_message}'.format( the_id=organization_id, error_message=error.__str__()) self.stdout.write(self.style.ERROR(error)) except AttributeError as error: error = 'Missing field error caught when importing the organization immediately after the one with id "{the_id}": {error_message}'.format( the_id=organization_id, error_message=error.__str__()) self.stdout.write(self.style.ERROR(error)) message_template = ( 'Successfully imported {0} organization(s), ' '{1} location(s), {2} service(s), ' '{3} taxonomy term(s), {4} address(es), {5} phone number type(s), ' 'and {6} phone number(s)') status_message = message_template.format( counts.organization_count, counts.location_count, counts.service_count, counts.taxonomy_term_count, counts.address_count, counts.phone_number_types_count, counts.phone_at_location_count) self.stdout.write(self.style.SUCCESS(status_message))
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_save_organizations_catches_exceptions(self): save_records_to_database( read_records_from_file(open(INVALID_AGENCIES_FIXTURE, 'r')), ImportCounters()) organizations = Organization.objects.all() organization_ids = list(map(lambda x: x.id, organizations)) self.assertEqual(len(organization_ids), 2) self.assertIn('SECOND_VALID_AGENCY', organization_ids) self.assertIn('FIRST_VALID_AGENCY', organization_ids)
def setUp(self): file = open(MULTI_AGENCY_FIXTURE, 'r') save_records_to_database(read_records_from_file(file), ImportCounters()) self.all_taxonomy_terms = TaxonomyTerm.objects.all() self.all_services = Service.objects.all()
def setUp(self): save_records_to_database( read_records_from_file(open(ONE_AGENCY_FIXTURE, 'r')), ImportCounters()) organizations = Organization.objects.all() self.organization = organizations[0]
def setUp(self): file = open(ONE_AGENCY_FIXTURE, 'r') records = read_records_from_file(file) save_records_to_database(records, ImportCounters()) all_records_from_database = Location.objects.all() self.location = all_records_from_database[0]
def setUp(self): file = open(ONE_AGENCY_FIXTURE, 'r') records = read_records_from_file(file) save_records_to_database(records, ImportCounters()) self.addresses = Address.objects.all()
def testTwoServicesCanBeRelatedToOneLocation(self): file = open(SHARED_SERVICE_FIXTURE, 'r') save_records_to_database(read_records_from_file(file), ImportCounters()) self.assertEqual( Service.objects.filter(locations__id='9493390').count(), 2)