1. Rufus Pollock
  2. wdmmg


wdmmg / wdmmg / tests / test_cra_2010.py

import pkg_resources, json

import wdmmg.model as model
from wdmmgext.load import cofog
from wdmmgext.load import cra2010
import os
from wdmmgext.load import util

class TestCRA(object):
    def setup_class(self):
        cofog.load_file(pkg_resources.resource_stream('wdmmg', 'tests/COFOG_english_structure_short_2010.txt'))
        cofog_mapper = util.CofogMapper(json.load(pkg_resources.resource_stream('wdmmg', 'tests/cofog_map_short_2010.json')))
        filename = os.path.abspath('wdmmg/tests/cra_2010_db_short.csv')
        cra2010.load_file(filename, cofog_mapper)
    def teardown_class(self):

	# check dataset exists
    def test_01_dataset(self):
        out = model.Dataset.find_one({'name': 'cra2010'})
        assert out, out

	# get all our keys, and check values exist for them
    # APS: why don't we check for the key 'to' at this point?   
    def test_02_classification(self):
        entry = model.Entry.find_one({'dataset.name': 'cra2010'})
        for key_name in [u'from', u'time', u'pog', u'cap_or_cur', u'region',
                u'cofog', u'cg_lg_or_pc']:
            assert key_name in entry.keys(), "Key %s is missing" % key_name

    # check there are some entries and none of them are null
    def test_03_entry(self):
        count = model.Entry.find({'dataset.name': 'cra2010'}).count()
        assert count, 'There are no Entries'
        assert not model.Entry.find({'dataset.name': 'cra2010', 
                                'amount': None}).count(), 'Some Entries have NULL amounts'
    # look for a 'to' field on the first entry in the dataset
    def test_04_entry_to(self):
        entry = model.Entry.find_one({'dataset.name': 'cra2010'})
        assert entry['to']['name'] == u'society'