diff --git a/auditlog/models.py b/auditlog/models.py index e03206f..a0029a1 100644 --- a/auditlog/models.py +++ b/auditlog/models.py @@ -384,7 +384,9 @@ class LogEntry(models.Model): additional_data = models.JSONField( blank=True, null=True, verbose_name=_("additional data") ) - actor_email = models.CharField(blank=True, null=True, max_length=254) + actor_email = models.CharField( + blank=True, null=True, max_length=254, verbose_name=_("actor email") + ) objects = LogEntryManager() diff --git a/auditlog_tests/manage.py b/auditlog_tests/manage.py index 48371db..230f53a 100644 --- a/auditlog_tests/manage.py +++ b/auditlog_tests/manage.py @@ -3,7 +3,7 @@ import os import sys if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "auditlog_tests.test_settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_settings") from django.core.management import execute_from_command_line diff --git a/auditlog_tests/templates/simplemodel_detail.html b/auditlog_tests/test_app/__init__.py similarity index 100% rename from auditlog_tests/templates/simplemodel_detail.html rename to auditlog_tests/test_app/__init__.py diff --git a/auditlog_tests/apps.py b/auditlog_tests/test_app/apps.py similarity index 72% rename from auditlog_tests/apps.py rename to auditlog_tests/test_app/apps.py index 2bcc080..d980d89 100644 --- a/auditlog_tests/apps.py +++ b/auditlog_tests/test_app/apps.py @@ -2,4 +2,4 @@ from django.apps import AppConfig class AuditlogTestConfig(AppConfig): - name = "auditlog_tests" + name = "test_app" diff --git a/auditlog_tests/fixtures/custom_get_cid.py b/auditlog_tests/test_app/fixtures/custom_get_cid.py similarity index 100% rename from auditlog_tests/fixtures/custom_get_cid.py rename to auditlog_tests/test_app/fixtures/custom_get_cid.py diff --git a/auditlog_tests/fixtures/m2m_test_fixture.json b/auditlog_tests/test_app/fixtures/m2m_test_fixture.json similarity index 56% rename from auditlog_tests/fixtures/m2m_test_fixture.json rename to auditlog_tests/test_app/fixtures/m2m_test_fixture.json index c5c5d9e..3c289fb 100644 --- a/auditlog_tests/fixtures/m2m_test_fixture.json +++ b/auditlog_tests/test_app/fixtures/m2m_test_fixture.json @@ -1,6 +1,6 @@ [ { - "model": "auditlog_tests.manyrelatedmodel", + "model": "test_app.manyrelatedmodel", "pk": 1, "fields": { "recursive": [1], @@ -8,7 +8,7 @@ } }, { - "model": "auditlog_tests.manyrelatedothermodel", + "model": "test_app.manyrelatedothermodel", "pk": 1, "fields": {} } diff --git a/auditlog_tests/models.py b/auditlog_tests/test_app/models.py similarity index 100% rename from auditlog_tests/models.py rename to auditlog_tests/test_app/models.py diff --git a/auditlog_tests/test_app/templates/simplemodel_detail.html b/auditlog_tests/test_app/templates/simplemodel_detail.html new file mode 100644 index 0000000..e69de29 diff --git a/auditlog_tests/urls.py b/auditlog_tests/test_app/urls.py similarity index 68% rename from auditlog_tests/urls.py rename to auditlog_tests/test_app/urls.py index 712071d..6c761bf 100644 --- a/auditlog_tests/urls.py +++ b/auditlog_tests/test_app/urls.py @@ -1,13 +1,13 @@ from django.contrib import admin from django.urls import path -from auditlog_tests.views import SimpleModelDetailview +from .views import SimpleModelDetailView urlpatterns = [ path("admin/", admin.site.urls), path( "simplemodel//", - SimpleModelDetailview.as_view(), + SimpleModelDetailView.as_view(), name="simplemodel-detail", ), ] diff --git a/auditlog_tests/views.py b/auditlog_tests/test_app/views.py similarity index 60% rename from auditlog_tests/views.py rename to auditlog_tests/test_app/views.py index 436ecbf..0346ccf 100644 --- a/auditlog_tests/views.py +++ b/auditlog_tests/test_app/views.py @@ -1,9 +1,10 @@ from django.views.generic import DetailView from auditlog.mixins import LogAccessMixin -from auditlog_tests.models import SimpleModel + +from .models import SimpleModel -class SimpleModelDetailview(LogAccessMixin, DetailView): +class SimpleModelDetailView(LogAccessMixin, DetailView): model = SimpleModel template_name = "simplemodel_detail.html" diff --git a/auditlog_tests/test_commands.py b/auditlog_tests/test_commands.py index a976759..5c446aa 100644 --- a/auditlog_tests/test_commands.py +++ b/auditlog_tests/test_commands.py @@ -7,8 +7,7 @@ from unittest import mock import freezegun from django.core.management import call_command from django.test import TestCase, TransactionTestCase - -from auditlog_tests.models import SimpleModel +from test_app.models import SimpleModel class AuditlogFlushTest(TestCase): diff --git a/auditlog_tests/test_settings.py b/auditlog_tests/test_settings.py index ba29ce7..f707a86 100644 --- a/auditlog_tests/test_settings.py +++ b/auditlog_tests/test_settings.py @@ -16,7 +16,7 @@ INSTALLED_APPS = [ "django.contrib.admin", "django.contrib.staticfiles", "auditlog", - "auditlog_tests", + "test_app", ] MIDDLEWARE = [ @@ -57,7 +57,7 @@ TEMPLATES = [ STATIC_URL = "/static/" -ROOT_URLCONF = "auditlog_tests.urls" +ROOT_URLCONF = "test_app.urls" USE_TZ = True diff --git a/auditlog_tests/test_two_step_json_migration.py b/auditlog_tests/test_two_step_json_migration.py index 7df115e..2c66bce 100644 --- a/auditlog_tests/test_two_step_json_migration.py +++ b/auditlog_tests/test_two_step_json_migration.py @@ -4,9 +4,9 @@ from unittest.mock import patch from django.core.management import CommandError, call_command from django.test import TestCase, override_settings +from test_app.models import SimpleModel from auditlog.models import LogEntry -from auditlog_tests.models import SimpleModel class TwoStepMigrationTest(TestCase): diff --git a/auditlog_tests/tests.py b/auditlog_tests/tests.py index f9bbcb6..c5c9fe8 100644 --- a/auditlog_tests/tests.py +++ b/auditlog_tests/tests.py @@ -26,17 +26,8 @@ from django.utils import dateformat, formats from django.utils import timezone as django_timezone from django.utils.encoding import smart_str from django.utils.translation import gettext_lazy as _ - -from auditlog.admin import LogEntryAdmin -from auditlog.cid import get_cid -from auditlog.context import disable_auditlog, set_actor -from auditlog.diff import model_instance_diff -from auditlog.middleware import AuditlogMiddleware -from auditlog.models import DEFAULT_OBJECT_REPR, LogEntry -from auditlog.registry import AuditlogModelRegistry, AuditLogRegistrationError, auditlog -from auditlog.signals import post_log, pre_log -from auditlog_tests.fixtures.custom_get_cid import get_cid as custom_get_cid -from auditlog_tests.models import ( +from test_app.fixtures.custom_get_cid import get_cid as custom_get_cid +from test_app.models import ( AdditionalDataIncludedModel, AltPrimaryKeyModel, AutoManyRelatedModel, @@ -68,6 +59,15 @@ from auditlog_tests.models import ( UUIDPrimaryKeyModel, ) +from auditlog.admin import LogEntryAdmin +from auditlog.cid import get_cid +from auditlog.context import disable_auditlog, set_actor +from auditlog.diff import model_instance_diff +from auditlog.middleware import AuditlogMiddleware +from auditlog.models import DEFAULT_OBJECT_REPR, LogEntry +from auditlog.registry import AuditlogModelRegistry, AuditLogRegistrationError, auditlog +from auditlog.signals import post_log, pre_log + class SimpleModelTest(TestCase): def setUp(self): @@ -631,9 +631,7 @@ class MiddlewareTest(TestCase): # these two tuples test using a custom getter. # Here, we don't necessarily care about the cid that was set in set_cid ( - { - "AUDITLOG_CID_GETTER": "auditlog_tests.fixtures.custom_get_cid.get_cid" - }, + {"AUDITLOG_CID_GETTER": "test_app.fixtures.custom_get_cid.get_cid"}, custom_get_cid(), ), ({"AUDITLOG_CID_GETTER": custom_get_cid}, custom_get_cid()), @@ -1254,15 +1252,12 @@ class RegisterModelSettingsTest(TestCase): # Exclude just one model self.assertTrue( SimpleExcludeModel - in self.test_auditlog._get_exclude_models( - ("auditlog_tests.SimpleExcludeModel",) - ) + in self.test_auditlog._get_exclude_models(("test_app.SimpleExcludeModel",)) ) # Exclude all model of an app self.assertTrue( - SimpleExcludeModel - in self.test_auditlog._get_exclude_models(("auditlog_tests",)) + SimpleExcludeModel in self.test_auditlog._get_exclude_models(("test_app",)) ) def test_register_models_no_models(self): @@ -1271,13 +1266,13 @@ class RegisterModelSettingsTest(TestCase): self.assertEqual(self.test_auditlog._registry, {}) def test_register_models_register_single_model(self): - self.test_auditlog._register_models(("auditlog_tests.SimpleExcludeModel",)) + self.test_auditlog._register_models(("test_app.SimpleExcludeModel",)) self.assertTrue(self.test_auditlog.contains(SimpleExcludeModel)) self.assertEqual(len(self.test_auditlog._registry), 1) def test_register_models_register_app(self): - self.test_auditlog._register_models(("auditlog_tests",)) + self.test_auditlog._register_models(("test_app",)) self.assertTrue(self.test_auditlog.contains(SimpleExcludeModel)) self.assertTrue(self.test_auditlog.contains(ChoicesFieldModel)) @@ -1287,7 +1282,7 @@ class RegisterModelSettingsTest(TestCase): self.test_auditlog._register_models( ( { - "model": "auditlog_tests.SimpleExcludeModel", + "model": "test_app.SimpleExcludeModel", "include_fields": ["label"], "exclude_fields": [ "text", @@ -1305,7 +1300,7 @@ class RegisterModelSettingsTest(TestCase): self.test_auditlog._register_models( ( { - "model": "auditlog_tests.ManyRelatedModel", + "model": "test_app.ManyRelatedModel", "m2m_fields": {"related"}, }, ) @@ -1427,7 +1422,7 @@ class RegisterModelSettingsTest(TestCase): @override_settings( AUDITLOG_INCLUDE_ALL_MODELS=True, - AUDITLOG_EXCLUDE_TRACKING_MODELS=("auditlog_tests.SimpleExcludeModel",), + AUDITLOG_EXCLUDE_TRACKING_MODELS=("test_app.SimpleExcludeModel",), ) def test_register_from_settings_register_all_models_with_exclude_models_tuple(self): self.test_auditlog.register_from_settings() @@ -1473,7 +1468,7 @@ class RegisterModelSettingsTest(TestCase): @override_settings( AUDITLOG_INCLUDE_ALL_MODELS=True, - AUDITLOG_EXCLUDE_TRACKING_MODELS=["auditlog_tests.SimpleExcludeModel"], + AUDITLOG_EXCLUDE_TRACKING_MODELS=["test_app.SimpleExcludeModel"], ) def test_register_from_settings_register_all_models_with_exclude_models_list(self): self.test_auditlog.register_from_settings() @@ -1484,7 +1479,7 @@ class RegisterModelSettingsTest(TestCase): @override_settings( AUDITLOG_INCLUDE_TRACKING_MODELS=( { - "model": "auditlog_tests.SimpleExcludeModel", + "model": "test_app.SimpleExcludeModel", "include_fields": ["label"], "exclude_fields": [ "text", @@ -2818,7 +2813,9 @@ class DisableTest(TestCase): This only works with context manager """ with disable_auditlog(): - management.call_command("loaddata", "m2m_test_fixture.json", verbosity=0) + management.call_command( + "loaddata", "test_app/fixtures/m2m_test_fixture.json", verbosity=0 + ) recursive = ManyRelatedModel.objects.get(pk=1) self.assertEqual(0, LogEntry.objects.get_for_object(recursive).count()) related = ManyRelatedOtherModel.objects.get(pk=1) diff --git a/docs/source/conf.py b/docs/source/conf.py index f6689fa..e2c5de6 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -19,10 +19,11 @@ from auditlog import __version__ # documentation root, use os.path.abspath to make it absolute, like shown here. # Add sources folder -sys.path.insert(0, os.path.abspath("../../")) + +sys.path.insert(0, os.path.abspath("../../auditlog_tests")) # Setup Django for autodoc -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "auditlog_tests.test_settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_settings") import django # noqa: E402 django.setup() diff --git a/runtests.py b/runtests.py deleted file mode 100644 index dea36f6..0000000 --- a/runtests.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python -import os -import sys - -import django -from django.conf import settings -from django.test.utils import get_runner - -if __name__ == "__main__": - os.environ["DJANGO_SETTINGS_MODULE"] = "auditlog_tests.test_settings" - django.setup() - TestRunner = get_runner(settings) - test_runner = TestRunner() - failures = test_runner.run_tests(["auditlog_tests"]) - sys.exit(bool(failures)) diff --git a/tox.ini b/tox.ini index fbb6149..cbcb695 100644 --- a/tox.ini +++ b/tox.ini @@ -6,12 +6,14 @@ envlist = {py312,py313}-djangomain py39-docs py39-lint + py39-checkmigrations [testenv] setenv = COVERAGE_FILE={toxworkdir}/.coverage.{envname} +changedir = auditlog_tests commands = - coverage run --source auditlog runtests.py + coverage run --source auditlog ./manage.py test coverage xml deps = django42: Django>=4.2,<4.3 @@ -47,6 +49,15 @@ deps = pre-commit commands = pre-commit run --all-files +[testenv:py39-checkmigrations] +description = Check for missing migrations +changedir = auditlog_tests +deps = + Django>=4.2 + psycopg2 +commands = + python manage.py makemigrations --check --dry-run + [gh-actions] python = 3.9: py39