diff --git a/ckanext/gbif/lib/__init__.py b/ckanext/gbif/lib/__init__.py index 196d2ad..9d2a2dd 100644 --- a/ckanext/gbif/lib/__init__.py +++ b/ckanext/gbif/lib/__init__.py @@ -9,5 +9,5 @@ def main(): pass -if __name__ == u'__main__': +if __name__ == '__main__': main() diff --git a/ckanext/gbif/lib/helpers.py b/ckanext/gbif/lib/helpers.py index de5e3a1..24901f9 100644 --- a/ckanext/gbif/lib/helpers.py +++ b/ckanext/gbif/lib/helpers.py @@ -83,9 +83,9 @@ def gbif_get_classification(gbif_record): def gbif_get_geography(occurrence): - ''' + """ :param occurrence: - ''' + """ geography = [] for geographic_part in ['continent', 'country', 'stateprovince']: value = occurrence.get(geographic_part, None) diff --git a/ckanext/gbif/logic/action.py b/ckanext/gbif/logic/action.py index 4fa7b20..2cdfa2a 100644 --- a/ckanext/gbif/logic/action.py +++ b/ckanext/gbif/logic/action.py @@ -5,7 +5,6 @@ # Created by the Natural History Museum in London, UK import requests - from ckan.plugins import toolkit @@ -16,17 +15,17 @@ def gbif_record_show(context, data_dict): :param context: CKAN context :param data_dict: dict of parameters, only one is required: gbif_id """ - gbif_id = toolkit.get_or_bust(data_dict, "gbif_id") + gbif_id = toolkit.get_or_bust(data_dict, 'gbif_id') try: response = requests.get( - f"https://api.gbif.org/v1/occurrence/{gbif_id}", timeout=5 + f'https://api.gbif.org/v1/occurrence/{gbif_id}', timeout=5 ) except requests.Timeout: - raise toolkit.ObjectNotFound("GBIF request timed out") + raise toolkit.ObjectNotFound('GBIF request timed out') # if there was an error getting the record, raise a not found error if 400 <= response.status_code < 600: raise toolkit.ObjectNotFound( - f"GBIF request failed with code {response.status_code}" + f'GBIF request failed with code {response.status_code}' ) else: return response.json() diff --git a/ckanext/gbif/plugin.py b/ckanext/gbif/plugin.py index f402738..ccf83c1 100644 --- a/ckanext/gbif/plugin.py +++ b/ckanext/gbif/plugin.py @@ -5,13 +5,14 @@ # Created by the Natural History Museum in London, UK from ckan.plugins import SingletonPlugin, implements, interfaces, toolkit + from ckanext.gbif import routes from ckanext.gbif.lib import helpers from ckanext.gbif.logic.action import gbif_record_show class GBIFPlugin(SingletonPlugin): - '''GBIF plugin - Data Quality Indicators''' + """GBIF plugin - Data Quality Indicators""" implements(interfaces.IActions, inherit=True) implements(interfaces.IConfigurer) diff --git a/ckanext/gbif/routes/gbif.py b/ckanext/gbif/routes/gbif.py index 5a01202..7554a6f 100644 --- a/ckanext/gbif/routes/gbif.py +++ b/ckanext/gbif/routes/gbif.py @@ -4,9 +4,8 @@ # This file is part of ckanext-gbif # Created by the Natural History Museum in London, UK -from flask import Blueprint - from ckan.plugins import toolkit +from flask import Blueprint blueprint = Blueprint( name='gbif', diff --git a/docs/_scripts/gen_api_pages.py b/docs/_scripts/gen_api_pages.py index e34a1bf..f441fa3 100644 --- a/docs/_scripts/gen_api_pages.py +++ b/docs/_scripts/gen_api_pages.py @@ -1,6 +1,5 @@ # !/usr/bin/env python # encoding: utf-8 - """ Generate the code reference pages and navigation. diff --git a/tests/test_actions.py b/tests/test_actions.py index 0668ade..ea4f2fa 100644 --- a/tests/test_actions.py +++ b/tests/test_actions.py @@ -1,8 +1,7 @@ -from unittest.mock import patch, MagicMock, call +from unittest.mock import MagicMock, call, patch import pytest import requests - from ckan.plugins import toolkit from ckanext.gbif.logic.action import gbif_record_show @@ -31,7 +30,7 @@ def test_failure(self, requests_mock): ) def test_timeout(self, requests_mock): - gbif_id = "test" + gbif_id = 'test' # we mock the entire requests module so we need to put the Timeout class back # before we use it requests_mock.Timeout = requests.Timeout @@ -39,7 +38,7 @@ def test_timeout(self, requests_mock): with pytest.raises(toolkit.ObjectNotFound): gbif_record_show(MagicMock(), dict(gbif_id=gbif_id)) assert requests_mock.get.call_args == call( - f"https://api.gbif.org/v1/occurrence/{gbif_id}", timeout=5 + f'https://api.gbif.org/v1/occurrence/{gbif_id}', timeout=5 ) def test_missing_gbif_id(self, requests_mock): diff --git a/tests/test_helpers.py b/tests/test_helpers.py index d0fd161..f08b355 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1,7 +1,7 @@ from unittest.mock import MagicMock -from ckanext.gbif.lib.errors import GBIF_ERRORS, DQI_MAJOR_ERRORS, DQI_MINOR_ERRORS -from ckanext.gbif.lib.helpers import dqi_parse_errors, dqi_get_severity +from ckanext.gbif.lib.errors import DQI_MAJOR_ERRORS, DQI_MINOR_ERRORS, GBIF_ERRORS +from ckanext.gbif.lib.helpers import dqi_get_severity, dqi_parse_errors class TestDQIParseErrors: