-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into fix/hdx-9070-google-search-optimize
- Loading branch information
Showing
88 changed files
with
864 additions
and
220 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
ckanext-hdx_dataviz/ckanext/hdx_dataviz/tests/test_dataviz_page_load.py
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import pytest | ||
import six | ||
|
||
import ckan.plugins.toolkit as tk | ||
|
||
|
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
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
90 changes: 90 additions & 0 deletions
90
...ckage/ckanext/hdx_package/tests/test_dataset_special_fields/test_data_update_frequency.py
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,90 @@ | ||
import pytest | ||
|
||
import ckan.tests.factories as factories | ||
import ckan.model as model | ||
import ckan.plugins.toolkit as tk | ||
|
||
import ckanext.hdx_theme.tests.hdx_test_base as hdx_test_base | ||
|
||
from ckanext.hdx_org_group.helpers.static_lists import ORGANIZATION_TYPE_LIST | ||
|
||
config = tk.config | ||
NotAuthorized = tk.NotAuthorized | ||
ValidationError = tk.ValidationError | ||
|
||
|
||
class TestDataUpdateFrequency(hdx_test_base.HdxBaseTest): | ||
NORMAL_USER = 'normal_user' | ||
LIVE_UPDATE_FREQUENCY = '0' | ||
|
||
INTERNAL_RESOURCE = { | ||
'package_id': 'test_private_dataset_1', | ||
'url': config.get('ckan.site_url', '') + '/storage/f/test_folder/hdx_test.csv', | ||
'resource_type': 'file.upload', | ||
'format': 'CSV', | ||
'name': 'hdx_test.csv' | ||
} | ||
EXTERNAL_RESOURCE = { | ||
'package_id': 'test_private_dataset_1', | ||
'url': 'http://test.ckan.test/test.csv', | ||
'resource_type': 'api', | ||
'url_type': 'api', | ||
'format': 'CSV', | ||
'name': 'data1.csv', | ||
} | ||
PACKAGE = { | ||
'package_creator': 'test function', | ||
'private': False, | ||
'dataset_date': '01/01/1960-12/31/2012', | ||
'caveats': 'These are the caveats', | ||
'license_other': 'TEST OTHER LICENSE', | ||
'methodology': 'This is a test methodology', | ||
'dataset_source': 'Test data', | ||
'license_id': 'hdx-other', | ||
'notes': 'This is a test dataset', | ||
'data_update_frequency': LIVE_UPDATE_FREQUENCY, | ||
'title': 'Test Dataset for Update Frequency', | ||
'owner_org': 'org_name_4_update_frequency', | ||
'groups': [{'name': 'roger'}], | ||
} | ||
|
||
@classmethod | ||
def _get_action(cls, action_name): | ||
return tk.get_action(action_name) | ||
|
||
@classmethod | ||
def setup_class(cls): | ||
super(TestDataUpdateFrequency, cls).setup_class() | ||
factories.User(name=cls.NORMAL_USER, email='[email protected]') | ||
factories.Organization( | ||
name='org_name_4_update_frequency', | ||
title='ORG NAME FOR UPDATE FREQUENCY', | ||
users=[ | ||
{'name': cls.NORMAL_USER, 'capacity': 'admin'}, | ||
], | ||
hdx_org_type=ORGANIZATION_TYPE_LIST[0][1], | ||
org_url='https://hdx.hdxtest.org/' | ||
) | ||
|
||
def test_valid_live_dataset_with_external_resource(self): | ||
context = {'model': model, 'session': model.Session, 'user': self.NORMAL_USER} | ||
|
||
self.PACKAGE['name'] = 'test_dataset_1' | ||
self.PACKAGE['resources'] = [self.INTERNAL_RESOURCE, self.EXTERNAL_RESOURCE] | ||
|
||
dataset_dict = self._get_action('package_create')(context, self.PACKAGE) | ||
assert dataset_dict.get( | ||
'data_update_frequency') == self.LIVE_UPDATE_FREQUENCY, 'Live dataset should be created successfully with ' \ | ||
'an external resource' | ||
|
||
def test_invalid_live_dataset_with_only_internal_resources(self): | ||
context = {'model': model, 'session': model.Session, 'user': self.NORMAL_USER} | ||
|
||
self.PACKAGE['name'] = 'test_dataset_2' | ||
self.PACKAGE['resources'] = [self.INTERNAL_RESOURCE] | ||
|
||
try: | ||
self._get_action('package_create')(context, self.PACKAGE) | ||
assert False, 'Validation error should be raised for live datasets without any external resource' | ||
except ValidationError as e: | ||
assert True, 'Live datasets should have at least one external resource' |
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 @@ | ||
from ckanext.hdx_theme.tests.conftest import keep_db_tables_on_clean |
88 changes: 88 additions & 0 deletions
88
ckanext-hdx_search/ckanext/hdx_search/tests/test_pages/test_pagination.py
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 @@ | ||
import pytest | ||
import ckan.tests.factories as factories | ||
|
||
import ckan.plugins.toolkit as tk | ||
import ckan.model as model | ||
|
||
from ckan.types import Context | ||
from ckanext.hdx_org_group.helpers.static_lists import ORGANIZATION_TYPE_LIST | ||
from ckanext.hdx_theme.tests import hdx_test_util | ||
|
||
_url_for = tk.url_for | ||
_get_action = tk.get_action | ||
|
||
STANDARD_USER = 'some_standard_user' | ||
LOCATION_NAME = 'some_location' | ||
ORG_NAME1 = 'some_org1' | ||
ORG_NAME2 = 'some_org2' | ||
|
||
|
||
def _get_dataset_dict(dataset_name, org_name): | ||
return { | ||
"package_creator": "test function", | ||
"private": False, | ||
"dataset_date": "[1960-01-01 TO 2012-12-31]", | ||
"caveats": "These are the caveats", | ||
"license_other": "TEST OTHER LICENSE", | ||
"methodology": "This is a test methodology", | ||
"dataset_source": "Test data", | ||
"license_id": "hdx-other", | ||
"name": dataset_name, | ||
"notes": "This is a test dataset", | ||
"title": "Test Dataset " + dataset_name, | ||
"owner_org": org_name, | ||
"groups": [{"name": LOCATION_NAME}], | ||
"data_update_frequency": "30", | ||
"maintainer": STANDARD_USER, | ||
"resources": [ | ||
{ | ||
'url': 'http://test.ckan.test/test.csv', | ||
'resource_type': 'api', | ||
'url_type': 'api', | ||
'format': 'CSV', | ||
'name': 'data1.csv', | ||
} | ||
], | ||
} | ||
|
||
|
||
@pytest.fixture() | ||
def setup_data(): | ||
factories.User(name=STANDARD_USER, email='[email protected]') | ||
group = factories.Group(name=LOCATION_NAME) | ||
for org_name in [ORG_NAME1, ORG_NAME2]: | ||
factories.Organization( | ||
name=org_name, | ||
title='ORG NAME FOR HDX_REL_URL', | ||
users=[ | ||
{'name': STANDARD_USER, 'capacity': 'editor'}, | ||
], | ||
hdx_org_type=ORGANIZATION_TYPE_LIST[0][1], | ||
org_url='https://hdx.hdxtest.org/' | ||
) | ||
|
||
context: Context = {'model': model, 'session': model.Session, 'user': STANDARD_USER} | ||
_get_action('package_create')(context, _get_dataset_dict(dataset_name='dataset1', | ||
org_name=ORG_NAME1)) | ||
_get_action('package_create')(context, _get_dataset_dict(dataset_name='dataset2', | ||
org_name=ORG_NAME2)) | ||
|
||
|
||
@pytest.mark.usefixtures('keep_db_tables_on_clean', 'clean_db', 'clean_index', 'setup_data') | ||
def test_pagination_2_valued_filter(app): | ||
url = _url_for('hdx_dataset.search', organization=[ORG_NAME1, ORG_NAME2], ext_page_size=1) | ||
response = app.get(url) | ||
assert response.status_code == 200 | ||
|
||
page = response.body | ||
|
||
begin_str = '<a class="page-link" href=' | ||
end_str = '</a>' | ||
search_item1 = f'organization={ORG_NAME1}' | ||
search_item2 = f'organization={ORG_NAME2}' | ||
|
||
count_org1 = hdx_test_util.count_string_occurrences(page, search_item1, begin_str, end_str) | ||
assert count_org1 == 1 | ||
|
||
count_org2 = hdx_test_util.count_string_occurrences(page, search_item2, begin_str, end_str) | ||
assert count_org2 == 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
Oops, something went wrong.