-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init player tests & reliability changes to pool recycle, timeout (#8)
* add makefile * init makefile * init test_player * base url check * testing players score, not working, 404 * make it a list of strings * working check of generic player1 * seperate player base prefix and add tag score * adding pool_recycle to use docker compose env var * force recreate and open docs * keep clean use docker compose env vars or .env * working config * reverting to known good version * name format code smells * not needed * test valid and invalid player returns ok * change pool recycle and timeout to reflect prod * should be utf-8 * needs cryptography * freeze version 41.03 * missing peroid on version * add verbose to docker commands * updating crypto to .4 * review fixes * idk why it removed the requirements --------- Co-authored-by: extreme4all <[email protected]>
- Loading branch information
1 parent
786d20f
commit 7d4e546
Showing
6 changed files
with
132 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
ENV = "DVP" | ||
DATABASE_URL = "mysql+aiomysql://root:root_bot_buster@localhost/playerdata" | ||
KAFKA_HOST = "kafka:9092" | ||
KAFKA_HOST = "kafka:9092" | ||
POOL_RECYCLE = 60 | ||
POOL_TIMEOUT = 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
.PHONY: clean clean-test clean-pyc clean-build build help | ||
.DEFAULT_GOAL := help | ||
|
||
define PRINT_HELP_PYSCRIPT | ||
import re, sys | ||
|
||
for line in sys.stdin: | ||
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) | ||
if match: | ||
target, help = match.groups() | ||
print("%-20s %s" % (target, help)) | ||
endef | ||
export PRINT_HELP_PYSCRIPT | ||
|
||
help: | ||
@python3 -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) | ||
|
||
clean-pyc: ## clean python cache files | ||
find . -name '*.pyc' -exec rm -f {} + | ||
find . -name '*.pyo' -exec rm -f {} + | ||
find . -name '*~' -exec rm -f {} + | ||
find . -name '__pycache__' -exec rm -fr {} + | ||
find . -name '.pytest_cache' -exec rm -fr {} + | ||
|
||
clean-test: ## cleanup pytests leftovers | ||
rm -f .coverage | ||
rm -fr htmlcov/ | ||
rm -fr test_results/ | ||
rm -f *report.html | ||
rm -f log.html | ||
rm -f test-results.html | ||
rm -f output.xml | ||
|
||
test: clean ## Run pytest unit tests | ||
python3 -m pytest | ||
|
||
test-debug: ## Run unit tests with debugging enabled | ||
python3 -m pytest --pdb | ||
|
||
test-coverage: clean ## Run unit tests and check code coverage | ||
PYTHONPATH=src python3 -m pytest --cov=src tests/ --disable-warnings | ||
|
||
docker-up: ## Startup docker | ||
docker-compose --verbose up | ||
|
||
docker-build: ## Startup docker | ||
docker-compose --verbose up --build | ||
|
||
setup: requirements pre-commit-setup docker-build test-setup api-setup ## setup & run after downloaded repo | ||
|
||
pre-commit-setup: ## Install pre-commit | ||
python3 -m pip install pre-commit | ||
pre-commit --version | ||
|
||
pre-commit: ## Run pre-commit | ||
pre-commit run --all-files | ||
|
||
test-setup: | ||
python3 -m pip install pytest | ||
|
||
requirements: | ||
python3 -m pip install -r requirements.txt | ||
|
||
docker-down: | ||
docker-compose down | ||
|
||
docker-rebuild: docker-down | ||
docker-compose --verbose up --build | ||
|
||
docker-force-rebuild: | ||
docker-compose --verbose up --build --force-recreate | ||
|
||
api-setup: | ||
python3 -m pip install "fastapi[all]" | ||
|
||
env-setup: | ||
touch .env | ||
echo "KAFKA_HOST= 'localhost:9092'" >> .env | ||
echo "DATABASE_URL= 'mysql+aiomysql://root:root_bot_buster@localhost:3306/playerdata'" >> .env | ||
echo "ENV='DEV'" >> .env | ||
echo "POOL_RECYCLE='60'" >> .env | ||
echo "POOL_TIMEOUT='30'" >> .env | ||
|
||
docs: | ||
open http://localhost:5000/docs | ||
xdg-open http://localhost:5000/docs | ||
. http://localhost:5000/docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
import sys | ||
import requests | ||
from unittest import TestCase | ||
|
||
|
||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
|
||
|
||
class TestPlayerAPI(TestCase): | ||
|
||
def testValidPlayerReturns200(self): | ||
url = "http://localhost:5000/v2/players/score" | ||
params = {"name": ["Player1"]} | ||
score = requests.get(url, params) | ||
assert score.status_code == 200 | ||
|
||
def testInvalidPlayerReturns200(self): | ||
url = "http://localhost:5000/v2/players/score" | ||
params = {"name": [""]} | ||
response = requests.get(url, params) | ||
assert response.status_code == 200 | ||
|
||
def testInvalidPlayerBodyIsEmpty(self): | ||
url = "http://localhost:5000/v2/players/score" | ||
params = {"name": [""]} | ||
response = requests.get(url, params) | ||
error = f"Invalid response return type, expected list[dict]" | ||
print(response.json()) | ||
assert isinstance(response.json(), list), error |