Refactored tests to use urljoin to create URLs

This commit is contained in:
Chris Hartjes 2019-10-16 14:03:41 -04:00
Родитель 54535fd665
Коммит 1285159dd9
13 изменённых файлов: 32 добавлений и 29 удалений

Просмотреть файл

@ -1,7 +1,7 @@
from support.assertions import assert_valid_schema
from urllib.parse import urljoin
def test_action_list(conf, requests_session):
response = requests_session.get(conf.getoption("server") + "/api/v3/action/")
response = requests_session.get(urljoin(conf.getoption("server"), "/api/v3/action/"))
assert response.status_code != 404
assert_valid_schema(response.json())

Просмотреть файл

@ -1,14 +1,15 @@
from support.assertions import assert_valid_schema
from urllib.parse import urljoin
def test_action_read(conf, requests_session):
# Get the first action from the list and use it
response = requests_session.get(conf.getoption("server") + "/api/v3/action/")
response = requests_session.get(urljoin(conf.getoption("server"), "/api/v3/action/"))
data = response.json()
action_id = data["results"][0]["id"]
response = requests_session.get(
conf.getoption("server") + "/api/v3/action/{}".format(action_id)
urljoin(conf.getoption("server"), "/api/v3/action/{}".format(action_id))
)
assert response.status_code != 404
assert_valid_schema(response.json())

Просмотреть файл

@ -1,7 +1,7 @@
from support.assertions import assert_valid_schema
from urllib.parse import urljoin
def test_approval_request_list(conf, requests_session):
response = requests_session.get(conf.getoption("server") + "/api/v3/approval_request/?page=1")
response = requests_session.get(urljoin(conf.getoption("server"), "/api/v3/approval_request/?page=1"))
assert response.status_code != 404
assert_valid_schema(response.json())

Просмотреть файл

@ -1,11 +1,12 @@
import pytest
from support.assertions import assert_valid_schema
from urllib.parse import urljoin
def test_approval_request_read(conf, requests_session):
# Get the ID of the first approval request and use it
response = requests_session.get(conf.getoption("server") + "/api/v3/approval_request/")
response = requests_session.get(urljoin(conf.getoption("server"), "/api/v3/approval_request/"))
data = response.json()
if len(data["results"]) == 0:
@ -14,7 +15,7 @@ def test_approval_request_read(conf, requests_session):
id = data["results"][0]["id"]
response = requests_session.get(
conf.getoption("server") + "/api/v3/approval_request/{}/".format(id)
urljoin(conf.getoption("server"), "/api/v3/approval_request/{}/".format(id))
)
assert response.status_code != 404
assert_valid_schema(response.json())

Просмотреть файл

@ -1,7 +1,8 @@
from support.assertions import assert_valid_schema
from urllib.parse import urljoin
def test_extension_list(conf, requests_session):
response = requests_session.get(conf.getoption("server") + "/api/v3/extension/")
response = requests_session.get(urljoin(conf.getoption("server"), "/api/v3/extension/"))
assert response.status_code != 404
assert_valid_schema(response.json())

Просмотреть файл

@ -1,10 +1,10 @@
import pytest
from support.assertions import assert_valid_schema
from urllib.parse import urljoin
def test_extension_read(conf, requests_session):
response = requests_session.get(conf.getoption("server") + "/api/v3/extension/")
response = requests_session.get(urljoin(conf.getoption("server"), "/api/v3/extension/"))
assert response.status_code != 404
details = response.json()
@ -14,6 +14,6 @@ def test_extension_read(conf, requests_session):
extension_id = details["results"][0]["id"]
response = requests_session.get(
conf.getoption("server") + "/api/v3/extension/{}".format(extension_id)
urljoin(conf.getoption("server"), "/api/v3/extension/{}".format(extension_id))
)
assert_valid_schema(response.json())

Просмотреть файл

@ -1,7 +1,7 @@
from support.assertions import assert_valid_schema
from urllib.parse import urljoin
def test_filters_list(conf, requests_session):
response = requests_session.get(conf.getoption("server") + "/api/v3/filters/")
response = requests_session.get(urljoin(conf.getoption("server"), "/api/v3/filters/"))
assert response.status_code != 404
assert_valid_schema(response.json())

