Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
FuhuXia committed Mar 4, 2025
1 parent 0ef72d9 commit e6b32d6
Show file tree
Hide file tree
Showing 20 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions ckanext/geodatagov/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ def tracking_update(start_date: Optional[str]):
tracking.update_tracking_solr = update_tracking_solr
tracking.update_all(start_date)


def update_tracking_solr(start_date: datetime.datetime):
"""copied from ckanext/tracking/cli/tracking.py
but with customized way of doing solr indexing
Expand Down
1 change: 0 additions & 1 deletion ckanext/geodatagov/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@ def clean_deleted(self):
# u'dataDictionary': 5841, u'temporal': 5830, u'modified': 5809, u'issued': 5793, u'mbox': 5547,
# u'granularity': 4434, u'license': 2048, u'dataQuality': 453}


def harvest_job_cleanup(self):
if p.toolkit.check_ckan_version(min_version='2.8'):
print('Task removed since new ckanext-harvest include ckan.harvest.timeout to mark as finished stuck jobs')
Expand Down
1 change: 1 addition & 0 deletions ckanext/geodatagov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ def get_auth_functions(self):
'group_catagory_tag_update': geodatagov_auth.group_catagory_tag_update,
}


class S3Test(p.SingletonPlugin):

p.implements(p.IClick)
Expand Down
3 changes: 2 additions & 1 deletion ckanext/geodatagov/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
def run_once_for_all_tests():
utils.simple_http_server()


@pytest.fixture(scope="class", autouse=True)
def run_for_every_test_class():
utils.reset_db_and_solr()
utils.reset_db_and_solr()
1 change: 1 addition & 0 deletions ckanext/geodatagov/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

log = logging.getLogger(__name__)


class HarvestSource(factory.Factory):
FACTORY_FOR = harvest_model.HarvestSource
_return_type = 'dict'
Expand Down
1 change: 1 addition & 0 deletions ckanext/geodatagov/tests/test_category_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

log = logging.getLogger(__name__)


@pytest.mark.usefixtures("with_plugins")
class TestCategoryTags(object):

Expand Down
1 change: 1 addition & 0 deletions ckanext/geodatagov/tests/test_datajson.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

log = logging.getLogger(__name__)


@pytest.mark.usefixtures("with_plugins")
class TestDataJsonHarvester(object):

Expand Down
1 change: 1 addition & 0 deletions ckanext/geodatagov/tests/test_db_solr_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

log = logging.getLogger(__name__)


@pytest.mark.usefixtures("with_plugins")
class TestSolrDBSync(object):

Expand Down
1 change: 1 addition & 0 deletions ckanext/geodatagov/tests/test_fix_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

log = logging.getLogger(__name__)


@pytest.mark.usefixtures("with_plugins")
class TestFixPkg(object):

Expand Down
1 change: 1 addition & 0 deletions ckanext/geodatagov/tests/test_fix_spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from utils import populate_locations_table


@pytest.mark.usefixtures("with_plugins")
class TestSpatialField(object):

Expand Down
1 change: 0 additions & 1 deletion ckanext/geodatagov/tests/test_json_export.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging

from ckan.tests.helpers import reset_db
from ckan.tests import factories


Expand Down
1 change: 1 addition & 0 deletions ckanext/geodatagov/tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from utils import populate_locations_table


class TestLogic(FunctionalTestBase):

def setup_method(self):
Expand Down
2 changes: 1 addition & 1 deletion ckanext/geodatagov/tests/test_relink.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import ckan.model as model
import ckan.lib.search as search
from ckan.tests import factories
from ckan.tests.helpers import reset_db
from click.testing import CliRunner
from ckanext.harvest.model import HarvestObject
from ckanext.harvest.tests import factories as harvest_factories
Expand All @@ -19,6 +18,7 @@

log = logging.getLogger(__name__)


class TestRelink(object):

@classmethod
Expand Down
1 change: 1 addition & 0 deletions ckanext/geodatagov/tests/test_s3test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

log = logging.getLogger(__name__)


class TestS3TestCommand(object):
@pytest.fixture
def txt_cli_result(self) -> Result:
Expand Down
1 change: 1 addition & 0 deletions ckanext/geodatagov/tests/test_sitemap_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# TODO - test for output, test checking complete s3 cycle


class TestSitemapExport(object):

def create_datasets(self) -> None:
Expand Down
1 change: 1 addition & 0 deletions ckanext/geodatagov/tests/test_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

log = logging.getLogger(__name__)


@pytest.mark.usefixtures("with_plugins")
class TestTracking(object):

Expand Down
2 changes: 1 addition & 1 deletion ckanext/geodatagov/tests/test_waf-collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

log = logging.getLogger(__name__)


@pytest.mark.usefixtures("with_plugins")
class TestWafCollectionHarvester(object):

Expand All @@ -23,7 +24,6 @@ def setup_method(self):

self.organization = Organization()


def run_gather(self, url, source_config):

sc = json.loads(source_config)
Expand Down
3 changes: 2 additions & 1 deletion ckanext/geodatagov/tests/test_waf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

log = logging.getLogger(__name__)


@pytest.mark.usefixtures("with_plugins")
class TestWafHarvester(object):

Expand All @@ -23,7 +24,7 @@ def setup_method(self):
self.organization = Organization()

def run_gather(self, url, source_config):

sc = json.loads(source_config)

source = WafHarvestSourceObj(url=url,
Expand Down
1 change: 1 addition & 0 deletions ckanext/geodatagov/tests/test_waf_GMI.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

log = logging.getLogger(__name__)


@pytest.mark.usefixtures("with_plugins")
class TestWafHarvester(object):

Expand Down
21 changes: 15 additions & 6 deletions ckanext/geodatagov/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

PORT = 8999


def simple_http_server(port=PORT):
'''Serves test XML files over HTTP'''

Expand Down Expand Up @@ -41,21 +42,32 @@ class TestServer(socketserver.TCPServer):
httpd_thread.setDaemon(True)
httpd_thread.start()


def populate_locations_table():
# download locations.sql.gz if not present
if not os.path.exists('/tmp/locations.sql.gz'):
os.system("wget https://github.com/GSA/datagov-deploy/raw/71936f004be1882a506362670b82c710c64ef796/"
"ansible/roles/software/ec2/ansible/files/locations.sql.gz -O /tmp/locations.sql.gz")
os.system(
"wget https://github.com/GSA/datagov-deploy/raw/71936f004be1882a506362670b82c710c64ef796/"
"ansible/roles/software/ec2/ansible/files/locations.sql.gz "
"-O /tmp/locations.sql.gz"
)
# echo "Creating locations table"
os.system("PGPASSWORD=ckan psql -h db -U ckan -d ckan -c 'DROP TABLE IF EXISTS locations;'")
os.system("PGPASSWORD=ckan psql -h db -U ckan -d ckan -c 'DROP SEQUENCE IF EXISTS locations_id_seq;'")
os.system("gunzip -c /tmp/locations.sql.gz | PGPASSWORD=ckan psql -h db -U ckan -d ckan -v ON_ERROR_STOP=1")


def reset_db_and_solr():
# https://github.com/ckan/ckan/issues/4764
# drop extension postgis so we can reset db
try:
os.system("PGPASSWORD=ckan psql -h db -U ckan -d ckan -c 'SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE datname = current_database() AND pid <> pg_backend_pid();'")
os.system(
"PGPASSWORD=ckan psql -h db -U ckan -d ckan -c "
"'SELECT pg_terminate_backend(pg_stat_activity.pid) "
" FROM pg_stat_activity WHERE "
" datname = current_database() AND"
" pid <> pg_backend_pid();'"
)
except Exception:
pass
os.system("PGPASSWORD=ckan psql -h db -U ckan -d ckan -c 'drop extension IF EXISTS postgis cascade;'")
Expand All @@ -68,6 +80,3 @@ def reset_db_and_solr():
metadata.create_all(bind=Session.bind)

search.clear_all()



0 comments on commit e6b32d6

Please sign in to comment.