@pytest.fixture
def db_with_obj(db):
factories.MyModelFactory()
@pytest.mark.asyncio
async def test_something(db_with_obj
):
print(models.MyModelFactory
.objects.all())
obj = models.MyModelFactory
.objects.first()
communicator = WebsocketCommunicator(MyConsumer, 'ws/')
connected, subprotocol = await communicator.connect()
assert connected
await communicator.send_to(text_data=json.dumps({
'id': obj.pk,
'content': 'my content',
}))
response = await communicator.receive_from()
assert response == 'my content'
await communicator.disconnect()
class MyConsumer(WebsocketConsumer):
def receive(self, text_data=None, bytes_data=None):
print(models.MyModel.objects.all())
# ...
--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7e5f63f4-789c-413e-a8d2-fcf8ea62a2cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
def test_fixture(db_with_segment, admin_client):
assert models.MyModel.objects.count() == 1
response = admin_client.get('/api/my_model/list/')
assert len(response.json()['results']) == 1
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/464c465b-8b24-4061-977d-a44b4868fc84%40googlegroups.com.