added open api handler to client
This commit is contained in:
parent
ac08ca855c
commit
a39e0f92a0
@ -1,15 +1,21 @@
|
||||
import sys
|
||||
|
||||
import requests
|
||||
from requests import RequestException
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
|
||||
def api_client(call_dict, verify_cert=False):
|
||||
def api_client(call_dict, verify_cert=False, oauth=False):
|
||||
|
||||
url = call_dict["url"]
|
||||
headers = call_dict["headers"]
|
||||
body = call_dict["body"]
|
||||
|
||||
if oauth:
|
||||
client = OAuth2Session(token=call_dict["token"])
|
||||
else:
|
||||
client = requests.Session()
|
||||
|
||||
method = call_dict["method"]
|
||||
|
||||
try:
|
||||
|
0
tests/oauth_service/__init__.py
Normal file
0
tests/oauth_service/__init__.py
Normal file
@ -1,13 +1,13 @@
|
||||
import json
|
||||
import pytest
|
||||
from apiclient.client import api_client
|
||||
from tests.helpers import get_expected_response
|
||||
from oauth_service.helpers import get_expected_response
|
||||
|
||||
|
||||
####
|
||||
# NOTE:
|
||||
# * api call fixtures can be found in tests/conftest.py
|
||||
# * expected response fixtures can be found in tests/expected_responses
|
||||
# * api call fixtures can be found in tests/oauth_service/conftest.py
|
||||
# * expected response fixtures can be found in tests/oauth_service/expected_responses
|
||||
####
|
||||
|
||||
@pytest.mark.get
|
0
tests/open_service/__init__.py
Normal file
0
tests/open_service/__init__.py
Normal file
29
tests/open_service/conftest.py
Normal file
29
tests/open_service/conftest.py
Normal file
@ -0,0 +1,29 @@
|
||||
import pytest
|
||||
from apiclient.config import get_cfg
|
||||
|
||||
ENV = 'gw' # This would be set in an actual OS env var on the execution platform
|
||||
CFG = get_cfg(ENV) # needed for the token, and the full api url
|
||||
|
||||
application_json = {'Content-Type': 'application/json'}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def get_creatures_call():
|
||||
api_call = {
|
||||
"method": "GET",
|
||||
"url": CFG["api_url"] + '/rules/creature',
|
||||
"headers": application_json,
|
||||
"body": {}
|
||||
}
|
||||
return api_call
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def get_creature_call():
|
||||
api_call = {
|
||||
"method": "GET",
|
||||
"url": CFG["api_url"] + '/rules/creature',
|
||||
"headers": application_json,
|
||||
"body": {"creature": "badder"}
|
||||
}
|
||||
return api_call
|
67
tests/open_service/expected_responses/test_get_creature.json
Normal file
67
tests/open_service/expected_responses/test_get_creature.json
Normal file
@ -0,0 +1,67 @@
|
||||
{
|
||||
"number": [
|
||||
3,
|
||||
6,
|
||||
0
|
||||
],
|
||||
"morale": [
|
||||
2,
|
||||
4,
|
||||
0
|
||||
],
|
||||
"hit dice": [
|
||||
6,
|
||||
6,
|
||||
0
|
||||
],
|
||||
"armour": 5,
|
||||
"environ": [
|
||||
"land"
|
||||
],
|
||||
"land speed": [
|
||||
12,
|
||||
900,
|
||||
18
|
||||
],
|
||||
"ms": [
|
||||
1,
|
||||
10,
|
||||
8
|
||||
],
|
||||
"in": [
|
||||
3,
|
||||
6,
|
||||
0
|
||||
],
|
||||
"dx": [
|
||||
1,
|
||||
10,
|
||||
11
|
||||
],
|
||||
"ch": [
|
||||
1,
|
||||
10,
|
||||
2
|
||||
],
|
||||
"cn": [
|
||||
1,
|
||||
6,
|
||||
8
|
||||
],
|
||||
"ps": [
|
||||
1,
|
||||
10,
|
||||
5
|
||||
],
|
||||
"attacks": {
|
||||
"bite": [
|
||||
1,
|
||||
6,
|
||||
0
|
||||
]
|
||||
},
|
||||
"mutations": [
|
||||
"Empathy"
|
||||
],
|
||||
"description": "1.5 meter tall bipedal mutated badgers. They inhabit temperate areas. Organized into Tech Level II societies run by their 'nobility'. 10% chance of each badder in a party having 1 Tech Level III weapon. 10d10 males of fighting age live in tunnels under their villages."
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
[
|
||||
"android",
|
||||
"ark",
|
||||
"arn",
|
||||
"badder",
|
||||
"barl nep",
|
||||
"ber lep",
|
||||
"bigoon",
|
||||
"blaash",
|
||||
"blackun",
|
||||
"blight",
|
||||
"blood bird",
|
||||
"brutorz",
|
||||
"buggem",
|
||||
"cal then",
|
||||
"carrin",
|
||||
"centisteed",
|
||||
"cren tosh",
|
||||
"crep plant",
|
||||
"dabber",
|
||||
"ert",
|
||||
"ert telden",
|
||||
"fen",
|
||||
"fleshin",
|
||||
"gator",
|
||||
"gren",
|
||||
"hawkoid",
|
||||
"herkel",
|
||||
"herp",
|
||||
"hisser",
|
||||
"hoop",
|
||||
"hopper",
|
||||
"horl choo",
|
||||
"jaget",
|
||||
"kai lin",
|
||||
"kamodo",
|
||||
"keeshin",
|
||||
"kep plant",
|
||||
"lil",
|
||||
"manta",
|
||||
"menarl",
|
||||
"narl ep",
|
||||
"obb",
|
||||
"orlen",
|
||||
"parn",
|
||||
"perth",
|
||||
"pineto",
|
||||
"podog",
|
||||
"rakox",
|
||||
"sep",
|
||||
"serf",
|
||||
"seroon lou",
|
||||
"sleeth",
|
||||
"soul besh",
|
||||
"squeeker",
|
||||
"terl",
|
||||
"wardent",
|
||||
"win seen",
|
||||
"yexil",
|
||||
"zarn",
|
||||
"zeethh"
|
||||
]
|
15
tests/open_service/helpers.py
Normal file
15
tests/open_service/helpers.py
Normal file
@ -0,0 +1,15 @@
|
||||
import os
|
||||
import json
|
||||
|
||||
|
||||
CWD = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
|
||||
####
|
||||
# HELPERS
|
||||
####
|
||||
def get_expected_response(test_name):
|
||||
expected_response_file = test_name + ".json"
|
||||
with open(os.path.join(CWD, 'expected_responses', expected_response_file), 'r') as file:
|
||||
expected_response = json.load(file)
|
||||
return expected_response
|
19
tests/open_service/test_gammaworld.py
Normal file
19
tests/open_service/test_gammaworld.py
Normal file
@ -0,0 +1,19 @@
|
||||
import json
|
||||
import pytest
|
||||
|
||||
from apiclient.client import api_client
|
||||
from open_service.helpers import get_expected_response
|
||||
|
||||
|
||||
@pytest.mark.rules
|
||||
def test_get_creatures(request, get_creatures_call):
|
||||
expected_response = get_expected_response(request.node.name)
|
||||
actual_response = api_client(get_creatures_call)
|
||||
assert json.dumps(actual_response, indent=4) == json.dumps(expected_response, indent=4)
|
||||
|
||||
|
||||
@pytest.mark.rules
|
||||
def test_get_creature(request, get_creature_call):
|
||||
expected_response = get_expected_response(request.node.name)
|
||||
actual_response = api_client(get_creature_call)
|
||||
assert json.dumps(actual_response, indent=4) == json.dumps(expected_response, indent=4)
|
Loading…
Reference in New Issue
Block a user