test_api.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import pytest
  2. import tempfile
  3. from ckan import model
  4. from ckan import plugins
  5. from ckan.tests import factories
  6. import ckan.tests.helpers as helpers
  7. from ckanext.archiver import model as archiver_model
  8. from ckanext.archiver.tasks import update_package
  9. @pytest.mark.usefixtures('with_plugins')
  10. @pytest.mark.ckan_config("ckanext-archiver.cache_url_root", "http://localhost:50001/resources/")
  11. @pytest.mark.ckan_config("ckanext-archiver.max_content_length", 1000000)
  12. @pytest.mark.ckan_config("ckan.plugins", "archiver testipipe")
  13. class TestApi(object):
  14. @pytest.fixture(autouse=True)
  15. @pytest.mark.usefixtures(u"clean_db")
  16. def initial_data(cls, clean_db):
  17. archiver_model.init_tables(model.meta.engine)
  18. cls.temp_dir = tempfile.mkdtemp()
  19. def test_package_show(self, client):
  20. url = client + '/?status=200&content=test&content-type=csv'
  21. testipipe = plugins.get_plugin('testipipe')
  22. testipipe.reset()
  23. pkg_dict = {
  24. 'name': 'test-package-api',
  25. 'resources': [
  26. {
  27. 'url': url,
  28. 'format': 'TXT',
  29. 'description': 'Test'
  30. }
  31. ]
  32. }
  33. pkg = factories.Dataset(**pkg_dict)
  34. update_package(pkg['id'])
  35. result = helpers.call_action(
  36. "package_show",
  37. id=pkg["id"]
  38. )
  39. print(result)
  40. assert 'archiver' in result.keys()