code cleanup for pylint
All checks were successful
Pylint / build (3.12) (push) Successful in 9s
execute / build (3.12) (push) Successful in 25s

This commit is contained in:
Greg Gauthier 2024-07-22 19:26:27 +01:00
parent c6a87dff12
commit a727c58cf3
20 changed files with 467 additions and 466 deletions

View File

@ -1,6 +1,6 @@
name: execute name: execute
on: [push] on: [ push ]
env: env:
BUILD_TYPE: Release BUILD_TYPE: Release
@ -10,34 +10,34 @@ jobs:
runs-on: ubuntu-gitea runs-on: ubuntu-gitea
strategy: strategy:
matrix: matrix:
python-version: ["3.12"] python-version: [ "3.12" ]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }} - name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3 uses: actions/setup-python@v3
with: with:
python-version: ${{ matrix.python-version }} python-version: ${{ matrix.python-version }}
- name: Install dependencies - name: Install dependencies
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install pylint pip install pylint
python -m pip install -r requirements.txt python -m pip install -r requirements.txt
- name: Prep Env Files - name: Prep Env Files
run: | run: |
touch .env.gw touch .env.gw
touch .env.qa touch .env.qa
- name: Run Open Api Tests - name: Run Open Api Tests
run: | run: |
echo "API_URL=${{ vars.GAMMA_WORLD_API_URL }}" >> .env.gw echo "API_URL=${{ vars.GAMMA_WORLD_API_URL }}" >> .env.gw
pytest -rA --durations=0 --color=auto --config-file=./pytest.ini -m rules pytest -rA --durations=0 --color=auto --config-file=./pytest.ini -m rules
- name: Run Oauth2 Api Tests - name: Run Oauth2 Api Tests
run: | run: |
echo "API_URL=${{ secrets.EDD_QA_API_URL }}" >> .env.qa echo "API_URL=${{ secrets.EDD_QA_API_URL }}" >> .env.qa
echo "CLIENT_ID=${{ secrets.EDD_CLIENT_ID }}" >> .env.qa echo "CLIENT_ID=${{ secrets.EDD_CLIENT_ID }}" >> .env.qa
echo "CLIENT_SECRET=${{ secrets.EDD_CLIENT_SECRET }}" >> .env.qa echo "CLIENT_SECRET=${{ secrets.EDD_CLIENT_SECRET }}" >> .env.qa
echo "TOKEN_FETCH_URL=${{ secrets.EDD_TOKEN_FETCH_URL }}" >> .env.qa echo "TOKEN_FETCH_URL=${{ secrets.EDD_TOKEN_FETCH_URL }}" >> .env.qa
echo "LOGIN=${{ secrets.EDD_QA_LOGIN }}" >> .env.qa echo "LOGIN=${{ secrets.EDD_QA_LOGIN }}" >> .env.qa
echo "PASSWORD=${{ secrets.EDD_QA_PWD }}" >> .env.qa echo "PASSWORD=${{ secrets.EDD_QA_PWD }}" >> .env.qa
echo "AUDIENCE=${{ secrets.EDD_AUDIENCE }}" >> .env.qa echo "AUDIENCE=${{ secrets.EDD_AUDIENCE }}" >> .env.qa
echo "SCOPES=${{ secrets.EDD_SCOPES }}" >> .env.qa echo "SCOPES=${{ secrets.EDD_SCOPES }}" >> .env.qa
pytest -rA --durations=0 --color=auto --config-file=./pytest.ini -m get pytest -rA --durations=0 --color=auto --config-file=./pytest.ini -m get

View File

@ -1,24 +1,24 @@
name: Pylint name: Pylint
on: [push] on: [ push ]
jobs: jobs:
build: build:
runs-on: ubuntu-gitea runs-on: ubuntu-gitea
strategy: strategy:
matrix: matrix:
python-version: ["3.12"] python-version: [ "3.12" ]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }} - name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3 uses: actions/setup-python@v3
with: with:
python-version: ${{ matrix.python-version }} python-version: ${{ matrix.python-version }}
- name: Install dependencies - name: Install dependencies
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install pylint pip install pylint
python -m pip install -r requirements.txt python -m pip install -r requirements.txt
- name: Analysing the code with pylint - name: Analysing the code with pylint
run: | run: |
pylint $(git ls-files '*.py') pylint $(git ls-files '*.py')

View File

@ -1,27 +1,35 @@
# pytest-api # pytest-api
This is a proof-of-concept project, showing how PyTest could be used in combination with a custom API client, to quickly and easily build api tests for a data-delivery service that is deployed and active on an existing environment. This is a proof-of-concept project, showing how PyTest could be used in combination with a custom API client, to quickly
and easily build api tests for a data-delivery service that is deployed and active on an existing environment.
## Instructions ## Instructions
1. Add a `.env` file to your local copy of the repo. By default, this demo project will look for `.env.qa` in the root of the project. You can find a template to base this on, in `apiclient/env_template`. Info on how to set the values in that file can be found by asking Greg. 1. Add a `.env` file to your local copy of the repo. By default, this demo project will look for `.env.qa` in the root
of the project. You can find a template to base this on, in `apiclient/env_template`. Info on how to set the values
in that file can be found by asking Greg.
2. Create your virtual env: 2. Create your virtual env:
```shell ```shell
python3 -m venv venv python3 -m venv venv
``` ```
3. Activate the environment: 3. Activate the environment:
```shell ```shell
source venv/bin/activate source venv/bin/activate
``` ```
On Windows: On Windows:
```shell ```shell
.\venv\Scripts\activate .\venv\Scripts\activate
``` ```
4. Install requirements (pip will come from your venv) 4. Install requirements (pip will come from your venv)
```shell ```shell
pip install -r requirements.txt pip install -r requirements.txt
``` ```
@ -70,7 +78,8 @@ PASSED tests/test_datadelivery.py::test_datadelivery_redaction_type_get
================================================================================================== 5 passed, 5 warnings in 17.20s =================================================================================================== ================================================================================================== 5 passed, 5 warnings in 17.20s ===================================================================================================
``` ```
PyTest is configured to show the top 25 test durations, as well as the pass/fail status of all the tests. The tests have been marked with various tags, to allow for granular test selection. To see all the available markers: PyTest is configured to show the top 25 test durations, as well as the pass/fail status of all the tests. The tests have
been marked with various tags, to allow for granular test selection. To see all the available markers:
``` ```
(.venv) PS C:\Users\GregGauthier\Projects\local\pytest-api> pytest --markers (.venv) PS C:\Users\GregGauthier\Projects\local\pytest-api> pytest --markers

View File

@ -6,7 +6,6 @@ from requests_oauthlib import OAuth2Session
def api_client(call_dict, verify_cert=False, oauth=False): def api_client(call_dict, verify_cert=False, oauth=False):
method = call_dict["method"] method = call_dict["method"]
url = call_dict["url"] url = call_dict["url"]
headers = call_dict["headers"] headers = call_dict["headers"]
@ -35,10 +34,9 @@ def api_client(call_dict, verify_cert=False, oauth=False):
except RequestException as e: except RequestException as e:
print(f"Request failed. Method: {method}, URL: {url}", file=sys.stderr) print(f"Request failed. Method: {method}, URL: {url}", file=sys.stderr)
print(f"Error details: {str(e)}", file=sys.stderr) print(f"Error details: {str(e)}", file=sys.stderr)
exit(e.response.status_code) sys.exit(e.response.status_code)
if response.status_code == 200: if response.status_code == 200:
return response.json() return response.json()
else:
return response.status_code, response.reason
return response.status_code, response.reason

View File

@ -1,7 +1,7 @@
import os import os
from dotenv import dotenv_values
from types import MappingProxyType from types import MappingProxyType
from dotenv import dotenv_values
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

View File

@ -1,8 +1,8 @@
import json import json
from apiclient.config import get_cfg
from apiclient.client import api_client
from apiclient.oauth_helper import get_legacy_token
from apiclient.client import api_client
from apiclient.config import get_cfg
from apiclient.oauth_helper import get_legacy_token
ENV = 'qa' ENV = 'qa'
cfg = get_cfg(ENV) cfg = get_cfg(ENV)

View File

@ -1,7 +1,9 @@
import sys
from oauthlib.oauth2 import LegacyApplicationClient, OAuth2Error from oauthlib.oauth2 import LegacyApplicationClient, OAuth2Error
from requests_oauthlib import OAuth2Session from requests_oauthlib import OAuth2Session
from apiclient.config import get_cfg from apiclient.config import get_cfg
import sys
def get_legacy_token(env): def get_legacy_token(env):
@ -22,6 +24,6 @@ def get_legacy_token(env):
) )
except OAuth2Error as e: except OAuth2Error as e:
print("OAuth2 Error: ", str(e), file=sys.stderr) print("OAuth2 Error: ", str(e), file=sys.stderr)
exit(e.status_code) sys.exit(e.status_code)
return token return token

View File

@ -3,3 +3,4 @@ requests~=2.32.3
requests-oauthlib~=2.0.0 requests-oauthlib~=2.0.0
python-dotenv~=1.0.1 python-dotenv~=1.0.1
pytest~=8.2.2 pytest~=8.2.2
pylint~=3.2.6

View File

@ -17,4 +17,3 @@ def reset_oauth_session():
oauth_session.cookies.clear() oauth_session.cookies.clear()
yield oauth_session yield oauth_session
oauth_session.close() oauth_session.close()

View File

@ -1,15 +1,13 @@
import os
import json import json
import os
CWD = os.path.dirname(os.path.realpath(__file__)) CWD = os.path.dirname(os.path.realpath(__file__))
#### def get_expected_response(pkg, test_name):
# HELPERS
####
def get_expected_response(test_name):
expected_response_file = test_name + ".json" expected_response_file = test_name + ".json"
with open(os.path.join(CWD, 'expected_responses', expected_response_file), 'r') as file: with open(
os.path.join(CWD, pkg, 'expected_responses', expected_response_file),
'r', encoding="utf8") as file:
expected_response = json.load(file) expected_response = json.load(file)
return expected_response return expected_response

View File

@ -1,8 +1,9 @@
# pylint: disable=line-too-long,unused-argument
import pytest import pytest
from apiclient.config import get_cfg from apiclient.config import get_cfg
from apiclient.oauth_helper import get_legacy_token from apiclient.oauth_helper import get_legacy_token
ENV = 'qa' ENV = 'qa'
CFG = get_cfg(ENV, force_refresh=True) CFG = get_cfg(ENV, force_refresh=True)
application_json = {'Content-Type': 'application/json'} application_json = {'Content-Type': 'application/json'}

View File

@ -1,42 +1,42 @@
[ [
{ {
"ClientId" : "e72cdfde-957a-4f65-9f5e-c7b18e95d8dc", "ClientId": "e72cdfde-957a-4f65-9f5e-c7b18e95d8dc",
"ClientSecret" : "f4ca195c-989c-48e6-a002-b1fb7b3c03fd", "ClientSecret": "f4ca195c-989c-48e6-a002-b1fb7b3c03fd",
"IsActive" : 1, "IsActive": 1,
"Name" : "testcase", "Name": "testcase",
"date_of_generation" : "2024-04-25 04:48:47", "date_of_generation": "2024-04-25 04:48:47",
"id" : 1, "id": 1,
"last_connection" : null, "last_connection": null,
"organization_id" : 16 "organization_id": 16
}, },
{ {
"ClientId" : "b0dd74c2-9f39-45fc-a52e-b1130ffddbb5", "ClientId": "b0dd74c2-9f39-45fc-a52e-b1130ffddbb5",
"ClientSecret" : "71b2ab0e-d3fa-40e2-a40e-2088ae716a46", "ClientSecret": "71b2ab0e-d3fa-40e2-a40e-2088ae716a46",
"IsActive" : 1, "IsActive": 1,
"Name" : "Test", "Name": "Test",
"date_of_generation" : "2024-05-20 07:22:31", "date_of_generation": "2024-05-20 07:22:31",
"id" : 2, "id": 2,
"last_connection" : null, "last_connection": null,
"organization_id" : 1 "organization_id": 1
}, },
{ {
"ClientId" : "be1a0686-fed2-4d79-a04c-c473c6c3e22e", "ClientId": "be1a0686-fed2-4d79-a04c-c473c6c3e22e",
"ClientSecret" : "ddfdaee7-1fe5-4f62-964c-cb2b8e8397e1", "ClientSecret": "ddfdaee7-1fe5-4f62-964c-cb2b8e8397e1",
"IsActive" : 1, "IsActive": 1,
"Name" : "Test3", "Name": "Test3",
"date_of_generation" : "2024-05-20 10:58:35", "date_of_generation": "2024-05-20 10:58:35",
"id" : 3, "id": 3,
"last_connection" : null, "last_connection": null,
"organization_id" : 1 "organization_id": 1
}, },
{ {
"ClientId" : "37f7afc6-91a1-4c2d-9696-0e8db6fc1bc6", "ClientId": "37f7afc6-91a1-4c2d-9696-0e8db6fc1bc6",
"ClientSecret" : "40106ff7-7feb-4869-b4c9-eeed5dee2f36", "ClientSecret": "40106ff7-7feb-4869-b4c9-eeed5dee2f36",
"IsActive" : 1, "IsActive": 1,
"Name" : "test4", "Name": "test4",
"date_of_generation" : "2024-05-20 11:14:16", "date_of_generation": "2024-05-20 11:14:16",
"id" : 4, "id": 4,
"last_connection" : null, "last_connection": null,
"organization_id" : 1 "organization_id": 1
} }
] ]

