You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the following TestSuite code, I get incorrect routing, and read/write operations are not correctly carried out on on the test 'mytestdatabase' specified in default DB's TEST settings. Instead:
write operations seem to be done fine (I cannot verify it via pgadmin, since the data is destroyed after every test is complete), but
read is done on the PRODUCTION DB
from django.test import TestCase
from DM.tests.factories.UserFactory import UserFactory
from DM.tests.factories.CaseFactory import CaseFactory
from users.models import User
from data.models import Case
import factory
class DATestSuite(TestCase):
databases = {
'default',
'read_replica',
}
@classmethod
def setUpTestData(cls):
cls.users = UserFactory.create_batch(50)
cls.cases = CaseFactory.create_batch(50)
def test_firstOne(self):
print(Case.objects.all())
print(User.objects.all())
self.assertQuerysetEqual(qs=Case.objects.all(), values=DATestSuite.cases, transform = lambda _: _)
import factory
from faker import Factory
import pytz
from DM.tests.factories.UserFactory import UserFactory
from data.models import Case
from users.models import User
faker = Factory.create()
class CaseFactory(factory.DjangoModelFactory):
class Meta:
model = Case
database = 'default'
user = factory.Iterator(User.objects.all())
uploaded_on = factory.LazyAttribute(lambda _: faker.date_time(tzinfo=pytz.timezone(faker.timezone())))
uuid_hex = factory.LazyAttribute(lambda _: faker.hexify(text="^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"))
upload_country = factory.LazyAttribute(lambda _: faker.country_code())
additional_info = faker.paragraph()
import factory
from faker import Factory
from django.contrib.auth.models import Group
faker = Factory.create()
class AuthGroupFactory(factory.DjangoModelFactory):
class Meta:
model = Group
django_get_or_create = ('name',)
name = factory.Iterator(["default_user", "different_user_1", "different_user_2", "different_user_3"])
permissions = None
As an effect, it becomes impossible to carry out any DB-based unit tests. I had to manually comment out the 'multidb.PinningReplicaRouter' in DATABASE_ROUTERS for Django's test suite to start working as intended.
Is that a known issue, and if so - are there any neat workarounds, or plans to have it fixed?
Here are my dependencies captured in requirements.txt:
Hi,
I have a project with the following database setup:
When using the following TestSuite code, I get incorrect routing, and read/write operations are not correctly carried out on on the test 'mytestdatabase' specified in default DB's TEST settings. Instead:
As an effect, it becomes impossible to carry out any DB-based unit tests. I had to manually comment out the 'multidb.PinningReplicaRouter' in DATABASE_ROUTERS for Django's test suite to start working as intended.
Is that a known issue, and if so - are there any neat workarounds, or plans to have it fixed?
Here are my dependencies captured in requirements.txt:
The text was updated successfully, but these errors were encountered: