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):
    @classmethod
    def setup_class(self):
        model.mongo.drop_db()
        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)
        
    @classmethod
    def teardown_class(self):
        model.mongo.drop_db()

	# 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'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.