Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test to check when django-simple-history not installed #113

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from __future__ import annotations

import sys
from unittest.mock import patch

import pytest
from django.conf import settings
from django.test import override_settings
from model_bakery import baker

pytestmark = pytest.mark.django_db
Expand Down Expand Up @@ -37,3 +42,21 @@ def test_save_without_history_method():
dummy.save_without_history()

assert dummy.history.count() == 1


@override_settings(
INSTALLED_APPS=[app for app in settings.INSTALLED_APPS if app != "simple_history"]
)
def test_without_simple_history():
if "django_twc_toolbox.models" in sys.modules:
del sys.modules["django_twc_toolbox.models"]

with patch("importlib.util.find_spec", return_value=None):
import django_twc_toolbox.models

assert not hasattr(django_twc_toolbox.models, "WithHistory")

assert hasattr(django_twc_toolbox.models, "TimeStamped")

if "django_twc_toolbox.models" in sys.modules:
del sys.modules["django_twc_toolbox.models"]