View File

@ -1,22 +1,22 @@
[ [
{ {
"description" : "RAW A717 Redaction Type", "description": "RAW A717 Redaction Type",
"name" : "RAWA717", "name": "RAWA717",
"redactiontype_id" : 1 "redactiontype_id": 1
}, },
{ {
"description" : "RAW A767 Redaction Type", "description": "RAW A767 Redaction Type",
"name" : "RAWA767", "name": "RAWA767",
"redactiontype_id" : 2 "redactiontype_id": 2
}, },
{ {
"description" : "CSV Redaction Type", "description": "CSV Redaction Type",
"name" : "CSV", "name": "CSV",
"redactiontype_id" : 3 "redactiontype_id": 3
}, },
{ {
"description" : "PARQUET Redaction Type", "description": "PARQUET Redaction Type",
"name" : "PARQUET", "name": "PARQUET",
"redactiontype_id" : 4 "redactiontype_id": 4
} }
] ]

View File

@ -1,184 +1,184 @@
[ [
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 151, "role_id": 151,
"role_name": "Administrator", "role_name": "Administrator",
"role_standard": 1 "role_standard": 1
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 5362, "role_id": 5362,
"role_name": "API_Non_Admin_ViewOnly_Enginetypes", "role_name": "API_Non_Admin_ViewOnly_Enginetypes",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 6459, "role_id": 6459,
"role_name": "API_TEST_MLBCUJ", "role_name": "API_TEST_MLBCUJ",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 6363, "role_id": 6363,
"role_name": "API_TEST_MPOYIM", "role_name": "API_TEST_MPOYIM",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 6354, "role_id": 6354,
"role_name": "API_TEST_STOZBG", "role_name": "API_TEST_STOZBG",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 5844, "role_id": 5844,
"role_name": "clone_admin_role", "role_name": "clone_admin_role",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 6200, "role_id": 6200,
"role_name": "create_aircraft_groups_nonadmin_api", "role_name": "create_aircraft_groups_nonadmin_api",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 6223, "role_id": 6223,
"role_name": "create_aircraft_groups_nonadmin_api01", "role_name": "create_aircraft_groups_nonadmin_api01",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 6043, "role_id": 6043,
"role_name": "create_not_allowed", "role_name": "create_not_allowed",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 6056, "role_id": 6056,
"role_name": "create_not_allowed_1", "role_name": "create_not_allowed_1",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 6059, "role_id": 6059,
"role_name": "create_not_allowed_22", "role_name": "create_not_allowed_22",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 5978, "role_id": 5978,
"role_name": "delete_non_admin_airframer", "role_name": "delete_non_admin_airframer",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 5372, "role_id": 5372,
"role_name": "manage_config_role", "role_name": "manage_config_role",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 5537, "role_id": 5537,
"role_name": "new_role", "role_name": "new_role",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 5733, "role_id": 5733,
"role_name": "new_role_sample", "role_name": "new_role_sample",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 5839, "role_id": 5839,
"role_name": "Sample_data", "role_name": "Sample_data",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 5548, "role_id": 5548,
"role_name": "smample_role_009", "role_name": "smample_role_009",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 5546, "role_id": 5546,
"role_name": "t_role", "role_name": "t_role",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 1, "role_admin": 1,
"role_id": 152, "role_id": 152,
"role_name": "TDY Administrator", "role_name": "TDY Administrator",
"role_standard": 1 "role_standard": 1
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 5628, "role_id": 5628,
"role_name": "Test_4", "role_name": "Test_4",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 5538, "role_id": 5538,
"role_name": "Test_Sample_21", "role_name": "Test_Sample_21",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 4602, "role_id": 4602,
"role_name": "test_sample_3 ", "role_name": "test_sample_3 ",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 4609, "role_id": 4609,
"role_name": "test_sample_4 ", "role_name": "test_sample_4 ",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 5736, "role_id": 5736,
"role_name": "Test_Sample_data", "role_name": "Test_Sample_data",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 4595, "role_id": 4595,
"role_name": "test_sample3 ", "role_name": "test_sample3 ",
"role_standard": 0 "role_standard": 0
}, },
{ {
"application_id": 1, "application_id": 1,
"role_admin": 0, "role_admin": 0,
"role_id": 6257, "role_id": 6257,
"role_name": "view_aircraftmodel_nonadmin1", "role_name": "view_aircraftmodel_nonadmin1",
"role_standard": 0 "role_standard": 0
} }
] ]

