facing issue on unit test

19 views
Skip to first unread message

Arulselvam K

unread,
Aug 12, 2019, 11:35:00 PM8/12/19
to Django users
Have hosted the code @ "https://github.com/tbone230590/plib"
Here is the problem I have two models Book and IssuedBook, IssuedBook have foreign key relation to Book object.Those models are defined @ "/api/data/models" I have unit tests for testing those models and are available @ "/api/unit_tests/models".
I am able to test Book model successfully. But I have a test for IssuedBook model which is referring Book model is getting failed.
It seems cause of the problem is referring Book object created in BookTestCase that was previously run. But I dont understand that why Book record getting deleted after first testcase execution.
Could you educate me on this to solve the problem?

Vinicius Assef

unread,
Aug 13, 2019, 11:02:16 AM8/13/19
to django...@googlegroups.com
The database is cleared after each test method.

So, in a new testcase your database is empty.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cf28d61d-8582-4148-a14a-9349fdfcca8f%40googlegroups.com.

Arulselvam K

unread,
Sep 8, 2019, 10:37:45 PM9/8/19
to Django users
Thanks!, So for each test , do i need to add same test data? or do we have any other way not to repeat the same test data?


On Tuesday, 13 August 2019 20:32:16 UTC+5:30, Vinicius Assef wrote:
The database is cleared after each test method.

So, in a new testcase your database is empty.

On Tue, 13 Aug 2019 at 00:34, Arulselvam K <tbone...@gmail.com> wrote:
Have hosted the code @ "https://github.com/tbone230590/plib"
Here is the problem I have two models Book and IssuedBook, IssuedBook have foreign key relation to Book object.Those models are defined @ "/api/data/models" I have unit tests for testing those models and are available @ "/api/unit_tests/models".
I am able to test Book model successfully. But I have a test for IssuedBook model which is referring Book model is getting failed.
It seems cause of the problem is referring Book object created in BookTestCase that was previously run. But I dont understand that why Book record getting deleted after first testcase execution.
Could you educate me on this to solve the problem?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages