Remove multi-db tests to make them more reliable

Fixes #213
This commit is contained in:
Keith Bussell 2019-11-06 09:12:05 -08:00 committed by Jan-Jelle Kester
parent e138ee8855
commit 843495f669
4 changed files with 2 additions and 46 deletions

View file

@ -172,7 +172,7 @@ class ChoicesFieldModel(models.Model):
status = models.CharField(max_length=1, choices=STATUS_CHOICES)
multiselect = MultiSelectField(max_length=3, choices=STATUS_CHOICES, max_choices=3)
multiplechoice = models.CharField(max_length=3, choices=STATUS_CHOICES)
multiplechoice = models.CharField(max_length=255, choices=STATUS_CHOICES)
history = AuditlogHistoryField()

View file

@ -1,38 +0,0 @@
class PostgresRouter(object):
"""
A router to control all database operations on models for use with tests
pertaining to the postgres test database.
"""
def db_for_read(self, model, **hints):
"""
Attempts to read postgres models go to postgres db.
"""
if model._meta.model_name.startswith('postgres'):
return 'postgres'
return None
def db_for_write(self, model, **hints):
"""
Attempts to write postgres models go to postgres db.
"""
if model._meta.model_name.startswith('postgres'):
return 'postgres'
return None
def allow_relation(self, obj1, obj2, **hints):
"""
Allow relations if a model in the postgres app is involved.
"""
if obj1._meta.model_name.startswith('postgres') or \
obj2._meta.model_name.startswith('postgres'):
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
"""
Make sure the postgres app only appears in the 'postgres db'
database.
"""
if model_name and model_name.startswith('postgres'):
return db == 'postgres'
return None

View file

@ -35,14 +35,8 @@ if django.VERSION <= (1, 9):
else:
POSTGRES_DRIVER = 'django.db.backends.postgresql'
DATABASE_ROUTERS = ['auditlog_tests.router.PostgresRouter']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'auditlog_tests.db',
},
'postgres': {
'ENGINE': POSTGRES_DRIVER,
'NAME': 'auditlog_tests_db',
'USER': 'postgres',

View file

@ -584,7 +584,7 @@ class PostgresArrayFieldModelTest(TestCase):
@property
def latest_array_change(self):
return self.obj.history.using("postgres").latest().changes_display_dict["arrayfield"][1]
return self.obj.history.latest().changes_display_dict["arrayfield"][1]
def test_changes_display_dict_arrayfield(self):
self.assertTrue(self.latest_array_change == "Red, Green",