From 3b55d6c994f9a22e3890e11667a90f1034e55025 Mon Sep 17 00:00:00 2001 From: Jin-Sun-tts Date: Thu, 27 Feb 2025 15:31:10 -0500 Subject: [PATCH] fixed test_waf and test_was_GMI tests --- Dockerfile | 2 +- ckanext/geodatagov/tests/test_waf.py | 24 +++++++++++++++++++----- ckanext/geodatagov/tests/test_waf_GMI.py | 18 +++++++++++++----- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index ca449a26..f4213457 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ARG CKAN_VERSION USER root -RUN apt-get update && apt-get install -y postgresql-client +RUN apt-get update && apt-get install -y postgresql-client openjdk-17-jre # Download Saxon jar for FGDC2ISO transform (geodatagov) ARG saxon_ver=9.9.1-7 diff --git a/ckanext/geodatagov/tests/test_waf.py b/ckanext/geodatagov/tests/test_waf.py index addaa1d6..41e1d1ad 100644 --- a/ckanext/geodatagov/tests/test_waf.py +++ b/ckanext/geodatagov/tests/test_waf.py @@ -10,10 +10,13 @@ from ckan.tests.helpers import reset_db from ckan.tests.factories import Organization, SysadminWithToken +import pytest +import os +from ckan.model.meta import Session, metadata log = logging.getLogger(__name__) - +@pytest.mark.usefixtures("with_plugins") class TestWafHarvester(object): @classmethod @@ -21,13 +24,24 @@ def setup_class(cls): log.info('Starting mock http server') mock_static_file_server.serve() - @classmethod - def setup(cls): + # @classmethod + # def setup(cls): + # reset_db() + # cls.organization = Organization() + + def setup_method(self): + # https://github.com/ckan/ckan/issues/4764 + # drop extension postgis so we can reset db + os.system("PGPASSWORD=ckan psql -h db -U ckan -d ckan -c 'drop extension IF EXISTS postgis cascade;'") reset_db() - cls.organization = Organization() + os.system("PGPASSWORD=ckan psql -h db -U ckan -d ckan -c 'create extension postgis;'") + # os.system("ckan -c test.ini db upgrade -p harvest") + metadata.create_all(bind=Session.bind) - def run_gather(self, url, source_config): + self.organization = Organization() + def run_gather(self, url, source_config): + sc = json.loads(source_config) source = WafHarvestSourceObj(url=url, diff --git a/ckanext/geodatagov/tests/test_waf_GMI.py b/ckanext/geodatagov/tests/test_waf_GMI.py index e07321d6..525b2a9e 100644 --- a/ckanext/geodatagov/tests/test_waf_GMI.py +++ b/ckanext/geodatagov/tests/test_waf_GMI.py @@ -9,10 +9,13 @@ from ckan.tests.helpers import reset_db from ckan.tests.factories import Organization +import pytest +import os +from ckan.model.meta import Session, metadata log = logging.getLogger(__name__) - +@pytest.mark.usefixtures("with_plugins") class TestWafHarvester(object): @classmethod @@ -20,13 +23,18 @@ def setup_class(cls): log.info('Starting mock http server') mock_static_file_server.serve() - @classmethod - def setup(cls): + def setup_method(self): + # https://github.com/ckan/ckan/issues/4764 + # drop extension postgis so we can reset db + os.system("PGPASSWORD=ckan psql -h db -U ckan -d ckan -c 'drop extension IF EXISTS postgis cascade;'") reset_db() - cls.organization = Organization() + os.system("PGPASSWORD=ckan psql -h db -U ckan -d ckan -c 'create extension postgis;'") + # os.system("ckan -c test.ini db upgrade -p harvest") + metadata.create_all(bind=Session.bind) - def run_gather(self, url, source_config): + self.organization = Organization() + def run_gather(self, url, source_config): sc = json.loads(source_config) source = WafHarvestSourceObj(url=url,