def test_table_layout_when_no_location_type_or_location_yet(self): LocationType.objects.all().delete() LocationTypeDetails.objects.all().delete() Location.objects.all().delete() ea_csv_layout = UploadEACSVLayoutHelper() self.assertEqual( [["No Location/LocationType added yet. Please add those first."]], ea_csv_layout.table_layout_example())
def setUp(self): self.country = LocationType.objects.create(name='Country', slug='country') self.uganda = Location.objects.create(name="Uganda", type=self.country) LocationTypeDetails.objects.create(country=self.uganda, location_type=self.country) self.region_type = LocationType.objects.create(name="Regiontype", slug="regiontype", parent=self.country) self.district_type = LocationType.objects.create( name="Districttype", slug='districttype', parent=self.region_type) self.county_type = LocationType.objects.create( name="Countytype", slug='countytype', parent=self.district_type) self.parish_type = LocationType.objects.create(name="Parishtype", slug='parishtype', parent=self.county_type) self.region = Location.objects.create(name="region1", type=self.region_type, parent=self.uganda) self.district = Location.objects.create(name="district1", parent=self.region, type=self.district_type) self.county_1 = Location.objects.create(name="county1", parent=self.district, type=self.county_type) self.parish_1 = Location.objects.create(name="parish_1", parent=self.county_1, type=self.parish_type) self.parish_1_b = Location.objects.create(name="parish_1b", parent=self.county_1, type=self.parish_type) self.region = Location.objects.create(name="region2", parent=self.uganda, type=self.region_type) self.district = Location.objects.create(name="district2", parent=self.region, type=self.district_type) self.county_2 = Location.objects.create(name="county2", parent=self.district, type=self.county_type) self.parish_2 = Location.objects.create(name="parish_2", parent=self.county_2, type=self.parish_type) self.ea_csv_layout = UploadEACSVLayoutHelper()
class EAUploadCSVLayoutHelperTest(BaseTest): def setUp(self): country = LocationType.objects.create(name='Country', slug='country') uganda = Location.objects.create(name="Uganda", type=country) LocationTypeDetails.objects.create(country=uganda, location_type=country) region_type = LocationType.objects.create(name="Regiontype", slug="regiontype") district_type = LocationType.objects.create(name="Districttype", slug='districttype') county_type = LocationType.objects.create(name="Countytype", slug='countytype') parish_type = LocationType.objects.create(name="Parishtype", slug='parishtype') region = Location.objects.create(name="region1", type=region_type, tree_parent=uganda) district = Location.objects.create(name="district1", tree_parent=region, type=district_type) county_1 = Location.objects.create(name="county1", tree_parent=district, type=county_type) parish_1 = Location.objects.create(name="parish_1", tree_parent=county_1, type=parish_type) parish_1_b = Location.objects.create(name="parish_1b", tree_parent=county_1, type=parish_type) region = Location.objects.create(name="region2", tree_parent=uganda, type=region_type) district = Location.objects.create(name="district2", tree_parent=region, type=district_type) county_2 = Location.objects.create(name="county2", tree_parent=district, type=county_type) parish_2 = Location.objects.create(name="parish_2", tree_parent=county_2, type=parish_type) self.ea_csv_layout = UploadEACSVLayoutHelper() def test_headers_format(self): expected_headers = ['Regiontype', 'Districttype', 'Countytype', 'EA', 'Parishtype', 'EA'] [self.assertIn(header, expected_headers) for header in self.ea_csv_layout._header_format()] def test_table_layout_example(self): expected = [ ['regiontype_0', 'districttype_0', 'countytype_0', 'ea_0', 'parishtype_0', ''], ['regiontype_0', 'districttype_0', 'countytype_0', 'ea_0', 'parishtype_0_b', ''], ['regiontype_1', 'districttype_1', 'countytype_1', '', 'parishtype_1', 'ea_1'], ['regiontype_1', 'districttype_1', 'countytype_1', '', 'parishtype_1', 'ea_1_b']] self.assertEqual(expected, self.ea_csv_layout.table_layout_example()) def test_table_layout_when_no_location_type_or_location_yet(self): LocationType.objects.all().delete() LocationTypeDetails.objects.all().delete() Location.objects.all().delete() ea_csv_layout = UploadEACSVLayoutHelper() self.assertEqual([["No Location/LocationType added yet. Please add those first."]], ea_csv_layout.table_layout_example())
def setUp(self): country = LocationType.objects.create(name='Country', slug='country') uganda = Location.objects.create(name="Uganda", type=country) LocationTypeDetails.objects.create(country=uganda, location_type=country) region_type = LocationType.objects.create(name="Regiontype", slug="regiontype") district_type = LocationType.objects.create(name="Districttype", slug='districttype') county_type = LocationType.objects.create(name="Countytype", slug='countytype') parish_type = LocationType.objects.create(name="Parishtype", slug='parishtype') region = Location.objects.create(name="region1", type=region_type, tree_parent=uganda) district = Location.objects.create(name="district1", tree_parent=region, type=district_type) county_1 = Location.objects.create(name="county1", tree_parent=district, type=county_type) parish_1 = Location.objects.create(name="parish_1", tree_parent=county_1, type=parish_type) parish_1_b = Location.objects.create(name="parish_1b", tree_parent=county_1, type=parish_type) region = Location.objects.create(name="region2", tree_parent=uganda, type=region_type) district = Location.objects.create(name="district2", tree_parent=region, type=district_type) county_2 = Location.objects.create(name="county2", tree_parent=district, type=county_type) parish_2 = Location.objects.create(name="parish_2", tree_parent=county_2, type=parish_type) self.ea_csv_layout = UploadEACSVLayoutHelper()
def upload(request): upload_form = UploadEAForm() if request.method == 'POST': upload_form = UploadEAForm(request.POST, request.FILES) if upload_form.is_valid(): begin_upload.delay(upload_form) messages.warning(request, "Upload in progress. This could take a while.") return HttpResponseRedirect('/locations/enumeration_area/upload/') context = {'button_label': 'Upload', 'id': 'upload-location-ea-form', 'upload_form': upload_form, 'csv_layout': UploadEACSVLayoutHelper()} return render(request, 'locations/enumeration_area/upload.html', context)
def test_table_layout_when_no_location_type_or_location_yet(self): LocationType.objects.all().delete() LocationTypeDetails.objects.all().delete() Location.objects.all().delete() ea_csv_layout = UploadEACSVLayoutHelper() self.assertEqual([["No Location/LocationType added yet. Please add those first."]], ea_csv_layout.table_layout_example())