Source

wdmmg / wdmmg / tests / test_loader.py

Full commit
from wdmmg import model
from wdmmg.lib import loader

test_data = {
    (u'red', u'flowery'): 30.0,
    (u'red', u'pungent'): 30.0,
    (u'red', None): 30.0,
    (u'green', u'flowery'): 30.0,
    (u'green', u'pungent'): 30.0,
}

class TestLoader(object):
    @classmethod
    def setup_class(self):
        print 'setting up TestLoader'
        # Load an example data set.
        my_loader = loader.Loader(u'test', 'Test Dataset')
        for (col, smell), a in test_data.items():
            my_loader.create_entry(a, colour=col, smell=smell)

    @classmethod
    def teardown_class(self):
        # Clean up.
        model.mongo.drop_db()

    def test_loader(self):
        print 'test_loader'
        # Read it back and see what we've got.
        entries = model.Entry.find()
        assert entries.count() == 5, entries.count()
        pairs = set()
        for t in entries:
            pairs.add((t.get('colour'), t.get('smell')))
        assert pairs == set(test_data.keys()), pairs