Exemplo n.º 1
0
    def test_browser_for_entity(self):
        h.skip_if_stubbed_solr()

        from openspending.model import Dataset, Entry

        dataset = Dataset(name='testdataset')
        Dataset.c.save(dataset, manipulate=True)
        dataset_ref_dict = dataset.to_ref_dict()

        entity = self._make_one(name="Test Entity", label="Test Entity Label")
        entity_ref_dict = entity.to_ref_dict()

        entry = {'name': 'Test Entry',
                 'label': 'Test Entry Label',
                 'from': entity_ref_dict,
                 'to': entity_ref_dict,
                 'amount': 10.0,
                 'dataset': dataset_ref_dict}
        Entry.c.save(entry)

        h.clean_and_reindex_solr()

        entity_url = url(controller='entity', id=str(entity['_id']),
                         slug='test-entity-label', action='view')
        response = self.app.get(entity_url)

        h.assert_equal(response._status, '200 OK')
        h.assert_true('<b>1 entries</b> found.<br />' in response)
        h.assert_true('entries.json">' in response)
        h.assert_true('entries.csv">' in response)
Exemplo n.º 2
0
 def test_entity_as_json(self):
     entity = self._make_one(name="Test Entity", label="Test Entity Label")
     response = self.app.get(url(controller='entity',
                                 id=str(entity['_id']),
                                 action='view',
                                 format='json'))
     h.assert_equal(response._status, '200 OK')
     h.assert_equal(response._headers['Content-Type'], 'application/json')
     h.assert_true('"name": "Test Entity",' in response._body,
                     'json fragment not found. got: %s' % response._body)
Exemplo n.º 3
0
    def test_view_entries_csv(self):
        classifier = self.db['classifier'].find_one({'taxonomy': 'cofog',
                                                     'name': '03'})

        url_ = url(controller='classifier', action='entries', format='csv',
                   taxonomy=classifier['taxonomy'],
                   name=classifier['name'])
        result = self.app.get(url_)

        h.assert_equal(result.status, '200 OK')
        h.assert_equal(result.content_type, 'text/csv')
        h.assert_true(result.body.startswith('_id,amount,'))  # csv headers
Exemplo n.º 4
0
    def test_common_pageview(self):
        h.skip_if_stubbed_solr()

        entity = self._make_one(name="Test Entity", label="Test Entity Label")
        response = self.app.get(url(controller='entity',
                                    id=str(entity['_id']),
                                    slug='test-entity-label',
                                    action='view'))
        h.assert_equal(response._status, '200 OK')
        h.assert_true('Test Entity Label' in response)
        json_name = '%s.json' % entity['_id']
        h.assert_true(json_name in response,
                        'Entity json "%s" not found in output' % json_name)
Exemplo n.º 5
0
    def test_view_by_taxonomy_name_json(self):
        classifier = self.db['classifier'].find_one({'taxonomy': 'cofog',
                                                     'name': '03'})

        url_ = classifier_url(classifier, format='json')
        result = self.app.get(url_)

        h.assert_equal(result.status, '200 OK')
        h.assert_equal(result.content_type, 'application/json')

        json_data = json.loads(result.body)
        h.assert_equal(json_data['name'], u'03')
        h.assert_equal(json_data['label'], classifier['label'])
        h.assert_equal(json_data['_id'], str(classifier['_id']))
Exemplo n.º 6
0
    def test_view_by_taxonomy_name_html(self):
        classifier = self.db['classifier'].find_one({'taxonomy': 'cofog',
                                                     'name': '03'})
        url_ = classifier_url(classifier)
        result = self.app.get(url_)

        h.assert_equal(result.status, '200 OK')

        # Links to entries json and csv and entries listing
        h.assert_true('<a href="/classifier/cofog/03/entries.json">'
                        in result)
        h.assert_true('<a href="/classifier/cofog/03/entries.csv">'
                        in result)
        h.assert_true('<a href="/classifier/cofog/03/entries">Search</a>'
                        in result)

        # Search box and result listing from the solr browser
        h.assert_true('class="search-form' in result)
        h.assert_equal(result.body.count('full entry'), 5)
