How to use the djangochannelsrestframework.mixins.CreateModelMixin function in djangochannelsrestframework

To help you get started, we’ve selected a few djangochannelsrestframework examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hishnash / djangochannelsrestframework / tests / test_generic_consumer.py View on Github external
async def test_create_mixin_consumer():

    class UserSerializer(serializers.ModelSerializer):
        class Meta:
            model = get_user_model()
            fields = ('id', 'username', 'email',)

    class AConsumer(CreateModelMixin, GenericAsyncAPIConsumer):
        queryset = get_user_model().objects.all()
        serializer_class = UserSerializer

    assert not get_user_model().objects.all().exists()

    # Test a normal connection
    communicator = WebsocketCommunicator(AConsumer, "/testws/")
    connected, _ = await communicator.connect()
    assert connected

    await communicator.send_json_to(
        {
            "action": "create",
            "data": {
                "username": "test101",
                "email": "42@example.com"