Example #1
0
    def test_should_create_load_edit_datadict(self):
        FIRST_NAME_SLUG = 'first_name'

        name_type = create_datadict_type(self.dbm, name='First name', slug=FIRST_NAME_SLUG, primitive_type='string')

        saved_type = get_datadict_type(self.dbm, name_type.id)
        self.assertEqual(name_type.id, saved_type.id)
        self.assertEqual(name_type.slug, saved_type.slug)

        ddtype = get_datadict_type_by_slug(self.dbm, slug=FIRST_NAME_SLUG)

        self.assertEqual(name_type.id, ddtype.id)
        self.assertEqual(name_type.slug, ddtype.slug)

        ddtype.description = "new desc"
        ddtype.save()

        saved = get_datadict_type_by_slug(self.dbm, slug=FIRST_NAME_SLUG)
        self.assertEqual("new desc", saved.description)
Example #2
0
    def test_should_create_load_edit_datadict(self):
        FIRST_NAME_SLUG = 'first_name'

        name_type = create_datadict_type(self.dbm,
                                         name='First name',
                                         slug=FIRST_NAME_SLUG,
                                         primitive_type='string')

        saved_type = get_datadict_type(self.dbm, name_type.id)
        self.assertEqual(name_type.id, saved_type.id)
        self.assertEqual(name_type.slug, saved_type.slug)

        ddtype = get_datadict_type_by_slug(self.dbm, slug=FIRST_NAME_SLUG)

        self.assertEqual(name_type.id, ddtype.id)
        self.assertEqual(name_type.slug, ddtype.slug)

        ddtype.description = "new desc"
        ddtype.save()

        saved = get_datadict_type_by_slug(self.dbm, slug=FIRST_NAME_SLUG)
        self.assertEqual("new desc", saved.description)
Example #3
0
 def test_should_raise_exception_if_datadict_not_found(self):
     with self.assertRaises(DataObjectNotFound):
         get_datadict_type(self.dbm, "ID not in db")
Example #4
0
 def test_should_raise_exception_if_datadict_not_found(self):
     with self.assertRaises(DataObjectNotFound):
         get_datadict_type(self.dbm, "ID not in db")
Example #5
0
                        name=name,
                        primitive_type=primitive_type,
                        tags=tags
                    )
                    datadict_types[slug] = dd_type.id

            for row in nims_data['Population Data']:
                state = get_string('state', row)
                lga = get_string('lga', row)
                location = ("Nigeria", state, lga)
                data = []
                if not state or not lga:
                    continue
                for dd_key in datadict_types.keys():
                    ss_key = dd_key.replace('_', '')
                    point = (dd_key, get_number(ss_key, row), get_datadict_type(dbm, datadict_types[dd_key]))
                    data.append(point)
                if location in locations:
                    lga_loaded.append(lga)
                    e = dbm.get(locations[location], Entity)
                    e.add_data(data, event_time=datetime.datetime(2011, 03, 01, tzinfo=UTC), multiple_records=True)
                    print [(key, value) for (key, value, typ) in data]
                else:
                    if not lga in lga_failed:
                        lga_failed.append(lga)

            print "Loaded %d out of %d records" % (len(lga_loaded), len(lga_failed) + len(lga_loaded))
            if lga_failed:
                print "%d LGAs failed to load:" % len(lga_failed)
                for lga in lga_failed:
                    print "\t%s" % lga
Example #6
0
                        name=name,
                        primitive_type=primitive_type,
                        tags=tags)
                    datadict_types[slug] = dd_type.id

            for row in nims_data['Population Data']:
                state = get_string('state', row)
                lga = get_string('lga', row)
                location = ("Nigeria", state, lga)
                data = []
                if not state or not lga:
                    continue
                for dd_key in datadict_types.keys():
                    ss_key = dd_key.replace('_', '')
                    point = (dd_key, get_number(ss_key, row),
                             get_datadict_type(dbm, datadict_types[dd_key]))
                    data.append(point)
                if location in locations:
                    lga_loaded.append(lga)
                    e = dbm.get(locations[location], Entity)
                    e.add_data(data,
                               event_time=datetime.datetime(2011,
                                                            03,
                                                            01,
                                                            tzinfo=UTC),
                               multiple_records=True)
                    print[(key, value) for (key, value, typ) in data]
                else:
                    if not lga in lga_failed:
                        lga_failed.append(lga)