diff --git a/.ahoy.yml b/.ahoy.yml index e350a9f..9fe4a59 100644 --- a/.ahoy.yml +++ b/.ahoy.yml @@ -161,7 +161,7 @@ commands: usage: Run unit tests. cmd: | ahoy title 'Run unit tests' - ahoy cli 'pytest --ckan-ini=${CKAN_INI} --cov=ckanext "${APP_DIR}"/ckanext --junit-xml=test/junit/results.xml' || \ + ahoy cli 'pytest -vv --ckan-ini=${CKAN_INI} --cov=ckanext "${APP_DIR}"/ckanext --junit-xml=test/junit/results.xml' || \ [ "${ALLOW_UNIT_FAIL:-0}" -eq 1 ] test-bdd: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6e16908..2d6523d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,24 +24,24 @@ jobs: test: needs: lint strategy: - fail-fast: true + fail-fast: false matrix: - ckan-version: ["2.10"] - solr-version: ["8"] + ckan-version: ['2.10'] + solr-version: ['8'] ckan-type: ['vanilla', 'custom'] experimental: [false] include: - ckan-version: '2.11' - solr-version: "9" + solr-version: '9' ckan-type: 'vanilla' experimental: true - ckan-version: '2.11' - solr-version: "9" + solr-version: '9' ckan-type: 'custom' experimental: false - ckan-version: 'master' - solr-version: "9" - experimental: true #master is unstable, good to know if we are compatible or not + solr-version: '9' + experimental: true # master is unstable, good to know if we are compatible or not name: ${{ matrix.experimental && '**Fail_Ignored** ' || '' }} CKAN ${{ matrix.ckan-version }} ${{ matrix.ckan-type }} runs-on: ubuntu-latest diff --git a/bin/init.sh b/bin/init.sh index ba172d5..ffa9709 100755 --- a/bin/init.sh +++ b/bin/init.sh @@ -7,3 +7,5 @@ set -e . "${APP_DIR}"/bin/activate CLICK_ARGS="--yes" ckan_cli db clean ckan_cli db init +# apply any plugin migrations +ckan_cli db upgrade diff --git a/ckanext/qgov/common/stats.py b/ckanext/qgov/common/stats.py index c146b25..aa27517 100644 --- a/ckanext/qgov/common/stats.py +++ b/ckanext/qgov/common/stats.py @@ -77,7 +77,7 @@ def resource_report(cls): resource = table('resource') group = table('group') package = table('package') - query = select([group.c.title, package.c.title, resource.c.name, resource.c.url, resource.c.created, resource.c.last_modified, resource.c.format, resource.c.webstore_url, resource.c.resource_type]). \ + query = select([group.c.title, package.c.title, resource.c.name, resource.c.url, resource.c.created, resource.c.last_modified, resource.c.format, resource.c.webstore_url if hasattr(resource.c, 'webstore_url') else None, resource.c.resource_type]). \ where(and_(resource.c.package_id == package.c.id, resource.c.state == 'active', group.c.id == package.c.owner_org)) diff --git a/ckanext/qgov/common/test/test_stats.py b/ckanext/qgov/common/test/test_stats.py new file mode 100644 index 0000000..dcbe723 --- /dev/null +++ b/ckanext/qgov/common/test/test_stats.py @@ -0,0 +1,83 @@ +# encoding: utf-8 + +'''Tests for the ckanext.qgov extension resource URL filter. +''' + +from datetime import datetime +import pytest + +from ckan.tests import factories +from ckan.plugins.toolkit import check_ckan_version + +from ckanext.qgov.common.stats import Stats + + +@pytest.fixture() +def migrate_db_for_plugins(migrate_db_for): + if check_ckan_version('2.11'): + migrate_db_for('activity') + + +@pytest.fixture() +def org(migrate_db_for_plugins): + return factories.Organization() + + +@pytest.fixture() +def group(migrate_db_for_plugins): + return factories.Group() + + +@pytest.fixture() +def dataset(org, group): + return factories.Dataset(owner_org=org['id'], groups=[{"id": group['id']}], private=False) + + +@pytest.fixture() +def resource(dataset): + return factories.Resource(package_id=dataset['id']) + + +@pytest.mark.usefixtures("with_plugins", "clean_db") +class TestStats(): + """ Test our URL validation. + """ + + def test_top_groups(self, group, resource): + """ Test that the most-used categories can be retrieved. + """ + top_categories = Stats().top_categories() + assert len(top_categories) == 1 + assert top_categories[0][0].id == group['id'] + assert top_categories[0][1] == 1 + + def test_top_orgs(self, org, resource): + """ Test that the most-used organisations can be retrieved. + """ + top_orgs = Stats().top_organisations() + assert len(top_orgs) == 1 + assert top_orgs[0][0].id == org['id'] + assert top_orgs[0][1] == 1 + + def test_resource_count(self, resource): + """ Test that all resources can be counted. + """ + assert Stats().resource_count() == 1 + + def test_resource_report(self, org, dataset, resource): + """ Test that the detailed resource report can be retrieved. + """ + report = Stats().resource_report() + assert len(report) == 1 + created_date = datetime.fromisoformat(resource['created']) if resource['created'] else None + modified_date = datetime.fromisoformat(resource['last_modified']) if resource['last_modified'] else None + assert report[0] == ( + org['title'], dataset['title'], resource['name'], resource['url'], + created_date, modified_date, + resource['format'], resource.get('webstore_url'), resource['resource_type'] + ) + + def test_resource_org_count(self, org, resource): + """ Test that the resources in an organisation can be counted. + """ + assert Stats().resource_org_count(org['id']) == 1 diff --git a/test/features/steps/steps.py b/test/features/steps/steps.py index cca1446..523a895 100644 --- a/test/features/steps/steps.py +++ b/test/features/steps/steps.py @@ -58,7 +58,7 @@ def log_in(context): @when(u'I expand the browser height') def expand_height(context): # Work around x=null bug in Selenium set_window_size - context.browser.driver.set_window_rect(x=0, y=0, width=1024, height=3072) + context.browser.driver.set_window_rect(x=0, y=0, width=1366, height=3072) @when(u'I log in directly') diff --git a/test/features/user_creation.feature b/test/features/user_creation.feature index f4ae94d..57ebf74 100644 --- a/test/features/user_creation.feature +++ b/test/features/user_creation.feature @@ -22,8 +22,8 @@ Feature: User creation Scenario: Non logged-in user register to the site. Given "Unauthenticated" as the persona - When I go to register page - And I expand the browser height + When I expand the browser height + And I go to register page Then I should see an element with xpath "//input[@name='fullname']" When I fill in "name" with "publisher_user" And I fill in "fullname" with "gov user" diff --git a/test/features/users.feature b/test/features/users.feature index 400b624..81f190e 100644 --- a/test/features/users.feature +++ b/test/features/users.feature @@ -151,8 +151,8 @@ Feature: User APIs Scenario: Register user password must be 10 characters or longer and contain number, lowercase, capital, and symbol Given "Unauthenticated" as the persona - When I go to register page - And I expand the browser height + When I expand the browser height + And I go to register page And I fill in "name" with "name" And I fill in "fullname" with "fullname" And I fill in "email" with "email@test.com"