View File

@ -1,8 +1,12 @@
import json import json
import pytest
from apiclient.client import api_client
from tests.oauth_service.helpers import get_expected_response
import pytest
from apiclient.client import api_client
from tests.helpers import get_expected_response
pkg_name = __package__.split('.')[1]
#### ####
# NOTE: # NOTE:
@ -13,7 +17,7 @@ from tests.oauth_service.helpers import get_expected_response
@pytest.mark.get @pytest.mark.get
@pytest.mark.role @pytest.mark.role
def test_datadelivery_role_get(request, role_get_call): def test_datadelivery_role_get(request, role_get_call):
expected_response = get_expected_response(request.node.name) expected_response = get_expected_response(pkg_name, request.node.name)
actual_response = api_client(role_get_call, oauth=True) actual_response = api_client(role_get_call, oauth=True)
assert json.dumps(actual_response, indent=4) == json.dumps(expected_response, indent=4) assert json.dumps(actual_response, indent=4) == json.dumps(expected_response, indent=4)
@ -21,7 +25,7 @@ def test_datadelivery_role_get(request, role_get_call):
@pytest.mark.get @pytest.mark.get
@pytest.mark.redaction @pytest.mark.redaction
def test_datadelivery_acms_redaction_get(request, acms_redaction_get_call): def test_datadelivery_acms_redaction_get(request, acms_redaction_get_call):
expected_response = get_expected_response(request.node.name) expected_response = get_expected_response(pkg_name,request.node.name)
actual_response = api_client(acms_redaction_get_call, oauth=True) actual_response = api_client(acms_redaction_get_call, oauth=True)
assert json.dumps(actual_response, indent=4) == json.dumps(expected_response, indent=4) assert json.dumps(actual_response, indent=4) == json.dumps(expected_response, indent=4)
@ -29,7 +33,7 @@ def test_datadelivery_acms_redaction_get(request, acms_redaction_get_call):
@pytest.mark.get @pytest.mark.get
@pytest.mark.client_application @pytest.mark.client_application
def test_datadelivery_client_applications_get(request, client_applications_get_call): def test_datadelivery_client_applications_get(request, client_applications_get_call):
expected_response = get_expected_response(request.node.name) expected_response = get_expected_response(pkg_name, request.node.name)
actual_response = api_client(client_applications_get_call, oauth=True) actual_response = api_client(client_applications_get_call, oauth=True)
assert json.dumps(actual_response, indent=4) == json.dumps(expected_response, indent=4) assert json.dumps(actual_response, indent=4) == json.dumps(expected_response, indent=4)
@ -37,7 +41,7 @@ def test_datadelivery_client_applications_get(request, client_applications_get_c
@pytest.mark.get @pytest.mark.get
@pytest.mark.endpoint @pytest.mark.endpoint
def test_datadelivery_endpoint_get(request, endpoint_get_call): def test_datadelivery_endpoint_get(request, endpoint_get_call):
expected_response = get_expected_response(request.node.name) expected_response = get_expected_response(pkg_name, request.node.name)
actual_response = api_client(endpoint_get_call, oauth=True) actual_response = api_client(endpoint_get_call, oauth=True)
assert json.dumps(actual_response, indent=4) == json.dumps(expected_response, indent=4) assert json.dumps(actual_response, indent=4) == json.dumps(expected_response, indent=4)
@ -45,6 +49,6 @@ def test_datadelivery_endpoint_get(request, endpoint_get_call):
@pytest.mark.get @pytest.mark.get
@pytest.mark.redaction @pytest.mark.redaction
def test_datadelivery_redaction_type_get(request, redaction_type_get_call): def test_datadelivery_redaction_type_get(request, redaction_type_get_call):
expected_response = get_expected_response(request.node.name) expected_response = get_expected_response(pkg_name, request.node.name)
actual_response = api_client(redaction_type_get_call, oauth=True) actual_response = api_client(redaction_type_get_call, oauth=True)
assert json.dumps(actual_response, indent=4) == json.dumps(expected_response, indent=4) assert json.dumps(actual_response, indent=4) == json.dumps(expected_response, indent=4)

View File

@ -1,6 +1,7 @@
# pylint: disable=line-too-long,unused-argument
import pytest import pytest
from apiclient.config import get_cfg
from apiclient.config import get_cfg
CFG = get_cfg('gw', force_refresh=True) CFG = get_cfg('gw', force_refresh=True)

View File

@ -1,67 +1,67 @@
{ {
"number": [ "number": [
3, 3,
6, 6,
0 0
], ],
"morale": [ "morale": [
2, 2,
4, 4,
0 0
], ],
"hit dice": [ "hit dice": [
6, 6,
6, 6,
0 0
], ],
"armour": 5, "armour": 5,
"environ": [ "environ": [
"land" "land"
], ],
"land speed": [ "land speed": [
12, 12,
900, 900,
18 18
], ],
"ms": [ "ms": [
1, 1,
10, 10,
8 8
], ],
"in": [ "in": [
3, 3,
6, 6,
0 0
], ],
"dx": [ "dx": [
1, 1,
10, 10,
11 11
], ],
"ch": [ "ch": [
1, 1,
10, 10,
2 2
], ],
"cn": [ "cn": [
1, 1,
6, 6,
8 8
], ],
"ps": [ "ps": [
1, 1,
10, 10,
5 5
], ],
"attacks": { "attacks": {
"bite": [ "bite": [
1, 1,
6, 6,
0 0
] ]
}, },
"mutations": [ "mutations": [
"Empathy" "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." "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."
} }

View File

@ -1,62 +1,62 @@
[ [
"android", "android",
"ark", "ark",
"arn", "arn",
"badder", "badder",
"barl nep", "barl nep",
"ber lep", "ber lep",
"bigoon", "bigoon",
"blaash", "blaash",
"blackun", "blackun",
"blight", "blight",
"blood bird", "blood bird",
"brutorz", "brutorz",
"buggem", "buggem",
"cal then", "cal then",
"carrin", "carrin",
"centisteed", "centisteed",
"cren tosh", "cren tosh",
"crep plant", "crep plant",
"dabber", "dabber",
"ert", "ert",
"ert telden", "ert telden",
"fen", "fen",
"fleshin", "fleshin",
"gator", "gator",
"gren", "gren",
"hawkoid", "hawkoid",
"herkel", "herkel",
"herp", "herp",
"hisser", "hisser",
"hoop", "hoop",
"hopper", "hopper",
"horl choo", "horl choo",
"jaget", "jaget",
"kai lin", "kai lin",
"kamodo", "kamodo",
"keeshin", "keeshin",
"kep plant", "kep plant",
"lil", "lil",
"manta", "manta",
"menarl", "menarl",
"narl ep", "narl ep",
"obb", "obb",
"orlen", "orlen",
"parn", "parn",
"perth", "perth",
"pineto", "pineto",
"podog", "podog",
"rakox", "rakox",
"sep", "sep",
"serf", "serf",
"seroon lou", "seroon lou",
"sleeth", "sleeth",
"soul besh", "soul besh",
"squeeker", "squeeker",
"terl", "terl",
"wardent", "wardent",
"win seen", "win seen",
"yexil", "yexil",
"zarn", "zarn",
"zeethh" "zeethh"
] ]

View File

@ -1,15 +0,0 @@
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

View File

@ -1,19 +1,22 @@
import json import json
import pytest import pytest
from apiclient.client import api_client from apiclient.client import api_client
from tests.open_service.helpers import get_expected_response from tests.helpers import get_expected_response
pkg_name = __package__.split('.')[1]
@pytest.mark.rules @pytest.mark.rules
def test_get_creatures(request, get_creatures_call): def test_get_creatures(request, get_creatures_call):
expected_response = get_expected_response(request.node.name) expected_response = get_expected_response(pkg_name, request.node.name)
actual_response = api_client(get_creatures_call, oauth=False) actual_response = api_client(get_creatures_call, oauth=False)
assert json.dumps(actual_response, indent=4) == json.dumps(expected_response, indent=4) assert json.dumps(actual_response, indent=4) == json.dumps(expected_response, indent=4)
@pytest.mark.rules @pytest.mark.rules
def test_get_creature(request, get_creature_call): def test_get_creature(request, get_creature_call):
expected_response = get_expected_response(request.node.name) expected_response = get_expected_response(pkg_name, request.node.name)
actual_response = api_client(get_creature_call, oauth=False) actual_response = api_client(get_creature_call, oauth=False)
assert json.dumps(actual_response, indent=4) == json.dumps(expected_response, indent=4) assert json.dumps(actual_response, indent=4) == json.dumps(expected_response, indent=4)