I add django simple history to project and it stores history fine, but now my unit test stopped working.
Without module 'simple_history.middleware.HistoryRequestMiddleware' it works but i cant make it work with this module. I know it stores who change the model etc.
and tests looks like this:
@classmethod
def setUpClass(cls):
cls.beneficiary = Beneficiary.objects.create(
b_id='AK1234',
first_name='Test',
middle_name='Test',
last_name='Test',
date_of_birth=datetime(1990, 6, 1),
gender='0'
)
@classmethod
def tearDownClass(cls):
super(TestSomeForm, cls).tearDownClass()
cls.beneficiary.delete()
ProjectUser.objects.all().delete()
def test_some_form(self):
client = Client()
ProjectUser.objects.create_superuser('test@example.com', 'test', 'Test', 'Test', 'test')
self.assertTrue(client.login(username='test', password='test'))
In setupclass i create the beneficiary and in teardown i try to delete it but then i will get an error:
IntegrityError: insert or update on table "beneficiary_historicalbeneficiary" violates foreign key constraint "beneficiar_history_user_id_15f861b_fk_project_projectuser_id"
DETAIL: Key (history_user_id)=(e1215b2f-9f33) is not present in table "project_projectuser".
How can i fix those tests? I tried to move create_superuser to setup but it didn't work
Aucun commentaire:
Enregistrer un commentaire