Example #1
0
 def test_get_classifier(self):
     testname = 'testname'
     testtaxonomy = 'testtaxonomy'
     created = logic.classifier.create_classifier(testname, testtaxonomy)
     fetched = logic.classifier.get_classifier(testname, testtaxonomy)
     h.assert_true(isinstance(fetched, Classifier))
     h.assert_false(created is fetched)
     h.assert_equal(created, fetched)
    def test_reads_unicode(self):
        reader = udr.UnicodeDictReader(h.fixture_file('simple.csv'))
        lines = [ l for l in reader ]

        h.assert_true(isinstance(lines[0].keys()[0], unicode),
                      "Keys in UnicodeDictReader dicts should be unicode.")
        h.assert_true(isinstance(lines[0].values()[0], unicode),
                      "Values in UnicodeDictReader dicts should be unicode.")
Example #3
0
    def test_compute_cube(self):
        from openspending.model import Dataset

        cra = h.load_fixture('cra')

        cube = Cube.configure_default_cube(cra)
        cube.compute()

        h.assert_true('cubes.cra.default' in mongo.db().collection_names())
Example #4
0
    def test_create_classifier_does_not_delete_attributes_in_existing(self):
        classifier = logic.classifier.create_classifier(u'Test Classifier',
                                                        taxonomy=u'taxonomy',
                                                        extra=u'extra')
        h.assert_true('extra' in classifier)

        upserted_classifier = logic.classifier.create_classifier(u'Test Classifier',
                                                                 taxonomy=u'taxonomy')
        h.assert_true('extra' in upserted_classifier)
Example #5
0
 def test_classify_entry(self):
     entry = {'name': u'Test Entry',
              'amount': 1000.00}
     c_name = u'support-transparency'
     c_taxonomy = u'Good Reasons'
     c_label = u'Support Transparency Initiatives'
     classifier = logic.classifier.create_classifier(name=c_name,
                                                     label=c_label,
                                                     taxonomy=c_taxonomy)
     logic.entry.classify_entry(entry, classifier, name=u'reason')
     h.assert_equal(entry.keys(), [u'reason', 'amount', 'name',
                                     'classifiers'])
     h.assert_equal(entry['classifiers'], [classifier['_id']])
     h.assert_equal(entry['reason']['label'], c_label)
     h.assert_equal(entry['reason']['name'], c_name)
     h.assert_equal(entry['reason']['taxonomy'], c_taxonomy)
     h.assert_true(isinstance(entry['reason']['ref'], DBRef))
Example #6
0
    def test_distincts(self):
        testdataset = self._make_dataset(name='testdataset')
        self._make_entry(name='one', region="Region 1", region2="Region 2",
                         dataset=testdataset)
        self._make_entry(name='two', region="Region 2", region2="Region 3",
                         dataset=testdataset)

        db = model.mongo.db()
        h.assert_true('compute_distincts' in db.system_js.list())

        # compute a distincts collection
        db.system_js.compute_distincts('testdataset')
        h.assert_true('distincts__testdataset' in db.collection_names())

        # test the distincts collection manually
        distinct_regions = db.distincts__testdataset.find({
            'value.keys': u'region'
        }).distinct('_id')
        h.assert_equal(sorted(distinct_regions), [u'Region 1', u'Region 2'])

        distincts = logic.entry.distinct('region', dataset_name='testdataset')
        h.assert_equal(sorted(distincts), [u'Region 1', u'Region 2'])
Example #7
0
    def test_distincts_create_collection(self):
        testdataset = self._make_dataset(name='testdataset')
        self._make_entry(name='one', region="Region 1", region2="Region 2",
                         dataset=testdataset)
        self._make_entry(name='two', region="Region 2", region2="Region 3",
                         dataset=testdataset)

        db = model.mongo.db()
        h.assert_true('compute_distincts' in db.system_js.list())

        # compute a distincts collection
        h.assert_true('distincts__testdataset' not in db.collection_names())

        distincts = logic.entry.distinct('region', dataset_name='testdataset')
        h.assert_true('distincts__testdataset' in db.collection_names())
        h.assert_equal(sorted(distincts), [u'Region 1', u'Region 2'])
 def test_is_compound(self):
     h.assert_true(self.entity.is_compound)
Example #9
0
 def test_is_compound(self):
     h.assert_true(self.entity.is_compound)
Example #10
0
 def test_package_init(self):
     p = ckan.Package('foo')
     h.assert_true(isinstance(p, ckan.Package))
Example #11
0
 def test_create_classifier(self):
     classifier = logic.classifier.create_classifier(name=u'Test Classifier',
                                                     taxonomy=u'taxonomy')
     h.assert_true(isinstance(classifier, Classifier))