Просмотреть файл

@ -1,7 +1,7 @@
from support.assertions import assert_valid_schema
from urllib.parse import urljoin
def test_list(conf, requests_session):
response = requests_session.get(conf.getoption("server") + "/api/v3")
response = requests_session.get(urljoin(conf.getoption("server"), "/api/v3"))
assert response.status_code != 404
assert_valid_schema(response.json())

Просмотреть файл

@ -2,11 +2,11 @@ import pytest
from random import randint
from support.assertions import assert_valid_schema
from urllib.parse import urljoin
def test_recipe_history(conf, requests_session):
# Get the ID of a random recipe and grab it's history
response = requests_session.get(conf.getoption("server") + "/api/v3/recipe/")
response = requests_session.get(urljoin(conf.getoption("server"), "/api/v3/recipe/"))
data = response.json()
if len(data["results"]) == 0:
@ -15,7 +15,7 @@ def test_recipe_history(conf, requests_session):
idx = randint(0, len(data["results"]) - 1)
id = data["results"][idx]["id"]
response = requests_session.get(
conf.getoption("server") + "/api/v3/recipe/{}/history/".format(id)
urljoin(conf.getoption("server"), "/api/v3/recipe/{}/history/".format(id))
)
assert response.status_code != 404
assert_valid_schema(response.json())

Просмотреть файл

@ -1,7 +1,7 @@
from support.assertions import assert_valid_schema
from urllib.parse import urljoin
def test_recipe_list(conf, requests_session):
response = requests_session.get(conf.getoption("server") + "/api/v3/recipe/")
response = requests_session.get(urljoin(conf.getoption("server"), "/api/v3/recipe/"))
assert response.status_code != 404
assert_valid_schema(response.json())

Просмотреть файл

@ -2,11 +2,11 @@ import pytest
from random import randint
from support.assertions import assert_valid_schema
from urllib.parse import urljoin
def test_recipe_read(conf, requests_session):
# Get random recipe and make sure it's valid
response = requests_session.get(conf.getoption("server") + "/api/v3/recipe/")
response = requests_session.get(urljoin(conf.getoption("server"), "/api/v3/recipe/"))
data = response.json()
if len(data["results"]) == 0:
@ -15,7 +15,7 @@ def test_recipe_read(conf, requests_session):
element = randint(0, len(data["results"]) - 1)
recipe_id = data["results"][element]["id"]
response = requests_session.get(
conf.getoption("server") + "/api/v3/recipe/{}".format(recipe_id)
urljoin(conf.getoption("server"), "/api/v3/recipe/{}".format(recipe_id))
)
data = response.json()
assert response.status_code != 404

Просмотреть файл

@ -1,7 +1,7 @@
from support.assertions import assert_valid_schema
from urllib.parse import urljoin
def test_recipe_revision_list(conf, requests_session):
response = requests_session.get(conf.getoption("server") + "/api/v3/recipe_revision/")
response = requests_session.get(urljoin(conf.getoption("server"), "/api/v3/recipe_revision/"))
assert response.status_code != 404
assert_valid_schema(response.json())

Просмотреть файл

@ -2,11 +2,11 @@ import pytest
from random import randint
from support.assertions import assert_valid_schema
from urllib.parse import urljoin
def test_recipe_revision_read(conf, requests_session):
# Get a random recipe revision from the list and verify it
response = requests_session.get(conf.getoption("server") + "/api/v3/recipe_revision/")
response = requests_session.get(urljoin(conf.getoption("server"), "/api/v3/recipe_revision/"))
data = response.json()
if len(data["results"]) == 0:
@ -15,6 +15,6 @@ def test_recipe_revision_read(conf, requests_session):
idx = randint(0, len(data["results"]) - 1)
id = data["results"][idx]["id"]
response = requests_session.get(
conf.getoption("server") + "/api/v3/recipe_revision/{}/".format(id)
urljoin(conf.getoption("server"), "/api/v3/recipe_revision/{}/".format(id))
)
assert_valid_schema(response.json())