class TestCsvReader(unittest.TestCase): def setUp(self): file_name = 'test.csv' dirname = os.path.dirname(__file__) abspath = os.path.abspath(dirname) file_path = os.path.join(abspath, file_name) self.csv_reader = CsvReader(file_path) def test_iteritems(self): expected_list = [ { 'one': '1', 'two': '2', 'three': '3', }, ] actual_list = list(self.csv_reader.iter_dicts()) self.assertEquals(expected_list, actual_list)
def setUp(self): file_name = 'test.csv' dirname = os.path.dirname(__file__) abspath = os.path.abspath(dirname) file_path = os.path.join(abspath, file_name) self.csv_reader = CsvReader(file_path)
if lga_failed: print "%d LGAs failed to load:" % len(lga_failed) for lga in lga_failed: print "\t%s" % lga if load_health: print "Adding Facility data..." print "Adding Health Clinics and associated data" file_name = 'health.csv' dirname = settings.DATA_DIRECTORY abspath = os.path.abspath(dirname) file_path = os.path.join(abspath, file_name) try: csv_reader = CsvReader(file_path) except IOError: raise IOError("File not found: %s. You may need to install dropbox and upload DATA_DIRECTORY in settings.py." % file_path) num_rows = 0 things_to_build = [] for row in csv_reader.iter_dicts(): num_rows += 1 if num_rows > max_facilities_to_import: break geo_id = get_string('geoid', row) geocode = get_string('geocodeoffacility', row).split() lat, long = None, None if geocode and len(geocode) >= 2: lat = float(geocode[0]) long = float(geocode[1]) else:
if lga_failed: print "%d LGAs failed to load:" % len(lga_failed) for lga in lga_failed: print "\t%s" % lga if load_health: print "Adding Facility data..." print "Adding Health Clinics and associated data" file_name = 'health.csv' dirname = settings.DATA_DIRECTORY abspath = os.path.abspath(dirname) file_path = os.path.join(abspath, file_name) try: csv_reader = CsvReader(file_path) except IOError: raise IOError( "File not found: %s. You may need to install dropbox and upload DATA_DIRECTORY in settings.py." % file_path) num_rows = 0 things_to_build = [] for row in csv_reader.iter_dicts(): num_rows += 1 if num_rows > max_facilities_to_import: break geo_id = get_string('geoid', row) geocode = get_string('geocodeoffacility', row).split() lat, long = None, None if geocode and len(geocode) >= 2: lat = float(geocode[0])