Skip to content

Commit

Permalink
working mvp now
Browse files Browse the repository at this point in the history
  • Loading branch information
extreme4all committed Aug 18, 2024
1 parent 6dc1104 commit 8022e02
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 76 deletions.
44 changes: 3 additions & 41 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,9 @@ for line in sys.stdin:
endef
export PRINT_HELP_PYSCRIPT

export ENV=DEV
export DATABASE_URL=mysql+aiomysql://root:root_bot_buster@localhost/playerdata
export KAFKA_HOST=localhost:9094
export POOL_RECYCLE=60
export POOL_TIMEOUT=30

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

docker-restart: ## restart containers
docker compose down
docker compose up --build -d
Expand All @@ -47,30 +25,14 @@ docker-test: docker-restart ## restart containers & test
docker-test-verbose: docker-restart ## restart containers & test
pytest -s

pre-commit-setup: ## Install pre-commit
python3 -m pip install pre-commit
pre-commit --version

test-setup: ## installs pytest singular package for local testing
python3 -m pip install pytest
python3 -m pip install requests
python3 -m pip install hypothesis
python3 -m pip install pytest-asyncio

requirements: ## installs all requirements
python3 -m pip install -r requirements.txt
python3 -m pip install ruff

python3 -m pip install -r requirements-dev.txt
create-env: ## create .env file
echo "ENV=DEV" > .env
echo "DATABASE_URL=mysql+aiomysql://root:root_bot_buster@localhost/playerdata" >> .env
echo "KAFKA_HOST=localhost:9094" >> .env
echo "POOL_RECYCLE=60" >> .env
echo "POOL_TIMEOUT=30" >> .env

setup: create-env pre-commit-setup test-setup requirements ## setup requirements

docs: ## opens your browser to the webapps testing docs
open http://localhost:5000/docs
xdg-open http://localhost:5000/docs
. http://localhost:5000/docs
setup: create-env requirements ## create env & install requirements
47 changes: 29 additions & 18 deletions mysql/docker-entrypoint-initdb.d/01_tables.sql
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
USE playerdata;

CREATE TABLE Players (
id INT PRIMARY KEY AUTO_INCREMENT,
name TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP,
possible_ban BOOLEAN,
confirmed_ban BOOLEAN,
confirmed_player BOOLEAN,
label_id INTEGER,
label_jagex INTEGER,
ironman BOOLEAN,
hardcore_ironman BOOLEAN,
ultimate_ironman BOOLEAN,
normalized_name TEXT
);
-- playerdata.Players definition-- playerdata.Labels definition

CREATE TABLE Labels (
id int NOT NULL AUTO_INCREMENT,
label varchar(50) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY Unique_label (label) USING BTREE
)
;
UNIQUE KEY Unique_label (label)
);

INSERT INTO `Labels` (id, label) VALUES (0, "UNKOWN");

CREATE TABLE Players (
id int NOT NULL AUTO_INCREMENT,
name text NOT NULL,
created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at datetime DEFAULT NULL,
possible_ban tinyint(1) NOT NULL DEFAULT '0',
confirmed_ban tinyint(1) NOT NULL DEFAULT '0',
confirmed_player tinyint(1) NOT NULL DEFAULT '0',
label_id int NOT NULL DEFAULT '0',
label_jagex int NOT NULL DEFAULT '0',
ironman tinyint DEFAULT NULL,
hardcore_ironman tinyint DEFAULT NULL,
ultimate_ironman tinyint DEFAULT NULL,
normalized_name text,
PRIMARY KEY (id),
UNIQUE KEY Unique_name (name (50)),
KEY FK_label_id (label_id),
KEY confirmed_ban_idx (confirmed_ban),
KEY normal_name_index (normalized_name (50)),
KEY Players_label_jagex_IDX (label_jagex),
KEY Players_possible_ban_IDX (possible_ban, confirmed_ban),
CONSTRAINT FK_label_id FOREIGN KEY (label_id) REFERENCES Labels (id) ON DELETE RESTRICT ON UPDATE RESTRICT
);
5 changes: 5 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pytest==8.3.2
pytest-asyncio==0.23.8
pytest-dependency==0.6.0
ruff==0.6.1
httpx==0.27.0
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ pydantic==2.8.2
pydantic-settings==2.4.0
pydantic_core==2.20.1
PyMySQL==1.1.1
pytest==8.3.2
pytest-asyncio==0.23.8
python-dotenv==1.0.1
ruff==0.6.1
SQLAlchemy==2.0.32
tomli==2.0.1
typing_extensions==4.12.2
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from contextlib import asynccontextmanager

import pytest
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker
Expand Down Expand Up @@ -27,6 +29,7 @@ async def setup_database():


@pytest.fixture(scope="function")
@asynccontextmanager
async def session(setup_database):
"""
Provide a new session for each test function.
Expand Down
File renamed without changes.
29 changes: 15 additions & 14 deletions tests/test_player_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@

@pytest.mark.asyncio
async def test_create_player(session: AsyncSession):
player_repository = PlayerRepository(db_session=session)
player_create = PlayerCreate(
name="Test_Player",
possible_ban=False,
confirmed_ban=False,
confirmed_player=True,
label_id=1,
label_jagex=2,
ironman=False,
hardcore_ironman=False,
ultimate_ironman=False,
normalized_name="test player",
)
async with session as db_session:
player_repository = PlayerRepository(db_session=db_session)
player_create = PlayerCreate(
name="Test_Player",
possible_ban=False,
confirmed_ban=False,
confirmed_player=True,
label_id=0,
label_jagex=2,
ironman=False,
hardcore_ironman=False,
ultimate_ironman=False,
normalized_name="test player",
)

await player_repository.create(player_create)
await player_repository.create(player_create)

0 comments on commit 8022e02

Please sign in to comment.