Skip to content

Commit

Permalink
HDX-10252 add more pages to test_page_load
Browse files Browse the repository at this point in the history
  • Loading branch information
ccataalin committed Oct 22, 2024
1 parent c5653ec commit 93a267f
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ def get_users():
return new_users


def get_showcases():
showcases = [
{
'name': 'test_showcase_1',
'title': 'Test Showcase test_showcase_1',
'notes': 'This is a test showcase',
'dataviz_label': 'Test Label',
}
]
return showcases


class HDXWithIndsAndOrgsTest(hdx_test_base.HdxBaseTest):
'''
This class extends the HDX Base test class by adding additional test data.
Expand All @@ -146,7 +158,7 @@ def _get_action(cls, action_name):
return tk.get_action(action_name)

@classmethod
def _create_test_data(cls, create_datasets=True, create_members=False):
def _create_test_data(cls, create_datasets=True, create_members=False, create_showcases=False):
'''
This method is responsible for creating additional test data.
Please note that the corresponding function from the parent is still called
Expand All @@ -160,6 +172,8 @@ def _create_test_data(cls, create_datasets=True, create_members=False):
:param create_members: If the org should have some members set this flag to True. Default False.
Note that 'testsysadmin' will be a member (admin) of the org regardless of the flag.
:type create_members: boolean
:param create_showcases: If the org should have showcases set this flag to True. Default False.
:type create_showcases: boolean
'''
super(HDXWithIndsAndOrgsTest, cls)._create_test_data()
Expand All @@ -168,6 +182,7 @@ def _create_test_data(cls, create_datasets=True, create_members=False):
organization = get_organization()
resource = get_resource()
users = get_users()
showcases = get_showcases()

if create_members:
organization['users'] = []
Expand All @@ -192,3 +207,10 @@ def _create_test_data(cls, create_datasets=True, create_members=False):
cls._get_action('package_update')(c, package)

cls._get_action('resource_create')(context, resource)

if create_showcases:
for showcase in showcases:
c = {'ignore_auth': True,
'model': model, 'session': model.Session, 'user': 'testsysadmin'}
cls._get_action('ckanext_showcase_create')(c, showcase)

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
{'url_name': 'hdx_splash.index', 'usertype': 'all'},
{'url_name': 'hdx_splash.index', 'usertype': None},

# search
{'url_name': 'hdx_search.search', 'usertype': 'all', 'url_params': {'q': 'test'}},
{'url_name': 'hdx_search.search', 'usertype': None, 'url_params': {'q': 'test'}},

# datasets list
{'url_name': 'hdx_dataset.search', 'usertype': 'all'},
{'url_name': 'hdx_dataset.search', 'usertype': None},
Expand All @@ -30,11 +34,23 @@
{'url_name': 'hdx_dataset.read', 'usertype': 'all', 'url_params': {'id': 'test_dataset_1'}},
{'url_name': 'hdx_dataset.read', 'usertype': None, 'url_params': {'id': 'test_dataset_1'}},

# locations list
# resource
{'url_name': 'dataset_resource.read', 'usertype': 'sysadmin',
'url_params': {'id': 'test_private_dataset_1', 'resource_id': '<>'}},

# showcases list
{'url_name': 'showcase_blueprint.index', 'usertype': 'all'},
{'url_name': 'showcase_blueprint.index', 'usertype': None},

# showcases
{'url_name': 'showcase_blueprint.read', 'usertype': 'all', 'url_params': {'id': 'test_showcase_1'}},
{'url_name': 'showcase_blueprint.read', 'usertype': None, 'url_params': {'id': 'test_showcase_1'}},

# locations/groups list
{'url_name': 'hdx_group.index', 'usertype': 'all'},
{'url_name': 'hdx_group.index', 'usertype': None},

# location
# location/group
{'url_name': 'hdx_group.read', 'usertype': 'all', 'url_params': {'id': 'roger'}},
{'url_name': 'hdx_group.read', 'usertype': None, 'url_params': {'id': 'roger'}},

Expand All @@ -49,24 +65,45 @@
# login
{'url_name': 'hdx_signin.login', 'usertype': None},

# faq
{'url_name': 'hdx_faqs.read', 'usertype': 'all', 'url_params': {'category': 'faq'}},
{'url_name': 'hdx_faqs.read', 'usertype': None, 'url_params': {'category': 'faq'}},

# terms of service
{'url_name': 'hdx_faqs.read', 'usertype': 'all', 'url_params': {'category': 'terms'}},
{'url_name': 'hdx_faqs.read', 'usertype': None, 'url_params': {'category': 'terms'}},

# resources for developers
{'url_name': 'hdx_faqs.read', 'usertype': 'all', 'url_params': {'category': 'devs'}},
{'url_name': 'hdx_faqs.read', 'usertype': None, 'url_params': {'category': 'devs'}},

# data licenses
{'url_name': 'hdx_faqs.read', 'usertype': 'all', 'url_params': {'category': 'licenses'}},
{'url_name': 'hdx_faqs.read', 'usertype': None, 'url_params': {'category': 'licenses'}},

# qa process
{'url_name': 'hdx_splash.about', 'usertype': 'all', 'url_params': {'page': 'hdx-qa-process'}},
{'url_name': 'hdx_splash.about', 'usertype': None, 'url_params': {'page': 'hdx-qa-process'}},

# archive page
{'url_name': 'hdx_archived_quick_links.show', 'usertype': 'all'},
{'url_name': 'hdx_archived_quick_links.show', 'usertype': None},

{'url_name': 'dashboard.organizations', 'usertype': 'all'},
{'url_name': 'activity.dashboard', 'usertype': 'all'},
{'url_name': 'hdx_user_dashboard.datasets', 'usertype': 'all'},
{'url_name': 'dashboard.groups', 'usertype': 'all'},
{'url_name': 'hdx_user_dashboard.datasets', 'usertype': 'all', 'url_params': {'id': 'tester'}},
{'url_name': 'hdx_splash.about_hrinfo', 'usertype': 'all'},

{'url_name': 'hdx_archived_quick_links.show', 'usertype': 'all'},

]


# @pytest.mark.skipif(six.PY3, reason=u"Needed plugins are not on PY3 yet")
class TestPageLoad(hdx_test_with_inds_and_orgs.HDXWithIndsAndOrgsTest):

tester_token = None
testsysadmin_token = None
resource_id = None

@classmethod
def _load_plugins(cls):
hdx_test_base.load_plugin(
Expand All @@ -86,11 +123,24 @@ def setup_class(cls):
cls.tester_token = factories.APIToken(user='tester', expires_in=2, unit=60 * 60)['token']
cls.testsysadmin_token = factories.APIToken(user='testsysadmin', expires_in=2, unit=60 * 60)['token']

cls.resource_id = cls._get_action('package_show')(
{'model': model, 'session': model.Session, 'user': 'testsysadmin'},
{'id': 'test_private_dataset_1'}
).get('resources')[0].get('id')

@classmethod
def _create_test_data(cls):
super(TestPageLoad, cls)._create_test_data(create_datasets=True, create_members=True, create_showcases=True)


@pytest.mark.parametrize("page", pages)
def test_page_load(self, page):
test_client = self.get_backwards_compatible_test_client()
url_name = page.get('url_name')
url_params = page.get('url_params')
if url_params and 'resource_id' in url_params:
url_params['resource_id'] = self.resource_id

if not page['usertype']:
self._try_page_load(test_client, url_name, None, None, url_params)
else:
Expand Down
7 changes: 7 additions & 0 deletions docker/hdx-test-core.ini.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ hdx.http_headers.mimetypes = application/json,text/html,text/json
# Disabling email sending in tests
hdx.api_token.email_notifications.enabled = false

# FAQ - Wordpress
hdx.wordpress.url=https://centre.humdata.org
hdx.wordpress.category.faq=554
hdx.wordpress.category.devs=568
hdx.wordpress.category.terms=577
hdx.wordpress.category.licenses=581


# Logging configuration
[loggers]
Expand Down

0 comments on commit 93a267f

Please sign in to comment.