Skip to content

Commit

Permalink
Merge pull request #42 from hishnash/channels-3
Browse files Browse the repository at this point in the history
Update to handle the new single callable async methods channels3
  • Loading branch information
hishnash authored Nov 12, 2020
2 parents 8aeba10 + d01b509 commit 61369b4
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
python:
- 3.8
django:
- Django==2.2
- Django==3.0.4
- Django==3.1.3
steps:
- uses: actions/checkout@v1
- name: Set up Python
Expand Down
2 changes: 1 addition & 1 deletion djangochannelsrestframework/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.2"
__version__ = "0.2.0"
4 changes: 2 additions & 2 deletions djangochannelsrestframework/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def get_view_args(self, action: str, **kwargs):
def view_as_consumer(
wrapped_view: typing.Callable[[HttpRequest], HttpResponse],
mapped_actions: typing.Optional[typing.Dict[str, str]] = None,
) -> Type[AsyncConsumer]:
) -> DjangoViewAsConsumer:
"""
Wrap a django View so that it will be triggered by actions over this json
websocket consumer.
Expand All @@ -286,4 +286,4 @@ class DjangoViewWrapper(DjangoViewAsConsumer):
view = wrapped_view
actions = mapped_actions

return DjangoViewWrapper
return DjangoViewWrapper()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
django>=3.0
djangorestframework>=3
channels>=2.1.1,<3.0
channels>=3.0
pytest
pytest-asyncio
pytest-django
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="djangochannelsrestframework",
version="0.1.2",
version="0.2.0",
url="https://github.com/hishnash/djangochannelsrestframework",
author="Matthaus Woolard",
author_email="[email protected]",
Expand All @@ -11,7 +11,7 @@
license="MIT",
packages=find_packages(exclude=["tests"]),
include_package_data=True,
install_requires=["Django>=3.*", "channels>=2.1.1,<3.0", "djangorestframework>=3.0"],
install_requires=["Django>=3.*", "channels>=3.0", "djangorestframework>=3.0"],
extras_require={
"tests": [
"pytest~=5.4.0",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_sync_action(self, pk=None, **kwargs):
return {"pk": pk, "sync": True}, 200

# Test a normal connection
communicator = WebsocketCommunicator(AConsumer, "/testws/")
communicator = WebsocketCommunicator(AConsumer(), "/testws/")

connected, _ = await communicator.connect()

Expand Down
16 changes: 8 additions & 8 deletions tests/test_generic_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_sync_action(self, pk=None, **kwargs):
return s.data, 200

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

Expand Down Expand Up @@ -68,7 +68,7 @@ def test_sync_action(self, pk=None, **kwargs):

await communicator.disconnect()

communicator = WebsocketCommunicator(AConsumer, "/testws/")
communicator = WebsocketCommunicator(AConsumer(), "/testws/")
connected, _ = await communicator.connect()

assert connected
Expand Down Expand Up @@ -109,7 +109,7 @@ class AConsumer(CreateModelMixin, GenericAsyncAPIConsumer):
assert not await database_sync_to_async(get_user_model().objects.all().exists)()

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

Expand Down Expand Up @@ -155,7 +155,7 @@ class AConsumer(ListModelMixin, GenericAsyncAPIConsumer):
assert not await database_sync_to_async(get_user_model().objects.all().exists)()

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

Expand Down Expand Up @@ -213,7 +213,7 @@ class AConsumer(RetrieveModelMixin, GenericAsyncAPIConsumer):
assert not await database_sync_to_async(get_user_model().objects.all().exists)()

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

Expand Down Expand Up @@ -286,7 +286,7 @@ class AConsumer(UpdateModelMixin, GenericAsyncAPIConsumer):
assert not await database_sync_to_async(get_user_model().objects.all().exists)()

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

Expand Down Expand Up @@ -359,7 +359,7 @@ class AConsumer(PatchModelMixin, GenericAsyncAPIConsumer):
assert not await database_sync_to_async(get_user_model().objects.all().exists)()

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

Expand Down Expand Up @@ -432,7 +432,7 @@ class AConsumer(DeleteModelMixin, GenericAsyncAPIConsumer):
assert not await database_sync_to_async(get_user_model().objects.all().exists)()

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

Expand Down
8 changes: 4 additions & 4 deletions tests/test_model_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def update_username(self, pk=None, username=None, **kwargs):
assert not await database_sync_to_async(get_user_model().objects.all().exists)()

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

Expand Down Expand Up @@ -216,12 +216,12 @@ async def update_username(self, pk=None, name=None, **kwargs):
assert not await database_sync_to_async(get_user_model().objects.all().exists)()

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

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

Expand Down Expand Up @@ -301,7 +301,7 @@ async def update_username(self, pk=None, username=None, **kwargs):
assert not await database_sync_to_async(get_user_model().objects.all().exists)()

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

Expand Down
21 changes: 10 additions & 11 deletions tests/test_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from asgiref.sync import async_to_sync
from channels import DEFAULT_CHANNEL_LAYER
from channels.db import database_sync_to_async
from channels.generic.websocket import AsyncJsonWebsocketConsumer
from channels.layers import channel_layers
from channels.testing import WebsocketCommunicator
from django.contrib.auth import user_logged_in, get_user_model
Expand Down Expand Up @@ -36,7 +35,7 @@ async def accept(self):
async def handle_user_logged_in(self, *args, observer=None, **kwargs):
await self.send_json({"message": kwargs, "observer": observer is not None})

communicator = WebsocketCommunicator(TestConsumer, "/testws/")
communicator = WebsocketCommunicator(TestConsumer(), "/testws/")

connected, _ = await communicator.connect()

Expand Down Expand Up @@ -78,7 +77,7 @@ async def accept(self, **kwargs):
async def user_change_observer_wrapper(self, message, observer=None, **kwargs):
await self.send_json(message)

communicator = WebsocketCommunicator(TestConsumer, "/testws/")
communicator = WebsocketCommunicator(TestConsumer(), "/testws/")

connected, _ = await communicator.connect()

Expand Down Expand Up @@ -122,7 +121,7 @@ async def user_change_wrapper_in_transaction(
):
await self.send_json(message)

communicator = WebsocketCommunicator(TestConsumer, "/testws/")
communicator = WebsocketCommunicator(TestConsumer(), "/testws/")

connected, _ = await communicator.connect()

Expand Down Expand Up @@ -175,7 +174,7 @@ async def accept(self, **kwargs):
async def user_change_observer_delete(self, message, observer=None, **kwargs):
await self.send_json(message)

communicator = WebsocketCommunicator(TestConsumerObserverDelete, "/testws/")
communicator = WebsocketCommunicator(TestConsumerObserverDelete(), "/testws/")

connected, _ = await communicator.connect()

Expand Down Expand Up @@ -233,13 +232,13 @@ async def accept(self, **kwargs):
async def user_change_many_connections_wrapper(self, message, **kwargs):
await self.send_json(message)

communicator1 = WebsocketCommunicator(TestConsumer, "/testws/")
communicator1 = WebsocketCommunicator(TestConsumer(), "/testws/")

connected, _ = await communicator1.connect()

assert connected

communicator2 = WebsocketCommunicator(TestConsumer, "/testws/")
communicator2 = WebsocketCommunicator(TestConsumer(), "/testws/")

connected, _ = await communicator2.connect()

Expand Down Expand Up @@ -300,13 +299,13 @@ async def accept(self, **kwargs):
async def user_change_many_consumers_wrapper_2(self, message, **kwargs):
await self.send_json(message)

communicator1 = WebsocketCommunicator(TestConsumer, "/testws/")
communicator1 = WebsocketCommunicator(TestConsumer(), "/testws/")

connected, _ = await communicator1.connect()

assert connected

communicator2 = WebsocketCommunicator(TestConsumer2, "/testws/")
communicator2 = WebsocketCommunicator(TestConsumer2(), "/testws/")

connected, _ = await communicator2.connect()

Expand Down Expand Up @@ -367,7 +366,7 @@ def user_change_custom_groups_wrapper(
else:
yield "-instance-username-{}".format(instance.username)

communicator = WebsocketCommunicator(TestConsumer, "/testws/")
communicator = WebsocketCommunicator(TestConsumer(), "/testws/")

connected, _ = await communicator.connect()

Expand Down Expand Up @@ -425,7 +424,7 @@ def user_change_custom_groups(self, instance=None, **kwargs):
def user_change_custom_groups(self, username=None, **kwargs):
yield "-instance-username-{}".format(slugify(username))

communicator = WebsocketCommunicator(TestConsumerObserverCustomGroups, "/testws/")
communicator = WebsocketCommunicator(TestConsumerObserverCustomGroups(), "/testws/")

connected, _ = await communicator.connect()

Expand Down

0 comments on commit 61369b4

Please sign in to comment.