Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

119
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda