[ckan-changes] commit/ckanext-dgu: amercader: [tests] Fix HTML filter tests

Bitbucket commits-noreply at bitbucket.org
Mon Nov 14 18:08:55 UTC 2011


1 new commit in ckanext-dgu:


https://bitbucket.org/okfn/ckanext-dgu/changeset/2f74841435c1/
changeset:   2f74841435c1
user:        amercader
date:        2011-11-14 19:08:17
summary:     [tests] Fix HTML filter tests
affected #:  3 files

diff -r ef03bd82c3cfaf0bcbec40a412e904c9d408f71c -r 2f74841435c14ade2b5fd9fc02b6499e01ad4b95 ckanext/dgu/tests/__init__.py
--- a/ckanext/dgu/tests/__init__.py
+++ b/ckanext/dgu/tests/__init__.py
@@ -285,6 +285,13 @@
                            guid='test-guid',
                            content='<xml>test content</xml>')
         ho.save()
+
+        # Save a reference to the harvest object in the package
+        rev = model.repo.new_revision()    
+        pkg = model.Package.by_name(u'annakarenina')
+        pkg.extras['harvest_object_id'] = ho.id
+        pkg.save()
+
         model.repo.commit_and_remove()
 
     @classmethod


diff -r ef03bd82c3cfaf0bcbec40a412e904c9d408f71c -r 2f74841435c14ade2b5fd9fc02b6499e01ad4b95 ckanext/dgu/tests/functional/test_filters.py
--- a/ckanext/dgu/tests/functional/test_filters.py
+++ b/ckanext/dgu/tests/functional/test_filters.py
@@ -4,17 +4,17 @@
 from ckan.lib.package_saver import PackageSaver
 from ckan.lib.create_test_data import CreateTestData
 from ckan.lib.base import render, c, h, g
-import ckan.logic.action.get as get
+from ckan.logic import get_action
 from ckan import model
 
-from ckanext.dgu.stream_filters import harvest_filter
+from ckanext.dgu.stream_filters import harvest_filter, package_id_filter
 
 from ckan.tests import TestController as ControllerTestCase
 from ckan.tests.pylons_controller import PylonsTestCase
 from ckan.tests.html_check import HtmlCheckMethods
 from ckanext.dgu.tests import HarvestFixture
 
-class TestHarvestFilter(PylonsTestCase, HtmlCheckMethods,
+class FilterTestCase(PylonsTestCase, HtmlCheckMethods,
                         ControllerTestCase, HarvestFixture):
     @classmethod
     def setup_class(cls):
@@ -34,7 +34,7 @@
         context = {'model': model, 'session': model.Session,
                    'user': c.user,
                    'package':c.pkg}
-        c.pkg_dict = get.package_show(context, {'id':c.pkg.id})
+        c.pkg_dict = get_action('package_show')(context, {'id':c.pkg.id})
 
         # inject a mock-routes_dict into the environ in order
         # that the template can be rendered correctly.
@@ -45,7 +45,7 @@
             'action': 'test-action',
             'controller': 'test-package::',
         }})
-        
+
         # Render package view page
         # (filter should not be called on this occasion)
         PackageSaver().render_package(c.pkg_dict,
@@ -53,9 +53,12 @@
         cls.pkg_page = render('package/read.html')
 
         # Expected URLs
-        cls.harvest_xml_url = '/api/2/rest/harvestobject/test-guid/xml'
-        cls.harvest_html_url = '/api/2/rest/harvestobject/test-guid/html'
-    
+        harvest_object_id = c.pkg.extras.get('harvest_object_id')
+        cls.harvest_xml_url = '/api/2/rest/harvestobject/%s/xml' % harvest_object_id
+        cls.harvest_html_url = '/api/2/rest/harvestobject/%s/html' % harvest_object_id
+
+class TestHarvestFilter(FilterTestCase):
+
     def test_basic(self):
         pkg_id = c.pkg.id
 
@@ -66,7 +69,6 @@
 
         res = harvest_filter(HTML(self.pkg_page), c.pkg)
         res = res.render('html').decode('utf8')
-        main_res = self.main_div(res)
 
         # after filter
         self.check_named_element(res, 'a', 'href="%s"' % self.harvest_xml_url)
@@ -80,4 +82,19 @@
         res = self.app.get(self.harvest_html_url)
         assert 'GEMINI record' in res.body
         assert 'error' not in res.body
-        
+
+class TestPackageIdFilter(FilterTestCase):
+
+    def test_basic(self):
+        pkg_id = c.pkg.id
+
+        # before filter
+        # <a href="http://www.annakarenina.com/download/x=1&y=2" target="_blank">Full text. Needs escaping: " Umlaut: u</a>
+        self.check_named_element(self.pkg_page, 'h3', '!ID')
+
+        res = package_id_filter(HTML(self.pkg_page), c.pkg)
+        res = res.render('html').decode('utf8')
+
+        # after filter
+        self.check_named_element(res, 'h3', 'ID')
+


diff -r ef03bd82c3cfaf0bcbec40a412e904c9d408f71c -r 2f74841435c14ade2b5fd9fc02b6499e01ad4b95 ckanext/dgu/tests/test_filters.py
--- a/ckanext/dgu/tests/test_filters.py
+++ b/ckanext/dgu/tests/test_filters.py
@@ -37,10 +37,13 @@
     def setup_class(cls):
         HarvestFixture.setup_class()
         cls.pkg_page = HTML(basic_package_page)
-    
+
     def test_basic(self):
-        harvest_xml_url = '/api/2/rest/harvestobject/test-guid/xml'
-        harvest_html_url = '/api/2/rest/harvestobject/test-guid/html'
+
+        pkg = model.Package.by_name(u'annakarenina')
+        harvest_object_id = pkg.extras.get('harvest_object_id')
+        harvest_xml_url = '/api/2/rest/harvestobject/%s/xml' % harvest_object_id
+        harvest_html_url = '/api/2/rest/harvestobject/%s/html' % harvest_object_id
 
         # before filter
         pkg_page = HTML(self.pkg_page).render()
@@ -62,7 +65,7 @@
     @classmethod
     def setup_class(cls):
         cls.pkg_page = HTML(basic_package_page)
-        
+
     def test_basic(self):
         self.pkg_url = 'http://site.com/data.csv'
         self.archive_url = 'http://webarchive.nationalarchives.gov.uk/tna/+/' + self.pkg_url
@@ -72,7 +75,7 @@
         self.pkg_page = HTML(self.pkg_page).render()
         self.check_named_element(self.pkg_page, 'a', 'href="%s"' % self.pkg_url)
         self.check_named_element(self.pkg_page, 'a', '!href="%s"' % self.archive_url)
-        
+
         res = archive_filter(HTML(self.pkg_page))
         res = res.render('html').decode('utf8')
         print res

Repository URL: https://bitbucket.org/okfn/ckanext-dgu/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list