Fake data generated inside tests is not accessible inside the consumer #1743
Unanswered
Amohammadi2
asked this question in
Help!
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone. I want to write unittests for my consumers but I'm having problem with "Generating Fake Data". I'm using
factory_boy
andfaker
packages to provide fake data to my unit tests (you can findpip freeze
output at the end of the issue)Senario
Please consider the consumer below:
And here is the unit test code I've written:
As you can see, I'm printing out the contents of database in 3 different sections of code:
setUp
method in theTestPersonalChatRoomConsumer
classtest_personal_chat_room_connection
method in theTestPersonalChatRoomConsumer
classconnect
method of the consumerWhat I expected.
I expected all the print statements to print out identical results but ...
What actually happened
As you can see, the queryset inside the consumer is empty even though It's supposed to contain the same data as the unit tests.
How to reproduce
It is really simple:
2. create a simple model
3. create a consumer
4. create a test case
5. create a model instance inside the test case
6. try to access it inside the consumer and you will be surprised with an empty queryset
Extra info
OS
: windows 10 64 bitspython manage.py test
command3.8.10
pip freeze output
Beta Was this translation helpful? Give feedback.
All reactions