-
Notifications
You must be signed in to change notification settings - Fork 4
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 #4 from resulyrt93/release/0.1.2
Release/0.1.2
- Loading branch information
Showing
7 changed files
with
46 additions
and
37 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,5 +1,4 @@ | ||
name: Publish Python 🐍 distributions 📦 to PyPI | ||
|
||
name: Deploy | ||
on: | ||
push: | ||
tags: | ||
|
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
Empty file.
31 changes: 3 additions & 28 deletions
31
pytest_sqlalchemy_mock.py → pytest_sqlalchemy_mock/base.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
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,36 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import List, Tuple | ||
|
||
from sqlalchemy.orm import Session | ||
|
||
MOCK_CONFIG_TYPE = List[Tuple[str, List]] | ||
|
||
|
||
class ModelMocker: | ||
_base = None | ||
_mock_config: MOCK_CONFIG_TYPE = None | ||
|
||
def __init__(self, session: Session, base, mock_config: MOCK_CONFIG_TYPE): | ||
self._session: Session = session | ||
self._base = base | ||
self._mock_config = mock_config | ||
|
||
def get_model_class_with_table_name(self, table_name: str): | ||
for mapper in self._base.registry.mappers: | ||
cls = mapper.class_ | ||
if cls.__tablename__ == table_name: | ||
return cls | ||
|
||
def create_all(self): | ||
for model_config in self._mock_config: | ||
table_name, data = model_config | ||
model_class = self.get_model_class_with_table_name(table_name) | ||
if model_class: | ||
for datum in data: | ||
instance = model_class(**datum) | ||
self._session.add(instance) | ||
self._session.commit() |
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