django-axes/axes/tests/test_models.py
Aleksi Häkli 40a0eae647
Improve tests
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-12 23:22:52 +02:00

43 lines
1.3 KiB
Python

from django.apps.registry import apps
from django.db import connection
from django.db.migrations.autodetector import MigrationAutodetector
from django.db.migrations.executor import MigrationExecutor
from django.db.migrations.state import ProjectState
from django.test import TestCase
from axes.models import AccessAttempt, AccessLog
class ModelsTestCase(TestCase):
def setUp(self):
self.failures_since_start = 42
self.access_attempt = AccessAttempt(
failures_since_start=self.failures_since_start,
)
self.access_log = AccessLog()
def test_access_attempt_str(self):
self.assertIn('Access', str(self.access_attempt))
def test_access_attempt_failures(self):
self.assertEqual(
self.access_attempt.failures,
self.failures_since_start,
)
def test_access_log_str(self):
self.assertIn('Access', str(self.access_log))
class MigrationsTestCase(TestCase):
def test_missing_migrations(self):
executor = MigrationExecutor(connection)
autodetector = MigrationAutodetector(
executor.loader.project_state(),
ProjectState.from_apps(apps),
)
changes = autodetector.changes(graph=executor.loader.graph)
self.assertEqual({}, changes)