Skip to content

Commit

Permalink
Merge pull request #28 from akai-org/backend
Browse files Browse the repository at this point in the history
Backend - websockets + unit testing for websockets
  • Loading branch information
siemieniuk authored Dec 18, 2023
2 parents d6fd929 + 74e622f commit 92a5b8f
Show file tree
Hide file tree
Showing 20 changed files with 607 additions and 50 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ To run the project, type
docker-compose up
```

## Run tests on backend

Make sure you have installed PyTest.

To run tests on the backend, being on `project root directory`, type
```bash
python3 -m pytest
```

To run coverage tests, after installing `coverage` package and being on
`project root directory`, type
```bash
coverage run -m pytest
```

Ports:
- frontend: 3000
- backend: 8000
4 changes: 4 additions & 0 deletions backend/.isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[settings]
known_first_party = ["src"]
line_length = 79
profile = "black"
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ COPY requirements.txt ./requirements.txt

RUN pip install --no-cache-dir --upgrade -r requirements.txt

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
3 changes: 3 additions & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.isort]
py_version=311
line-length=79
2 changes: 2 additions & 0 deletions backend/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
execution_timeout = 2.0
3 changes: 3 additions & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ anyio==3.7.1
click==8.1.7
fastapi==0.104.1
h11==0.14.0
httpx==0.25.2
idna==3.4
pydantic==2.5.1
pydantic_core==2.14.3
pytest==7.4.3
pytest-timeouts==1.2.1
sniffio==1.3.0
starlette==0.27.0
typing_extensions==4.8.0
Expand Down
Empty file added backend/src/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions backend/src/custom_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from enum import Enum


class GameStatus(Enum):
NOT_STARTED = 0
STARTED = 1
TERMINATED = 2

def __str__(self):
return str(self.name).lower()
9 changes: 9 additions & 0 deletions backend/src/dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from src.game_manager import GameManager


async def get_manager() -> GameManager:
try:
yield get_manager.manager
except AttributeError:
get_manager.manager = GameManager()
yield get_manager.manager
Loading

0 comments on commit 92a5b8f

Please sign in to comment.