Skip to content

Commit

Permalink
re-factor default unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skasberger committed Apr 26, 2021
1 parent 5a153ee commit dde6008
Show file tree
Hide file tree
Showing 29 changed files with 636 additions and 329 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ __pycache__/
internal
Pipfile.lock
browserengines
src/dvtests/testing/data
src/dvtests/data
env-config/
dendron.yml
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ markers =
v4_18_1: mark test as working for Dataverse v4.18.1
v4_20: mark test as working for Dataverse v4.20
selenium: mark test as using selenium frontend testing
smoke: mark test as smoke tests

[flake8]
max-line-length = 88
Expand Down
1 change: 1 addition & 0 deletions src/dvtests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class UtilsConfig(BaseSettings):

class TestingConfig(BaseSettings):
INSTANCE: str
BASE_URL: str = None
API_TOKEN: str = ""
USER_AGENT: str = None
HEADLESS: bool = True
Expand Down
83 changes: 78 additions & 5 deletions src/dvtests/testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from time import sleep

import pytest
import requests
from pyDataverse.api import NativeApi
from selenium import webdriver
from selenium.webdriver.common.by import By

Expand All @@ -16,20 +18,64 @@

@pytest.fixture
def config():
# Arrange
# Act
# Assert
# Cleanup
if os.getenv("ENV_FILE"):
return TestingConfig(_env_file=os.getenv("ENV_FILE"))
else:
return TestingConfig()


INSTANCE = (
TestingConfig(_env_file=os.getenv("ENV_FILE")).INSTANCE
if os.getenv("ENV_FILE")
else TestingConfig().INSTANCE
)
BASE_URL = (
TestingConfig(_env_file=os.getenv("ENV_FILE")).BASE_URL
if os.getenv("ENV_FILE")
else TestingConfig().BASE_URL
)


@pytest.fixture
def session(config):
# Arrange
# Act
# Assert
# Cleanup
s = requests.Session()
s.headers.update({"User-Agent": config.USER_AGENT})
return s


@pytest.fixture
def native_api(config):
# Arrange
# Act
# Assert
# Cleanup
return NativeApi(BASE_URL)


@pytest.fixture
def test_config(config):
# Arrange
# Act
# Assert
# Cleanup
instance_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data")
return read_json(os.path.join(instance_dir, config.INSTANCE + ".json"))


@pytest.fixture
def firefox_options(firefox_options, config):
# Arrange
# Act
# Assert
# Cleanup
firefox_options.add_argument("-foreground")
if config.HEADLESS:
firefox_options.headless = True
Expand All @@ -42,6 +88,10 @@ def firefox_options(firefox_options, config):

@pytest.fixture
def chrome_options(chrome_options, config):
# Arrange
# Act
# Assert
# Cleanup
if config.HEADLESS:
chrome_options.add_argument("--headless")
if config.USER_AGENT:
Expand All @@ -54,12 +104,11 @@ def chrome_options(chrome_options, config):
return chrome_options


def login_normal_user(driver, test_config, config, user, password):
base_url = test_config["instance"]["base-url"]
driver.get(f"{base_url}/loginpage.xhtml")
driver.set_window_size(config.WINDOW_WIDTH, config.WINDOW_HEIGHT)
def login_normal_user(driver, login_mode, window_width, window_height, user, password):
driver.get(f"{BASE_URL}/loginpage.xhtml")
driver.set_window_size(window_width, window_height)
sleep(5)
if test_config["tests"]["login"]["login-page"] == "normal-user-and-shibboleth":
if login_mode == "normal-user-and-shibboleth":
driver.find_element(By.LINK_TEXT, "Username/Email").click()
sleep(3)
driver.find_element(By.ID, "loginForm:credentialsContainer:0:credValue").send_keys(
Expand Down Expand Up @@ -135,6 +184,10 @@ def read_json(filename: str, mode: str = "r", encoding: str = "utf-8") -> dict:

@pytest.fixture
def dataverse_upload_full_01():
# Arrange
# Act
# Assert
# Cleanup
return read_json(
os.path.join(
ROOT_DIR,
Expand All @@ -145,6 +198,10 @@ def dataverse_upload_full_01():

@pytest.fixture
def dataverse_upload_min_01():
# Arrange
# Act
# Assert
# Cleanup
return read_json(
os.path.join(
ROOT_DIR,
Expand All @@ -155,6 +212,10 @@ def dataverse_upload_min_01():

@pytest.fixture
def dataset_upload_default_full_01():
# Arrange
# Act
# Assert
# Cleanup
return read_json(
os.path.join(
ROOT_DIR,
Expand All @@ -165,6 +226,10 @@ def dataset_upload_default_full_01():

@pytest.fixture
def dataset_upload_default_min_02():
# Arrange
# Act
# Assert
# Cleanup
return read_json(
os.path.join(
ROOT_DIR,
Expand All @@ -175,6 +240,10 @@ def dataset_upload_default_min_02():

@pytest.fixture
def datafile_upload_full_01():
# Arrange
# Act
# Assert
# Cleanup
return read_json(
os.path.join(
ROOT_DIR,
Expand All @@ -185,6 +254,10 @@ def datafile_upload_full_01():

@pytest.fixture
def datafile_upload_min_01():
# Arrange
# Act
# Assert
# Cleanup
return read_json(
os.path.join(
ROOT_DIR,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"shibboleth": {
"login-valid": [
{
"title": "AUSSDA"
}
]
},
"normal-login": {
"login-valid": [
[
{
"login-mode": "normal-user-and-shibboleth"
},
{
"title": "AUSSDA"
}
]
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"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"
}
]
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"shibboleth": {
"interface-valid": [
[
{
"url": "/Shibboleth.sso/DiscoFeed"
},
{
"content-type": "application/json; charset=UTF-8"
}
],
[
{
"url": "/Shibboleth.sso/Metadata"
},
{
"content-type": "application/samlmetadata+xml"
}
]
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"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"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"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"
}
]
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"robots-txt": {
"valid": [
{
"encoding": "ISO-8859-1",
"content-type": "text/plain"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"sitemap": {
"valid": [
{
"encoding": "ISO-8859-1",
"content-type": "application/xml"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"api": {
"valid": [
{
"url": "data.aussda.at"
}
]
}
}
2 changes: 2 additions & 0 deletions src/dvtests/testing/default/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from ..conftest import BASE_URL
from ..conftest import click_cookie_rollbar
from ..conftest import INSTANCE
from ..conftest import login_normal_user
from ..conftest import login_shibboleth_user
from ..conftest import read_json
Expand Down
Loading

0 comments on commit dde6008

Please sign in to comment.