def test_load_data_from_csv_without_postcodes(self): collection_type = BinCollectionType.objects.get(friendly_id='D') # sample_domestic_no_postcodes.csv is the first few lines from a Barnet spreadsheet, exported to CSV domestic_sample_file = os.path.join(os.path.dirname(binalerts.__file__), 'fixtures/sample_domestic_no_postcodes.csv') DataImport.load_from_csv_file(open(domestic_sample_file, 'r'), collection_type=collection_type, guess_postcodes=True) response = self.client.post('/', { 'query': 'Amber Grove' }) self.assertContains(response, "No street found with that name. Try typing a smaller part of it") response = self.client.get('/street/juniper_close') self.assertContains(response, "No street found with that name. Try typing a smaller part of it")
def test_load_data_from_native_csv(self): collection_type = BinCollectionType.objects.get(friendly_id='D') # sample_ideal.csv is in the nativce CSV format, rather than a proprietary one sample_file = os.path.join(os.path.dirname(binalerts.__file__), 'fixtures/sample_native.csv') DataImport.load_from_csv_file(open(sample_file, 'r'), collection_type=collection_type, guess_postcodes=False) response = self.client.get('/street/test_road') self.assertRedirects(response, '/street/test_road_ab1') response = self.client.get('/street/test_road_ab1') self.assertContains(response, 'Garden') self.assertContains(response, 'Domestic') self.assertContains(response, 'Friday') self.assertNotContains(response, 'Recycl')
def test_load_data_from_csv_then_pdf(self): Street.objects.all().delete() # not using fixtures here garden_sample_file = os.path.join(os.path.dirname(binalerts.__file__), 'fixtures/sample_garden_from_pdf.xml') DataImport.load_from_pdf_xml(garden_sample_file, collection_type=BinCollectionType.objects.get(friendly_id='G')) domestic_sample_file = os.path.join(os.path.dirname(binalerts.__file__), 'fixtures/sample_domestic_no_postcodes.csv') DataImport.load_from_csv_file(open(domestic_sample_file, 'r'), collection_type=BinCollectionType.objects.get(friendly_id='D')) # Juniper Close in csv doesn't have postcode... should snap to the (only) Juniper Close (with postcode) and # not create a record -- instead, redirecting to it response = self.client.get('/street/juniper_close') self.assertRedirects(response, '/street/juniper_close_en5') response = self.client.get('/street/juniper_close_en5') self.assertContains(response, 'Garden') # from xml import self.assertNotContains(response, 'Domestic') # from the csv import, which had no postcode
def test_load_data_from_pdf_then_csv(self): Street.objects.all().delete() # not using fixtures here collection_type = BinCollectionType.objects.get(friendly_id='G') garden_sample_file = os.path.join(os.path.dirname(binalerts.__file__), 'fixtures/sample_garden_from_pdf.xml') DataImport.load_from_pdf_xml(garden_sample_file, collection_type=collection_type) collection_type = BinCollectionType.objects.get(friendly_id='D') domestic_sample_file = os.path.join(os.path.dirname(binalerts.__file__), 'fixtures/sample_domestic_no_postcodes.csv') DataImport.load_from_csv_file(open(domestic_sample_file, 'r'), collection_type=collection_type, guess_postcodes=True) # Should snap to the (only) Juniper Close (with postcode) response = self.client.get('/street/juniper_close') self.assertRedirects(response, '/street/juniper_close_en5') response = self.client.get('/street/juniper_close_en5') self.assertContains(response, 'Domestic') # from csv import, because postcode was guessed OK self.assertContains(response, 'Garden') # from xml import response = self.client.post('/', { 'query': 'Amber Grove' }) self.assertContains(response, "No street found with that name. Try typing a smaller part of it") # not imported from csv, had no postcode