def test_replacing(self): command = LoadGeos() old_geo = { 'geoid': '1111111111', 'geo_type': Geo.TRACT_TYPE, 'name': 'Geo in 1990', 'year': '1990', 'state': '11', 'county': '111', 'tract': '11111', 'minlat': -1, 'maxlat': 1, 'minlon': -1, 'maxlon': 1, 'centlat': 0, 'centlon': 0, 'geom': MultiPolygon(Polygon(((0, 0), (0, 2), (-1, 2), (0, 0))), Polygon(((-4, -2), (-6, -1), (-2, -2), (-4, -2)))) } command.save_batch([old_geo]) # Geo save worked self.assertEqual(1, Geo.objects.filter(geoid='1111111111').count()) census = Census2010Sex(total_pop=100, male=45, female=55) census.geoid_id = '1111111111' census.save() # Census data worked self.assertEqual(1, Census2010Sex.objects.all().count()) new_geo = old_geo.copy() new_geo['name'] = 'Geo in 2000' command.save_batch([new_geo]) # check that both models still exist query = Geo.objects.filter(geoid='1111111111') self.assertEqual(1, query.count()) self.assertEqual('Geo in 2000', query.get().name) self.assertEqual(1, Census2010Sex.objects.all().count()) Geo.objects.all().delete() Census2010Sex.objects.all().delete()
def test_micro(self): row = ('12345', 'Small Town', '', '12345', 'M2', '-45', '45', Polygon(((0, 0), (0, 2), (-1, 2), (0, 0)))) field_names = ('GEOID', 'NAME', 'CSAFP', 'CBSAFP', 'LSAD', 'INTPTLAT', 'INTPTLON') command = LoadGeos() geo = command.process_row(row, field_names) self.assertEqual('12345', geo['geoid']) self.assertEqual(Geo.MICRO_TYPE, geo['geo_type']) self.assertEqual('Small Town', geo['name']) self.assertEqual(None, geo['state']) self.assertEqual(None, geo['county']) self.assertEqual(None, geo['tract']) self.assertEqual(None, geo['csa']) self.assertEqual('12345', geo['cbsa'])
def test_metro(self): row = ('12345', 'Big City', '090', '12345', 'M1', '-45', '45', Polygon(((0, 0), (0, 2), (-1, 2), (0, 0)))) field_names = ('GEOID', 'NAME', 'CSAFP', 'CBSAFP', 'LSAD', 'INTPTLAT', 'INTPTLON') command = LoadGeos() geo = command.process_row(row, field_names) self.assertEqual('12345', geo.geoid) self.assertEqual(Geo.METRO_TYPE, geo.geo_type) self.assertEqual('Big City', geo.name) self.assertEqual(None, geo.state) self.assertEqual(None, geo.county) self.assertEqual(None, geo.tract) self.assertEqual('090', geo.csa) self.assertEqual('12345', geo.cbsa)
def test_metro(self): year = "2010" row = ('12345', 'Big City', '090', '12345', 'M1', '-45', '45', Polygon(((0, 0), (0, 2), (-1, 2), (0, 0)))) field_names = ('GEOID', 'NAME', 'CSAFP', 'CBSAFP', 'LSAD', 'INTPTLAT', 'INTPTLON') command = LoadGeos() geo = command.process_row(year, row, field_names) self.assertEqual('201012345', geo['geoid']) self.assertEqual(Geo.METRO_TYPE, geo['geo_type']) self.assertEqual('Big City', geo['name']) self.assertEqual(None, geo['state']) self.assertEqual(None, geo['county']) self.assertEqual(None, geo['tract']) self.assertEqual('090', geo['csa']) self.assertEqual('12345', geo['cbsa']) self.assertEqual("2010", geo['year'])
def test_census_tract(self): row = ('1122233333', 'Tract 33333', '11', '222', '33333', '-45', '45', Polygon(((0, 0), (0, 2), (-1, 2), (0, 0)))) field_names = ('GEOID', 'NAME', 'STATEFP', 'COUNTYFP', 'TRACTCE', 'INTPTLAT', 'INTPTLON') command = LoadGeos() geo = command.process_row(row, field_names) self.assertEqual('1122233333', geo['geoid']) self.assertEqual(Geo.TRACT_TYPE, geo['geo_type']) self.assertEqual('Tract 33333', geo['name']) self.assertEqual('11', geo['state']) self.assertEqual('222', geo['county']) self.assertEqual('33333', geo['tract']) self.assertEqual(None, geo['csa']) self.assertEqual(None, geo['cbsa']) self.assertEqual((-1, 0), (geo['minlon'], geo['maxlon'])) self.assertEqual((0, 2), (geo['minlat'], geo['maxlat'])) self.assertEqual(-45, geo['centlat']) self.assertEqual(45, geo['centlon'])
def test_census_tract(self): row = ('1122233333', 'Tract 33333', '11', '222', '33333', '-45', '45', Polygon(((0, 0), (0, 2), (-1, 2), (0, 0)))) field_names = ('GEOID', 'NAME', 'STATEFP', 'COUNTYFP', 'TRACTCE', 'INTPTLAT', 'INTPTLON') command = LoadGeos() geo = command.process_row(row, field_names) self.assertEqual('1122233333', geo.geoid) self.assertEqual(Geo.TRACT_TYPE, geo.geo_type) self.assertEqual('Tract 33333', geo.name) self.assertEqual('11', geo.state) self.assertEqual('222', geo.county) self.assertEqual('33333', geo.tract) self.assertEqual(None, geo.csa) self.assertEqual(None, geo.cbsa) self.assertEqual((-1, 0), (geo.minlon, geo.maxlon)) self.assertEqual((0, 2), (geo.minlat, geo.maxlat)) self.assertEqual(-45, geo.centlat) self.assertEqual(45, geo.centlon)
def test_county(self): poly1 = Polygon(((0, 0), (0, 2), (-1, 2), (0, 0))) poly2 = Polygon(((-4, -2), (-6, -1), (-2, -2), (-4, -2))) row = ('11222', 'Some County', '11', '222', '-45', '45', MultiPolygon(poly1, poly2)) field_names = ('GEOID', 'NAME', 'STATEFP', 'COUNTYFP', 'INTPTLAT', 'INTPTLON') command = LoadGeos() geo = command.process_row(row, field_names) self.assertEqual('11222', geo['geoid']) self.assertEqual(Geo.COUNTY_TYPE, geo['geo_type']) self.assertEqual('Some County', geo['name']) self.assertEqual('11', geo['state']) self.assertEqual('222', geo['county']) self.assertEqual(None, geo['tract']) self.assertEqual(None, geo['csa']) self.assertEqual(None, geo['cbsa']) self.assertEqual((-6, 0), (geo['minlon'], geo['maxlon'])) self.assertEqual((-2, 2), (geo['minlat'], geo['maxlat'])) self.assertEqual(-45, geo['centlat']) self.assertEqual(45, geo['centlon'])