Skip to content

Commit

Permalink
Merge pull request #18 from 2jun0/GDET-32
Browse files Browse the repository at this point in the history
GDET-32: 스크래퍼 자동 테스트 추가
  • Loading branch information
2jun0 authored Jan 25, 2024
2 parents b793b5d + f3628ca commit 4ba08db
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 6 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/test-scraper.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Test scraper

on:
pull_request:
branches: [main]
push:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest
env:
working-directory: ./data_scrapers

steps:
- uses: actions/checkout@v3

- name: setup python
uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.6.1

- name: setup a local virtual environment
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- uses: actions/cache@v3
name: Define a cache for the virtual environment based on the dependencies lock file
with:
path: ${{env.working-directory}}/.venv
key: venv-${{ hashFiles('poetry.lock') }}

- name: install the project dependencies
run: poetry install
working-directory: ${{env.working-directory}}

- name: test app
run: poetry run python -m pytest tests -c pytest.ini
working-directory: ${{env.working-directory}}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# mac
.DS_Store
1 change: 1 addition & 0 deletions data_scrapers/test.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=sqlite://
5 changes: 3 additions & 2 deletions data_scrapers/tests/private/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
import pytest
from sqlalchemy.orm import Session

from tests.private.database import drop_tables, engine, init_database
from tests.private.database import create_tables, drop_tables, engine, init_database


@pytest.fixture(autouse=True)
def database():
init_database()
create_tables()
yield
drop_tables()
engine.dispose()


@pytest.fixture
def session() -> Generator[Session, Any, None]:
with Session(engine) as session:
yield session
session.rollback()
7 changes: 6 additions & 1 deletion data_scrapers/tests/private/database.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from sqlalchemy import Table, create_engine
from sqlalchemy_utils import create_database, database_exists

import private.game.model # noqa: F401
import private.genre.model # noqa: F401
import private.screenshot.model # noqa: F401
from private.config import setting
from private.model import Base

Expand All @@ -15,8 +18,10 @@ def init_database():
if not database_exists(setting.DATABASE_URL):
create_database(setting.DATABASE_URL)


def create_tables():
Base.metadata.create_all(engine, get_tables(), checkfirst=True)


def drop_tables():
Base.metadata.drop_all(engine)
Base.metadata.drop_all(engine, get_tables())
7 changes: 4 additions & 3 deletions data_scrapers/tests/public/utils/mock_steam_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@


class MockSteamAPI(SteamAPI):
games: dict[int, dict] = {}
genres: list[str] = []
screenshots: dict[int, list[dict]] = {}
def __init__(self) -> None:
self.games: dict[int, dict] = {}
self.genres: list[str] = []
self.screenshots: dict[int, list[dict]] = {}

def prepare_mock_data(
self, *, genre_size=MOCK_GENRE_SIZE, game_size=MOCK_GAME_SIZE, screenshot_size=MOCK_SCREENSHOT_SIZE
Expand Down

0 comments on commit 4ba08db

Please sign in to comment.