Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
How to write class based testview for Django Channels using unittest module

I am trying to write unittests for my web sockets. I haven't wrote any previously so I am struggling understanding how to write using module unittest python package.

This is my consumer:

class DepartmentInfoConsumer(JsonWebsocketConsumer):

 def connect(self):
    if not self.scope["user"]:
        raise DenyConnection()
    self.accept()
    self.group_name = "test"

    async_to_sync(self.channel_layer.group_add)(f"department{self.scope['company'].id}", self.channel_name)
    departmentobject = Department.objects.get(company=self.scope["company"])
    self.send_json({"used_id": departmentobject.my_id})

 def disconnect(self, close_code):
    async_to_sync(self.channel_layer.group_discard)(f"department{self.scope['company'].id}", self.channel_name)
    raise StopConsumer()

 def used_id_info(self, event):
    self.send_json({"used_id": event["used_id"]})

MY URL:

websocket_urlpatterns = [
    re_path("bill/", consumers. DepartmentInfoConsumer.as_asgi(), name="billing-ws"),
]
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!