diff --git a/src/dvtests/settings.py b/src/dvtests/settings.py index da7d1b1..b879658 100755 --- a/src/dvtests/settings.py +++ b/src/dvtests/settings.py @@ -19,11 +19,12 @@ class TestSettings(BaseSettings): INSTANCE: str USER_FILENAME: str DATA_COLLECTOR: str + VERSION: str HEADLESS: bool = True USER_AGENT: str = "TESTING" WINDOW_HEIGHT: int = 1400 WINDOW_WIDTH: int = 1600 - MAX_WAIT_TIME: int = 10 + MAX_WAIT_TIME: int = 20 LOGIN_OPTIONS: List[str] = ["normal"] FILENAME_DATAVERSES: str = "dataverses.json" FILENAME_DATASETS: str = "datasets.json" diff --git a/src/dvtests/testing/conftest.py b/src/dvtests/testing/conftest.py index 7ee4113..2ffb9d3 100644 --- a/src/dvtests/testing/conftest.py +++ b/src/dvtests/testing/conftest.py @@ -1,5 +1,6 @@ import os from json import load +from time import sleep import pytest import requests @@ -20,10 +21,17 @@ ROOT_DIR = os.path.dirname( os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) ) -DATA_DIR = os.path.join( +UTILS_DATA_DIR = os.path.join( ROOT_DIR, "src/dvtests/data", CONFIG.INSTANCE, CONFIG.DATA_COLLECTOR ) -TESTING_DATA_DIR = os.path.join(ROOT_DIR, "src/dvtests/testing/data", CONFIG.INSTANCE) +TEST_CONFIG_DATA_DIR = os.path.join( + ROOT_DIR, "src/dvtests/testing/data/test_configs", CONFIG.INSTANCE +) +DATAVERSE_VERSION_DIR = os.path.join( + ROOT_DIR, + "src/dvtests/testing/data/dataverse_versions", + CONFIG.VERSION.replace(".", "_"), +) TESTDATA_METADATA_DIR = os.path.join(ROOT_DIR, "dataverse_testdata/metadata/json") @@ -78,81 +86,76 @@ def chrome_options(chrome_options, config): @pytest.fixture -def selenium(selenium, config): +def homepage(selenium, config): + """Get homepage with selenium.""" + selenium.get(config.BASE_URL) selenium.set_window_size(config.WINDOW_WIDTH, config.WINDOW_HEIGHT) - yield selenium - selenium.close() - selenium.quit() - - -def login_normal( - selenium, base_url, login_options, user_handle, user_pwd, max_wait_time -): - """Login with normal user.""" - wait = WebDriverWait(selenium, max_wait_time) - selenium.get(f"{base_url}/loginpage.xhtml") - - if "shibboleth" in login_options: - btn_username_email = wait.until( - EC.element_to_be_clickable((By.LINK_TEXT, "Username/Email")) - ) - btn_username_email.click() + custom_click_cookie_rollbar(selenium, config.MAX_WAIT_TIME) + return selenium - input_username_email = wait.until( - EC.element_to_be_clickable( - (By.ID, "loginForm:credentialsContainer:0:credValue") - ) - ) - input_username_email.send_keys(user_handle) - input_pwd = wait.until( - EC.element_to_be_clickable( - (By.ID, "loginForm:credentialsContainer:1:sCredValue") - ) +@pytest.fixture +def homepage_logged_in(request, homepage, config, users): + """Get homepage logged in with selenium.""" + selenium = homepage + user_handle = request.param + user_pwd = users[user_handle]["password"] + user_name = ( + users[user_handle]["given-name"] + " " + users[user_handle]["family-name"] ) - input_pwd.send_keys(user_pwd) + user_auth = users[user_handle]["authentication"] - btn_login = wait.until(EC.element_to_be_clickable((By.ID, "loginForm:login"))) - btn_login.click() - wait.until(EC.element_to_be_clickable((By.ID, "userDisplayInfoTitle"))) - return selenium - # TODO: logout - - -def login_shibboleth( - selenium, config, shibb_login_page_title, user_handle, user_pwd, user_name -): - """Login with Shibboleth user.""" wait = WebDriverWait(selenium, config.MAX_WAIT_TIME) - # set_window_size(config.WINDOW_WIDTH, config.WINDOW_HEIGHT) selenium.get(f"{config.BASE_URL}/loginpage.xhtml") + sleep(15) - if "shibboleth" in config.LOGIN_OPTIONS: + if user_auth == "normal": btn_username_email = wait.until( - EC.element_to_be_clickable((By.LINK_TEXT, "Username/Email")) + EC.element_to_be_clickable((By.XPATH, "//*[text()='Username/Email']")) ) btn_username_email.click() + input_username_email = wait.until( + EC.element_to_be_clickable( + (By.XPATH, "//input[@id='loginForm:credentialsContainer:0:credValue']") + ) + ) + input_username_email.send_keys(user_handle) - select_institution = wait.until( - EC.element_to_be_clickable((By.ID, "idpSelectSelector")) - ) - select_institution.click() + input_pwd = wait.until( + EC.element_to_be_clickable( + (By.XPATH, "//input[@id='loginForm:credentialsContainer:1:sCredValue']") + ) + ) + input_pwd.send_keys(user_pwd) - select_institution.find_element( - By.XPATH, f"//option[. = '{config.SHIBBOLETH_INSTITUTION}']" - ).click() + btn_login = wait.until( + EC.element_to_be_clickable((By.XPATH, "//button[@id='loginForm:login']")) + ) + btn_login.click() + elif user_auth == "shibboleth": + select_institution = wait.until( + EC.element_to_be_clickable((By.XPATH, "//select[@id='idpSelectSelector']")) + ) + select_institution.click() - btn_select_institution = wait.until( - EC.element_to_be_clickable((By.ID, "idpSelectListButton")) - ) - btn_select_institution.click() + select_institution.find_element( + By.XPATH, f"//option[. = '{config.SHIBBOLETH_INSTITUTION}']" + ).click() - # Institutions Shibboleth Login Page - selenium = custom_login_shibboleth_institution_page( - selenium, config, shibb_login_page_title, user_handle, user_pwd, user_name + btn_select_institution = wait.until( + EC.element_to_be_clickable((By.XPATH, "//input[@id='idpSelectListButton']")) + ) + btn_select_institution.click() + + # Institutions Shibboleth Login Page + selenium = custom_shibboleth_institution_login( + selenium, config, user_handle, user_pwd, user_name + ) + navbar_user = wait.until( + EC.element_to_be_clickable((By.XPATH, "//span[@id='userDisplayInfoTitle']")) ) - wait.until(EC.element_to_be_clickable((By.ID, "userDisplayInfoTitle"))) - return selenium + assert navbar_user.text == user_name + return homepage, user_handle def search_navbar(selenium, config, query): @@ -169,7 +172,11 @@ def search_navbar(selenium, config, query): navbar_search_input.send_keys(query) navbar_search_input.send_keys(Keys.ENTER) - wait.until(EC.visibility_of_element_located((By.ID, "dv-main"))) + wait.until( + EC.text_to_be_present_in_element_value( + (By.XPATH, "//input[@id='j_idt421:searchBasic']"), "elections" + ) + ) return selenium @@ -184,42 +191,66 @@ def search_header(selenium, config, query): header_search.send_keys(query) header_search.send_keys(Keys.ENTER) - wait.until(EC.visibility_of_element_located((By.ID, "dv-main"))) + wait.until( + EC.text_to_be_present_in_element_value( + (By.XPATH, "//input[@id='j_idt421:searchBasic']"), "elections" + ) + ) return selenium -def custom_login_shibboleth_institution_page( - selenium, config, shibb_login_page_title, user_handle, user_pwd, user_name +def custom_shibboleth_institution_login( + selenium, config, user_handle, user_pwd, user_name ): """Login on Shibboleth institution login page.""" wait = WebDriverWait(selenium, config.MAX_WAIT_TIME) - input_user_id = wait.until(EC.element_to_be_clickable((By.ID, "userid"))) + input_user_id = wait.until( + EC.element_to_be_clickable((By.XPATH, "//input[@id='userid']")) + ) input_user_id.send_keys(user_handle) - input_user_pwd = wait.until(EC.element_to_be_clickable((By.ID, "password"))) + input_user_pwd = wait.until( + EC.element_to_be_clickable((By.XPATH, "//input[@id='password']")) + ) input_user_pwd.send_keys(user_pwd) - btn_login = wait.until(EC.element_to_be_clickable((By.NAME, "_eventId_proceed"))) + btn_login = wait.until( + EC.element_to_be_clickable((By.XPATH, "//button[@name='_eventId_proceed']")) + ) btn_login.click() + sleep(3) if selenium.title == config.SHIBBOLETH_LOGIN_PAGE_TITLE: btn_tou = wait.until( - EC.element_to_be_clickable((By.ID, "_shib_idp_accept_TOU")) + EC.element_to_be_clickable( + (By.XPATH, "//button[@id='_shib_idp_accept_TOU']") + ) ) btn_tou.click() - btn_next = wait.until(EC.element_to_be_clickable((By.ID, "_eventId_proceed"))) + btn_next = wait.until( + EC.element_to_be_clickable((By.XPATH, "//button[@id='_eventId_proceed']")) + ) btn_next.click() + navbar_user = wait.until( + EC.element_to_be_clickable((By.XPATH, "//span[@id='userDisplayInfoTitle']")) + ) + assert navbar_user.text == user_name return selenium def custom_click_cookie_rollbar(selenium, max_wait_time): """Accept cookie rollbar.""" wait = WebDriverWait(selenium, max_wait_time) - wait.until( + sleep(3) + btn_cookie_accept = wait.until( EC.element_to_be_clickable( - (By.ID, "CybotCookiebotDialogBodyLevelButtonLevelOptinAllowallSelection") + ( + By.XPATH, + "//a[@id='CybotCookiebotDialogBodyLevelButtonLevelOptinAllowallSelection']", + ) ) - ).click() + ) + btn_cookie_accept.click() return selenium @@ -317,3 +348,10 @@ def datafile_upload_min_01(): return read_json( os.path.join(TESTDATA_METADATA_DIR, "datafile/datafile_upload_min_01.json",) ) + + +@pytest.fixture +def form_create_dataverse(): + return read_json( + os.path.join(TESTDATA_METADATA_DIR, "datafile/datafile_upload_min_01.json",) + ) diff --git a/src/dvtests/testing/data/aussda_production/default/system/testdata_authentication.json b/src/dvtests/testing/data/aussda_production/default/system/testdata_authentication.json deleted file mode 100644 index 760c1fd..0000000 --- a/src/dvtests/testing/data/aussda_production/default/system/testdata_authentication.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "normal-login": { - "login-valid": [ - [ - { - "user-handle": "dataverseAdmin" - }, - { - "title": "AUSSDA" - } - ], - [ - { - "user-handle": "TestUser_NormalLogin" - }, - { - "title": "AUSSDA" - } - ] - ] - } -} diff --git a/src/dvtests/testing/data/aussda_production/default/system/testdata_datasets.json b/src/dvtests/testing/data/aussda_production/default/system/testdata_datasets.json deleted file mode 100644 index 5904c31..0000000 --- a/src/dvtests/testing/data/aussda_production/default/system/testdata_datasets.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "all-datasets": { - "facet-not-logged-in": [ - { - "num-datasets": 758 - } - ] - } -} diff --git a/src/dvtests/testing/data/aussda_production/default/system/testdata_dataverses.json b/src/dvtests/testing/data/aussda_production/default/system/testdata_dataverses.json deleted file mode 100644 index 38dc779..0000000 --- a/src/dvtests/testing/data/aussda_production/default/system/testdata_dataverses.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "all-dataverses": { - "facet-not-logged-in": [ - { - "num-dataverses": 17 - } - ] - }, - "create-dataverse": { - "min-valid": [ - { - "user-handle": "dataverseAdmin" - } - ] - } -} diff --git a/src/dvtests/testing/data/aussda_production/default/system/testdata_search.json b/src/dvtests/testing/data/aussda_production/default/system/testdata_search.json deleted file mode 100644 index c7e60da..0000000 --- a/src/dvtests/testing/data/aussda_production/default/system/testdata_search.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "search": { - "navbar-not-logged-in": [ - [ - { - "query": "elections" - }, - { - "num-dataverses": 2, - "num-datasets": 124, - "num-datafiles": 1, - "url": "https://data.aussda.at/dataverse/AUSSDA?q=elections" - } - ] - ] - } -} diff --git a/src/dvtests/testing/data/aussda_production/default/unit/testdata_api.json b/src/dvtests/testing/data/aussda_production/default/unit/testdata_api.json deleted file mode 100644 index 498c660..0000000 --- a/src/dvtests/testing/data/aussda_production/default/unit/testdata_api.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "dataverse": { - "valid": [ - [ - { - "alias": ":root" - }, - { - "alias": "AUSSDA", - "name": "AUSSDA", - "affiliation": "AUSSDA", - "emails": [ - "info@aussda.at" - ], - "tagline": "We make social science data accessible, creating opportunities for research and data reuse, benefitting science and society.", - "link-url": "https://aussda.at", - "url": "https://data.aussda.at/api/v1/dataverses/:root?User-Agent=pydataverse" - } - ], - [ - { - "alias": "AUSSDA" - }, - { - "alias": "AUSSDA", - "name": "AUSSDA", - "affiliation": "AUSSDA", - "emails": [ - "info@aussda.at" - ], - "tagline": "We make social science data accessible, creating opportunities for research and data reuse, benefitting science and society.", - "link-url": "https://aussda.at", - "url": "https://data.aussda.at/api/v1/dataverses/AUSSDA?User-Agent=pydataverse" - } - ] - ] - } -} diff --git a/src/dvtests/testing/data/aussda_production/default/unit/testdata_authentication.json b/src/dvtests/testing/data/aussda_production/default/unit/testdata_authentication.json deleted file mode 100644 index 0a26d0b..0000000 --- a/src/dvtests/testing/data/aussda_production/default/unit/testdata_authentication.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "shibboleth": { - "interface-valid": [ - [ - { - "url": "/Shibboleth.sso/DiscoFeed" - }, - { - "content-type": "application/json; charset=UTF-8" - } - ], - [ - { - "url": "/Shibboleth.sso/Metadata" - }, - { - "content-type": "application/samlmetadata+xml" - } - ] - ] - } -} diff --git a/src/dvtests/testing/data/aussda_production/default/unit/testdata_installation.json b/src/dvtests/testing/data/aussda_production/default/unit/testdata_installation.json deleted file mode 100644 index 7749f12..0000000 --- a/src/dvtests/testing/data/aussda_production/default/unit/testdata_installation.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "version": { - "valid": [ - { - "version": "4.20", - "build": "413-4e07b62" - } - ] - }, - "server": { - "api-valid": [ - { - "url": "data.aussda.at" - } - ], - "request-valid": [ - { - "server": "Apache/2.4.41 (Ubuntu)", - "content-encoding": "gzip", - "keep-alive": "timeout=5, max=100", - "connection": "Keep-Alive" - } - ] - } -} diff --git a/src/dvtests/testing/data/aussda_production/default/unit/testdata_oaipmh.json b/src/dvtests/testing/data/aussda_production/default/unit/testdata_oaipmh.json deleted file mode 100644 index 88d9105..0000000 --- a/src/dvtests/testing/data/aussda_production/default/unit/testdata_oaipmh.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "endpoint": { - "valid": [ - [ - { - "url": "https://data.aussda.at/oai" - }, - { - "encoding": "UTF-8", - "content-type": "text/xml;charset=UTF-8" - } - ], - [ - { - "url": "https://data.aussda.at/oai?verb=ListIdentifiers&metadataPrefix=oai_ddi&set=all_published" - }, - { - "encoding": "UTF-8", - "content-type": "text/xml;charset=UTF-8" - } - ], - [ - { - "url": "https://data2.aussda.at/oai?verb=ListIdentifiers&metadataPrefix=ddi" - }, - { - "encoding": "UTF-8", - "content-type": "text/xml;charset=UTF-8" - } - ], - [ - { - "url": "https://data2.aussda.at/oai?verb=ListRecords&metadataPrefix=ddi&set=all_published" - }, - { - "encoding": "UTF-8", - "content-type": "text/xml;charset=UTF-8" - } - ], - [ - { - "url": "https://data2.aussda.at/oai?verb=GetRecord&metadataPrefix=oai_ddi&identifier=doi:10.11587/BQVSOW" - }, - { - "encoding": "UTF-8", - "content-type": "text/xml;charset=UTF-8" - } - ] - ] - } -} diff --git a/src/dvtests/testing/data/aussda_production/default/unit/testdata_robots-txt.json b/src/dvtests/testing/data/aussda_production/default/unit/testdata_robots-txt.json deleted file mode 100644 index e9e0b69..0000000 --- a/src/dvtests/testing/data/aussda_production/default/unit/testdata_robots-txt.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "robots-txt": { - "valid": [ - { - "encoding": "ISO-8859-1", - "content-type": "text/plain" - } - ] - } -} diff --git a/src/dvtests/testing/data/aussda_production/default/unit/testdata_sitemap.json b/src/dvtests/testing/data/aussda_production/default/unit/testdata_sitemap.json deleted file mode 100644 index f9b6874..0000000 --- a/src/dvtests/testing/data/aussda_production/default/unit/testdata_sitemap.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "sitemap": { - "valid": [ - { - "encoding": "ISO-8859-1", - "content-type": "application/xml" - } - ] - } -} diff --git a/src/dvtests/testing/data/aussda_production/default/unit/testdata_user.json b/src/dvtests/testing/data/aussda_production/default/unit/testdata_user.json deleted file mode 100644 index 0f04d04..0000000 --- a/src/dvtests/testing/data/aussda_production/default/unit/testdata_user.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "api": { - "valid": [ - { - "url": "data.aussda.at" - } - ] - } -} diff --git a/src/dvtests/testing/data/dataverse_versions/4_20/form-data_create-dataverse.json b/src/dvtests/testing/data/dataverse_versions/4_20/form-data_create-dataverse.json new file mode 100644 index 0000000..dc95a28 --- /dev/null +++ b/src/dvtests/testing/data/dataverse_versions/4_20/form-data_create-dataverse.json @@ -0,0 +1,46 @@ +{ + "name": { + "xpath": "//input[@id='dataverseForm:name']", + "type": "text", + "content": "name" + }, + "alias": { + "xpath": "//input[@id='dataverseForm:identifier']", + "type": "text", + "content": "alias" + }, + "category": { + "xpath": "//select[@id='dataverseForm:dataverseCategory']", + "type": "select", + "content": "dataverseType" + }, + "storage": { + "xpath": "//select[@id='dataverseForm:dataverseStorage']", + "type": "select", + "content": "" + }, + "affiliation": { + "xpath": "//input[@id='dataverseForm:affiliation']", + "type": "text", + "content": "affiliation" + }, + "parent-dataverse": { + "xpath": "//input[@id='dataverseForm:selectHostDataverse']", + "type": "text", + "content": "" + }, + "description": { + "xpath": "//input[@id='dataverseForm:description']", + "type": "text", + "content": "description" + }, + "contactEmail": { + "xpath": "//input[@id='dataverseForm:j_idt259:0:contactEmail']", + "type": "text", + "content": [ + "dataverseContacts", + 0, + "contactEmail" + ] + } +} diff --git a/src/dvtests/testing/data/aussda_production/custom/system/testdata_authentication.json b/src/dvtests/testing/data/test_configs/aussda_production/custom/system/testdata_authentication.json similarity index 100% rename from src/dvtests/testing/data/aussda_production/custom/system/testdata_authentication.json rename to src/dvtests/testing/data/test_configs/aussda_production/custom/system/testdata_authentication.json diff --git a/src/dvtests/testing/data/test_configs/aussda_production/default/system/test-config_authentication.json b/src/dvtests/testing/data/test_configs/aussda_production/default/system/test-config_authentication.json new file mode 100644 index 0000000..6fb593b --- /dev/null +++ b/src/dvtests/testing/data/test_configs/aussda_production/default/system/test-config_authentication.json @@ -0,0 +1,19 @@ +{ + "normal-login": { + "login-valid": { + "users": [ + "dataverseAdmin", + "TestUser_NormalLogin", + "froehlichs65" + ], + "input-expected": [ + [ + {}, + { + "title": "AUSSDA" + } + ] + ] + } + } +} diff --git a/src/dvtests/testing/data/aussda_production/default/system/testdata_datafiles.json b/src/dvtests/testing/data/test_configs/aussda_production/default/system/test-config_datafiles.json similarity index 100% rename from src/dvtests/testing/data/aussda_production/default/system/testdata_datafiles.json rename to src/dvtests/testing/data/test_configs/aussda_production/default/system/test-config_datafiles.json diff --git a/src/dvtests/testing/data/test_configs/aussda_production/default/system/test-config_datasets.json b/src/dvtests/testing/data/test_configs/aussda_production/default/system/test-config_datasets.json new file mode 100644 index 0000000..7146442 --- /dev/null +++ b/src/dvtests/testing/data/test_configs/aussda_production/default/system/test-config_datasets.json @@ -0,0 +1,14 @@ +{ + "all-datasets": { + "facet-not-logged-in": { + "input-expected": [ + [ + {}, + { + "num-datasets": 758 + } + ] + ] + } + } +} diff --git a/src/dvtests/testing/data/test_configs/aussda_production/default/system/test-config_dataverses.json b/src/dvtests/testing/data/test_configs/aussda_production/default/system/test-config_dataverses.json new file mode 100644 index 0000000..4bfa6e9 --- /dev/null +++ b/src/dvtests/testing/data/test_configs/aussda_production/default/system/test-config_dataverses.json @@ -0,0 +1,21 @@ +{ + "all-dataverses": { + "facet-not-logged-in": { + "input-expected": [ + [ + {}, + { + "num-dataverses": 17 + } + ] + ] + } + }, + "create-dataverse": { + "min-valid": { + "users": [ + "dataverseAdmin" + ] + } + } +} diff --git a/src/dvtests/testing/data/test_configs/aussda_production/default/system/test-config_search.json b/src/dvtests/testing/data/test_configs/aussda_production/default/system/test-config_search.json new file mode 100644 index 0000000..1d0e236 --- /dev/null +++ b/src/dvtests/testing/data/test_configs/aussda_production/default/system/test-config_search.json @@ -0,0 +1,19 @@ +{ + "search": { + "navbar-not-logged-in": { + "input-expected": [ + [ + { + "query": "elections" + }, + { + "num-dataverses": 2, + "num-datasets": 254, + "num-datafiles": 1, + "url": "https://data.aussda.at/dataverse/AUSSDA?q=elections" + } + ] + ] + } + } +} diff --git a/src/dvtests/testing/data/aussda_production/default/system/testdata_user.json b/src/dvtests/testing/data/test_configs/aussda_production/default/system/test-config_user.json similarity index 100% rename from src/dvtests/testing/data/aussda_production/default/system/testdata_user.json rename to src/dvtests/testing/data/test_configs/aussda_production/default/system/test-config_user.json diff --git a/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_api.json b/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_api.json new file mode 100644 index 0000000..a56550f --- /dev/null +++ b/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_api.json @@ -0,0 +1,40 @@ +{ + "dataverse": { + "valid": { + "input-expected": [ + [ + { + "alias": ":root" + }, + { + "alias": "AUSSDA", + "name": "AUSSDA", + "affiliation": "AUSSDA", + "emails": [ + "info@aussda.at" + ], + "tagline": "We make social science data accessible, creating opportunities for research and data reuse, benefitting science and society.", + "link-url": "https://aussda.at", + "url": "https://data.aussda.at/api/v1/dataverses/:root?User-Agent=pydataverse" + } + ], + [ + { + "alias": "AUSSDA" + }, + { + "alias": "AUSSDA", + "name": "AUSSDA", + "affiliation": "AUSSDA", + "emails": [ + "info@aussda.at" + ], + "tagline": "We make social science data accessible, creating opportunities for research and data reuse, benefitting science and society.", + "link-url": "https://aussda.at", + "url": "https://data.aussda.at/api/v1/dataverses/AUSSDA?User-Agent=pydataverse" + } + ] + ] + } + } +} diff --git a/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_authentication.json b/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_authentication.json new file mode 100644 index 0000000..128554d --- /dev/null +++ b/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_authentication.json @@ -0,0 +1,24 @@ +{ + "shibboleth": { + "interface-valid": { + "input-expected": [ + [ + { + "url": "/Shibboleth.sso/DiscoFeed" + }, + { + "content-type": "application/json; charset=UTF-8" + } + ], + [ + { + "url": "/Shibboleth.sso/Metadata" + }, + { + "content-type": "application/samlmetadata+xml" + } + ] + ] + } + } +} diff --git a/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_installation.json b/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_installation.json new file mode 100644 index 0000000..6fa6984 --- /dev/null +++ b/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_installation.json @@ -0,0 +1,40 @@ +{ + "version": { + "valid": { + "input-expected": [ + [ + {}, + { + "version": "4.20", + "build": "413-4e07b62" + } + ] + ] + } + }, + "server": { + "api-valid": { + "input-expected": [ + [ + {}, + { + "url": "data.aussda.at" + } + ] + ] + }, + "request-valid": { + "input-expected": [ + [ + {}, + { + "server": "Apache/2.4.41 (Ubuntu)", + "content-encoding": "gzip", + "keep-alive": "timeout=5, max=100", + "connection": "Keep-Alive" + } + ] + ] + } + } +} diff --git a/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_oaipmh.json b/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_oaipmh.json new file mode 100644 index 0000000..6708cba --- /dev/null +++ b/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_oaipmh.json @@ -0,0 +1,53 @@ +{ + "endpoint": { + "valid": { + "input-expected": [ + [ + { + "url": "https://data.aussda.at/oai" + }, + { + "encoding": "UTF-8", + "content-type": "text/xml;charset=UTF-8" + } + ], + [ + { + "url": "https://data.aussda.at/oai?verb=ListIdentifiers&metadataPrefix=oai_ddi&set=all_published" + }, + { + "encoding": "UTF-8", + "content-type": "text/xml;charset=UTF-8" + } + ], + [ + { + "url": "https://data2.aussda.at/oai?verb=ListIdentifiers&metadataPrefix=ddi" + }, + { + "encoding": "UTF-8", + "content-type": "text/xml;charset=UTF-8" + } + ], + [ + { + "url": "https://data2.aussda.at/oai?verb=ListRecords&metadataPrefix=ddi&set=all_published" + }, + { + "encoding": "UTF-8", + "content-type": "text/xml;charset=UTF-8" + } + ], + [ + { + "url": "https://data2.aussda.at/oai?verb=GetRecord&metadataPrefix=oai_ddi&identifier=doi:10.11587/BQVSOW" + }, + { + "encoding": "UTF-8", + "content-type": "text/xml;charset=UTF-8" + } + ] + ] + } + } +} diff --git a/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_robots-txt.json b/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_robots-txt.json new file mode 100644 index 0000000..69e5e78 --- /dev/null +++ b/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_robots-txt.json @@ -0,0 +1,15 @@ +{ + "robots-txt": { + "valid": { + "input-expected": [ + [ + {}, + { + "encoding": "ISO-8859-1", + "content-type": "text/plain" + } + ] + ] + } + } +} diff --git a/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_sitemap.json b/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_sitemap.json new file mode 100644 index 0000000..743b375 --- /dev/null +++ b/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_sitemap.json @@ -0,0 +1,15 @@ +{ + "sitemap": { + "valid": { + "input-expected": [ + [ + {}, + { + "encoding": "ISO-8859-1", + "content-type": "application/xml" + } + ] + ] + } + } +} diff --git a/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_user.json b/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_user.json new file mode 100644 index 0000000..c35025d --- /dev/null +++ b/src/dvtests/testing/data/test_configs/aussda_production/default/unit/test-config_user.json @@ -0,0 +1,14 @@ +{ + "api": { + "valid": { + "input-expected": [ + [ + {}, + { + "url": "data.aussda.at" + } + ] + ] + } + } +} diff --git a/src/dvtests/testing/default/conftest.py b/src/dvtests/testing/default/conftest.py index d98978c..8acf698 100644 --- a/src/dvtests/testing/default/conftest.py +++ b/src/dvtests/testing/default/conftest.py @@ -1,9 +1,8 @@ -from ..conftest import custom_click_cookie_rollbar -from ..conftest import DATA_DIR -from ..conftest import login_normal -from ..conftest import login_shibboleth +from ..conftest import DATAVERSE_VERSION_DIR from ..conftest import read_json from ..conftest import ROOT_DIR from ..conftest import search_header from ..conftest import search_navbar -from ..conftest import TESTING_DATA_DIR +from ..conftest import TEST_CONFIG_DATA_DIR +from ..conftest import TESTDATA_METADATA_DIR +from ..conftest import UTILS_DATA_DIR diff --git a/src/dvtests/testing/default/unit/test_api.py b/src/dvtests/testing/default/unit/test_api.py index 7751c70..d27dd08 100644 --- a/src/dvtests/testing/default/unit/test_api.py +++ b/src/dvtests/testing/default/unit/test_api.py @@ -1,27 +1,26 @@ -import json import os import pytest -from ..conftest import TESTING_DATA_DIR +from ..conftest import read_json +from ..conftest import TEST_CONFIG_DATA_DIR - -with open( - os.path.join(TESTING_DATA_DIR, "default/unit/testdata_api.json") -) as json_file: - testdata = json.load(json_file) +test_config = read_json( + os.path.join(TEST_CONFIG_DATA_DIR, "default/unit/test-config_api.json") +) class TestDataverse: @pytest.mark.v4_20 - @pytest.mark.parametrize("test_input,expected", testdata["dataverse"]["valid"]) + @pytest.mark.parametrize( + "test_input,expected", test_config["dataverse"]["valid"]["input-expected"] + ) def test_valid(self, config, native_api, test_input, expected): """Test important Dataverses.""" # Arrange # Act resp = native_api.get_dataverse(test_input["alias"]) r_data = resp.json()["data"] - # Assert assert r_data["alias"] == expected["alias"] assert r_data["name"] == expected["name"] @@ -34,5 +33,4 @@ def test_valid(self, config, native_api, test_input, expected): assert resp.status_code == 200 assert resp.headers["Content-Type"] == "application/json" assert resp.url == expected["url"] - # Cleanup diff --git a/src/dvtests/testing/default/unit/test_authentication.py b/src/dvtests/testing/default/unit/test_authentication.py index 6df832e..09d6947 100644 --- a/src/dvtests/testing/default/unit/test_authentication.py +++ b/src/dvtests/testing/default/unit/test_authentication.py @@ -1,21 +1,21 @@ -import json import os import pytest -from ..conftest import TESTING_DATA_DIR +from ..conftest import read_json +from ..conftest import TEST_CONFIG_DATA_DIR -with open( - os.path.join(TESTING_DATA_DIR, "default/unit/testdata_authentication.json",) -) as json_file: - testdata = json.load(json_file) +test_config = read_json( + os.path.join(TEST_CONFIG_DATA_DIR, "default/unit/test-config_authentication.json",) +) class TestShibboleth: @pytest.mark.v4_20 @pytest.mark.parametrize( - "test_input,expected", testdata["shibboleth"]["interface-valid"] + "test_input,expected", + test_config["shibboleth"]["interface-valid"]["input-expected"], ) def test_interface_valid(self, config, session, test_input, expected): """Test Shibboleth interface.""" diff --git a/src/dvtests/testing/default/unit/test_installation.py b/src/dvtests/testing/default/unit/test_installation.py index dac2c4e..ac61768 100644 --- a/src/dvtests/testing/default/unit/test_installation.py +++ b/src/dvtests/testing/default/unit/test_installation.py @@ -1,21 +1,22 @@ -import json import os import pytest -from ..conftest import TESTING_DATA_DIR +from ..conftest import read_json +from ..conftest import TEST_CONFIG_DATA_DIR -with open( - os.path.join(TESTING_DATA_DIR, "default/unit/testdata_installation.json",) -) as json_file: - testdata = json.load(json_file) +test_config = read_json( + os.path.join(TEST_CONFIG_DATA_DIR, "default/unit/test-config_installation.json") +) class TestVersion: @pytest.mark.v4_20 - @pytest.mark.parametrize("expected", testdata["version"]["valid"]) - def test_valid(self, native_api, expected): + @pytest.mark.parametrize( + "test_input,expected", test_config["version"]["valid"]["input-expected"] + ) + def test_valid(self, native_api, test_input, expected): """Test Dataverse version.""" # Arrange # Act @@ -29,8 +30,10 @@ def test_valid(self, native_api, expected): class TestServer: @pytest.mark.v4_20 - @pytest.mark.parametrize("expected", testdata["server"]["api-valid"]) - def test_api_valid(self, native_api, expected): + @pytest.mark.parametrize( + "test_input,expected", test_config["server"]["api-valid"]["input-expected"] + ) + def test_api_valid(self, native_api, test_input, expected): """Test Dataverse server.""" # Arrange # Act @@ -41,8 +44,10 @@ def test_api_valid(self, native_api, expected): # Cleanup @pytest.mark.v4_20 - @pytest.mark.parametrize("expected", testdata["server"]["request-valid"]) - def test_request_valid(self, config, session, expected): + @pytest.mark.parametrize( + "test_input,expected", test_config["server"]["request-valid"]["input-expected"] + ) + def test_request_valid(self, config, session, test_input, expected): """Test Dataverse server.""" # Arrange # Act diff --git a/src/dvtests/testing/default/unit/test_oaipmh.py b/src/dvtests/testing/default/unit/test_oaipmh.py index 0fbef7d..ba664c9 100644 --- a/src/dvtests/testing/default/unit/test_oaipmh.py +++ b/src/dvtests/testing/default/unit/test_oaipmh.py @@ -1,20 +1,21 @@ -import json import os import pytest -from ..conftest import TESTING_DATA_DIR +from ..conftest import read_json +from ..conftest import TEST_CONFIG_DATA_DIR -with open( - os.path.join(TESTING_DATA_DIR, "default/unit/testdata_oaipmh.json",) -) as json_file: - testdata = json.load(json_file) +test_config = read_json( + os.path.join(TEST_CONFIG_DATA_DIR, "default/unit/test-config_oaipmh.json",) +) class TestEndpoint: @pytest.mark.v4_20 - @pytest.mark.parametrize("test_input,expected", testdata["endpoint"]["valid"]) + @pytest.mark.parametrize( + "test_input,expected", test_config["endpoint"]["valid"]["input-expected"] + ) def test_valid(self, session, test_input, expected): """Test OAI-PMH endpoints.""" # Arrange diff --git a/src/dvtests/testing/default/unit/test_robots_txt.py b/src/dvtests/testing/default/unit/test_robots_txt.py index bc0adef..46ee5db 100644 --- a/src/dvtests/testing/default/unit/test_robots_txt.py +++ b/src/dvtests/testing/default/unit/test_robots_txt.py @@ -1,21 +1,22 @@ -import json import os import pytest -from ..conftest import TESTING_DATA_DIR +from ..conftest import read_json +from ..conftest import TEST_CONFIG_DATA_DIR -with open( - os.path.join(TESTING_DATA_DIR, "default/unit/testdata_robots-txt.json",) -) as json_file: - testdata = json.load(json_file) +test_config = read_json( + os.path.join(TEST_CONFIG_DATA_DIR, "default/unit/test-config_robots-txt.json",) +) class TestRobotsTxt: @pytest.mark.v4_20 - @pytest.mark.parametrize("expected", testdata["robots-txt"]["valid"]) - def test_valid(self, config, session, expected): + @pytest.mark.parametrize( + "test_input,expected", test_config["robots-txt"]["valid"]["input-expected"] + ) + def test_valid(self, config, session, test_input, expected): """Test robots.txt.""" # Arrange url = f"{config.BASE_URL}/robots.txt" diff --git a/src/dvtests/testing/default/unit/test_sitemap.py b/src/dvtests/testing/default/unit/test_sitemap.py index f61b32a..f27a2a5 100644 --- a/src/dvtests/testing/default/unit/test_sitemap.py +++ b/src/dvtests/testing/default/unit/test_sitemap.py @@ -1,21 +1,22 @@ -import json import os import pytest -from ..conftest import TESTING_DATA_DIR +from ..conftest import read_json +from ..conftest import TEST_CONFIG_DATA_DIR -with open( - os.path.join(TESTING_DATA_DIR, "default/unit/testdata_sitemap.json",) -) as json_file: - testdata = json.load(json_file) +test_config = read_json( + os.path.join(TEST_CONFIG_DATA_DIR, "default/unit/test-config_sitemap.json",) +) class TestSitemap: @pytest.mark.v4_20 - @pytest.mark.parametrize("expected", testdata["sitemap"]["valid"]) - def test_valid(self, config, session, expected): + @pytest.mark.parametrize( + "test_input,expected", test_config["sitemap"]["valid"]["input-expected"] + ) + def test_valid(self, config, session, test_input, expected): """Test sitemap.""" # Arrange url = f"{config.BASE_URL}/sitemap.xml" diff --git a/src/dvtests/testing/default/unit/test_user.py b/src/dvtests/testing/default/unit/test_user.py index aacf65c..f0aa7a1 100644 --- a/src/dvtests/testing/default/unit/test_user.py +++ b/src/dvtests/testing/default/unit/test_user.py @@ -1,20 +1,21 @@ -import json import os import pytest -from ..conftest import TESTING_DATA_DIR +from ..conftest import read_json +from ..conftest import TEST_CONFIG_DATA_DIR -with open( - os.path.join(TESTING_DATA_DIR, "default/unit/testdata_user.json",) -) as json_file: - testdata = json.load(json_file) +test_config = read_json( + os.path.join(TEST_CONFIG_DATA_DIR, "default/unit/test-config_user.json",) +) class TestApi: @pytest.mark.v5_2 - @pytest.mark.parametrize("expected", testdata["api"]["valid"]) - def test_valid(self, native_api, expected): + @pytest.mark.parametrize( + "test_input,expected", test_config["api"]["valid"]["input-expected"] + ) + def test_valid(self, native_api, test_input, expected): """Test API user endpoint. Does not work below Dataverse 5.3 or 5.2