-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from Ivareh/226-update-the-pytests-backend-to…
…-the-new-backend-setup 226 update the pytests backend to the new backend setup
Showing
8 changed files
with
234 additions
and
83 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
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
44 changes: 44 additions & 0 deletions
44
src/backend_api/app/app/tests/crud/crud_models/test_stash.py
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,44 @@ | ||
from typing import Callable, Dict, Tuple, List, Union | ||
import pytest | ||
|
||
from app.crud import ( | ||
CRUD_stash, | ||
CRUD_account, | ||
) | ||
from app.core.models.models import Stash, Account | ||
from app.crud.base import CRUDBase | ||
import app.tests.crud.cascade_tests as cascade_test | ||
from app.tests.utils.model_utils.stash import generate_random_stash | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def object_generator_func() -> Callable[[], Dict]: | ||
return generate_random_stash | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def object_generator_func_w_deps() -> ( | ||
Callable[[], Tuple[Dict, Stash, List[Union[Dict, Account]]]] | ||
): | ||
def generate_random_stash_w_deps( | ||
db, | ||
) -> Callable[[], Tuple[Dict, Stash, List[Union[Dict, Account]]]]: | ||
return generate_random_stash(db, retrieve_dependencies=True) | ||
|
||
return generate_random_stash_w_deps | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def crud_instance() -> CRUDBase: | ||
return CRUD_stash | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def crud_deps_instances() -> CRUDBase: | ||
return [ | ||
CRUD_account, | ||
] | ||
|
||
|
||
class TestStashCRUD(cascade_test.TestCascade): | ||
pass |
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,52 @@ | ||
import asyncio | ||
from typing import Dict, List, Optional, Tuple, Union | ||
from sqlalchemy.orm import Session | ||
|
||
from app import crud | ||
from app.tests.conftest import db | ||
from app.core.models.models import Account, Stash | ||
from app.core.schemas.stash import StashCreate | ||
from app.tests.utils.utils import random_lower_string, random_bool | ||
from app.tests.utils.model_utils.account import generate_random_account | ||
|
||
|
||
async def create_random_stash_dict( | ||
db: Session, retrieve_dependencies: Optional[bool] = False | ||
) -> Union[Dict, Tuple[Dict, List[Union[Dict, Account]]]]: | ||
stashId = random_lower_string() | ||
public: bool = random_bool() | ||
league = random_lower_string() | ||
|
||
account_dict, account = await generate_random_account(db) | ||
accountName = account.accountName | ||
|
||
stash = { | ||
"stashId": stashId, | ||
"accountName": accountName, | ||
"public": public, | ||
"league": league, | ||
} | ||
|
||
if not retrieve_dependencies: | ||
return stash | ||
else: | ||
deps = [] | ||
deps += [account_dict, account] | ||
return stash, deps | ||
|
||
|
||
async def generate_random_stash( | ||
db: Session, retrieve_dependencies: Optional[bool] = False | ||
) -> Tuple[Dict, Stash, Optional[List[Union[Dict, Account]]]]: | ||
output = await create_random_stash_dict(db, retrieve_dependencies) | ||
if not retrieve_dependencies: | ||
stash_dict = output | ||
else: | ||
stash_dict, deps = output | ||
stash_create = StashCreate(**stash_dict) | ||
stash = await crud.CRUD_stash.create(db, obj_in=stash_create) | ||
|
||
if not retrieve_dependencies: | ||
return stash_dict, stash | ||
else: | ||
return stash_dict, stash, deps |