Esempio n. 1
0
    def handle(self, *args, **kwargs):
        print kwargs
        data_loader = DataLoader(**kwargs)

        # If no arguments are given to this command run all the import
        # methods.
        if len(args) == 0:
            data_loader.setup()
            if kwargs['limit_import']:
                lga_ids = settings.LIMITED_LGA_LIST
            else:
                lga_ids = [str(i['id']) for i in LGA.objects.filter(data_available=True).values('id')]
            if not kwargs['spawn_subprocess']:
                #load fixtures the old fashioned way.
                data_loader.load(lga_ids)
                data_loader.print_stats()
            else:
                print "Starting subprocess to load lga data in."
                ccargs = ['load_lgas'] + lga_ids
                #calling "load_lgas" with arguments.
                call_command(*ccargs)

        # If arguments have been given to this command, run those
        # methods in the order they have been specified.
        for arg in args:
            if hasattr(data_loader, arg):
                method = getattr(data_loader, arg)
                method()
            else:
                print "Unknown command:", arg
Esempio n. 2
0
class ImportDataTest(TestCase):

    def setUp(self):
        self.data_loader = DataLoader()

    def test_create_sectors(self):
        self.data_loader.create_sectors()
        sectors = dict([(s.slug, s.name) for s in Sector.objects.all()])
        expected_dict = {
            'education': 'Education',
            'health': 'Health',
            'water': 'Water'
            }
        self.assertEquals(sectors, expected_dict)

    def test_create_facility_types(self):
        self.data_loader.create_facility_types()
        self.assertEquals(FacilityType.objects.count(), 23)

    def test_limited_import(self):
        # this needs to be rewritten with small csvs

        # data_loader.load()
        # expected_info = {
        #     "number of facilities": 41,
        #     "unused variables": [],
        #     "facilities without lgas": 0,
        #     "number of lga records": 183,
        #     "number of facility records": 4419
        #     }
        # self.assertEquals(data_loader.get_info(), expected_info)
        pass

    def count_all_objects(self):
        result = {}
        for ct in ContentType.objects.all():
            result[ct.natural_key()] = ct.model_class().objects.count()
        return result
Esempio n. 3
0
 def setUp(self):
     self.data_loader = DataLoader()