Exemplo n.º 7
0
 def test_aggregate(self):
     response = self.app.get(url(controller='api2', action='aggregate',
                                 dataset='cra'))
     h.assert_equal(response.status, '200 OK')
     h.assert_equal(response.content_type, 'application/json')
     result = json.loads(response.body)
     h.assert_equal(sorted(result.keys()), [u'drilldown', u'summary'])
     h.assert_equal(sorted(result['summary'].items()),
                      [(u'amount', -371500000.0),
                       (u'num_drilldowns', 36),
                       (u'num_entries', 36),
                       (u'page', 1),
                       (u'pages', 1),
                       (u'pagesize', 10000)])
Exemplo n.º 8
0
 def test_cut(self):
     response = self.app.get(url(controller='api2', action='aggregate',
                                 dataset='cra', cut='year:2009'))
     h.assert_equal(response.status, '200 OK')
     result = json.loads(response.body)
     h.assert_equal(result['summary']['num_drilldowns'], 7)
     h.assert_equal(result['summary']['amount'], 57300000.0)
Exemplo n.º 9
0
 def test_drilldown(self):
     response = self.app.get(url(controller='api2', action='aggregate',
                                 dataset='cra', drilldown='cofog1|cofog2'))
     h.assert_equal(response.status, '200 OK')
     result = json.loads(response.body)
     h.assert_equal(result['summary']['num_drilldowns'], 6)
     h.assert_equal(result['summary']['amount'], -371500000.0)
Exemplo n.º 10
0
    def test_view_entries_html(self):
        classifier = self.db['classifier'].find_one({'taxonomy': 'cofog',
                                                     'name': '03'})

        url_ = url(controller='classifier', action='entries', format='html',
                   taxonomy=classifier['taxonomy'],
                   name=classifier['name'])
        result = self.app.get(url_)
        h.assert_equal(result.status, '200 OK')
        h.assert_equal(result.content_type, 'text/html')
        h.assert_true(('<h2 class="page-title">Public order and '
                         'safety: Entries</h2>') in result)
        h.assert_equal(result.body.count('full entry'), 5)
Exemplo n.º 11
0
    def test_view_entries_json(self):
        classifier = self.db['classifier'].find_one({'taxonomy': 'cofog',
                                                     'name': '03'})

        url_ = url(controller='classifier', action='entries', format='json',
                   taxonomy=classifier['taxonomy'],
                   name=classifier['name'])
        result = self.app.get(url_)

        h.assert_equal(result.status, '200 OK')
        h.assert_equal(result.content_type, 'application/json')

        json_data = json.loads(result.body)
        h.assert_equal(len(json_data['results']), 5)
Exemplo n.º 12
0
    def test_order(self):
        def unique(seq):
            result = []
            for item in seq:
                if item not in result:
                    result.append(item)
            return result
        response = self.app.get(url(controller='api2', action='aggregate',
                                    dataset='cra', order='year:asc'))
        h.assert_equal(response.status, '200 OK')
        result = json.loads(response.body)
        order = [cell['year']  for cell in result['drilldown']]
        h.assert_equal(unique(order),
                         [2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010])

        response = self.app.get(url(controller='api2', action='aggregate',
                                    dataset='cra', order='year:desc'))
        h.assert_equal(response.status, '200 OK')
        result = json.loads(response.body)
        order = [cell['year']  for cell in result['drilldown']]
        h.assert_equal(unique(order),
                         [2010, 2009, 2008, 2007, 2006, 2005, 2004, 2003])
Exemplo n.º 13
0
 def test_number_of_entries(self):
     url_ = url(controller='dataset', action='view', id='cra')
     response = self.app.get(url_)
     h.assert_equal(response.tmpl_context.num_entries, 36)