-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[QOLDEV-955] add unit testing for stats reporting
- Loading branch information
Showing
9 changed files
with
104 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# 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. | ||
""" | ||
# ~ self._create_test_data() | ||
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. | ||
""" | ||
# ~ self._create_test_data() | ||
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. | ||
""" | ||
# ~ self._create_test_data() | ||
assert Stats().resource_count() == 1 | ||
|
||
def test_resource_report(self, org, dataset, resource): | ||
""" Test that the detailed resource report can be retrieved. | ||
""" | ||
# ~ self._create_test_data() | ||
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. | ||
""" | ||
# ~ self._create_test_data() | ||
assert Stats().resource_org_count(org['id']) == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 protected]" | ||
|