-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* DQB-28 Created command to choose from menu Command can choose first item on the menu or a random item * DQB-28 Introduce more of select command Replace command args with flag converter * DQB-28 Clean up select command code and create tests for controller Add pytest-mock to pyproject.toml to support rare cases of needing to patch code. * DQB-28 Upgrade python packages Run poetry upgrade to upgrade existing installed packages * DQB-28 Update tests to use factory boy and introduce factories Install factoryboy into pyproject.toml, and update ruff rules accordingly. Installed and implemented factory boy through out tests * DQB-28 Delete broken factory Maybe clause in factory was not working. will come back to this
- Loading branch information
Showing
16 changed files
with
693 additions
and
374 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -47,6 +47,10 @@ module = "sqlalchemy.*" | |
ignore_missing_imports = true | ||
module = "furl" | ||
|
||
[[tool.mypy.overrides]] | ||
ignore_missing_imports = true | ||
module = "factory.*" | ||
|
||
[tool.poetry] | ||
authors = ["jplhanna <[email protected]>"] | ||
description = "Discord bot for tracking and rewarding tasks" | ||
|
@@ -73,6 +77,7 @@ typing-extensions = "^4.9.0" | |
bandit = {extras = ["toml"], version = "^1.7.4"} | ||
black = "*" | ||
coverage = {extras = ["toml"], version = "^6.4.4"} | ||
factory-boy = "^3.3.0" | ||
faker = "*" | ||
flake8-pytest-style = "^1.6.0" | ||
mypy = "*" | ||
|
@@ -81,6 +86,8 @@ pytest = "<=7.4.4" | |
pytest-async-sqlalchemy = "*" | ||
pytest-asyncio = "*" | ||
pytest-cov = "*" | ||
pytest-factoryboy = "^2.7.0" | ||
pytest-mock = "^3.12.0" | ||
pytest-randomly = "*" | ||
ruff = "^0.2.0" | ||
|
||
|
@@ -132,4 +139,5 @@ lines-between-types = 1 | |
max-complexity = 10 | ||
|
||
[tool.ruff.lint.per-file-ignores] | ||
"src/helpers/factories/*" = ["FBT001"] | ||
"src/model_hub.py" = ["F401"] |
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
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,10 @@ | ||
import inspect | ||
import sys | ||
|
||
from .base_factories import BaseFactory | ||
from .quest_factories import * # noqa: F403 | ||
from .tavern_factories import * # noqa: F403 | ||
from .user_factories import * # noqa: F403 | ||
|
||
fact_classes = inspect.getmembers(sys.modules[__name__], lambda x: inspect.isclass(x) and issubclass(x, BaseFactory)) | ||
factory_classes = [cls for cls_name, cls in fact_classes if cls_name != "BaseFactory"] |
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,15 @@ | ||
from factory.alchemy import SQLAlchemyModelFactory | ||
from sqlalchemy.orm import scoped_session | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
from src.config import DBSettings | ||
|
||
db_settings = DBSettings() | ||
|
||
test_session = scoped_session(sessionmaker()) | ||
|
||
|
||
class BaseFactory(SQLAlchemyModelFactory): | ||
class Meta: | ||
abstract = True | ||
sqlalchemy_session = test_session |
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,47 @@ | ||
from typing import Any | ||
|
||
import factory | ||
|
||
from pytest_factoryboy import register | ||
|
||
from src.helpers.factories.base_factories import BaseFactory | ||
from src.helpers.factories.user_factories import UserFactory | ||
from src.quests import ExperienceTransaction | ||
from src.quests import Quest | ||
from src.quests import UserQuest | ||
|
||
|
||
@register | ||
class QuestFactory(BaseFactory): | ||
id = factory.Sequence(lambda n: n + 1) | ||
|
||
class Meta: | ||
model = Quest | ||
|
||
name = "Test Quest" | ||
experience = 100 | ||
|
||
|
||
@register | ||
class UserQuestFactory(BaseFactory): | ||
class Meta: | ||
model = UserQuest | ||
|
||
date_completed = factory.Maybe("is_completed", yes_declaration=factory.Faker("date_between", start_date="-10d")) | ||
|
||
user = factory.SubFactory(UserFactory) | ||
quest = factory.SubFactory(QuestFactory) | ||
|
||
@factory.post_generation | ||
def append_to_quests(self, _create: bool, _extracted: Any, **_kwargs: Any) -> None: | ||
self.user.quests.append(self.quest) | ||
|
||
|
||
@register | ||
class ExperienceTransactionFactory(BaseFactory): | ||
class Meta: | ||
model = ExperienceTransaction | ||
|
||
quest = factory.SubFactory(QuestFactory) | ||
experience = factory.SelfAttribute("quest.experience") | ||
user = factory.SubFactory(UserFactory) |
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,30 @@ | ||
from unittest.mock import sentinel | ||
|
||
import factory | ||
|
||
from pytest_factoryboy import register | ||
|
||
from src.constants import DayOfWeek | ||
from src.helpers.factories.base_factories import BaseFactory | ||
from src.tavern import Menu | ||
from src.tavern.models import MenuItem | ||
|
||
|
||
@register | ||
class MenuItemFactory(BaseFactory): | ||
class Meta: | ||
model = MenuItem | ||
|
||
food = factory.Sequence(lambda n: f"Test Food {n}") | ||
day_of_the_week = factory.Iterator(DayOfWeek) | ||
menu = None | ||
|
||
|
||
@register | ||
class MenuFactory(BaseFactory): | ||
class Meta: | ||
model = Menu | ||
|
||
server_id = sentinel.guild_id | ||
start_date = factory.Faker("date_object") | ||
items = factory.RelatedFactoryList(MenuItemFactory, factory_related_name="menu") |
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,16 @@ | ||
import factory | ||
|
||
from pytest_factoryboy import register | ||
|
||
from src.helpers.factories.base_factories import BaseFactory | ||
from src.models import User | ||
|
||
|
||
@register | ||
class UserFactory(BaseFactory): | ||
id = factory.Sequence(lambda n: n + 1) | ||
|
||
class Meta: | ||
model = User | ||
|
||
discord_id = factory.Faker("random_number", digits=10) |
Oops, something went wrong.