Estoy tratando de escribir pruebas unitarias para mis sockets web. No he escrito ninguno anteriormente, así que tengo dificultades para entender cómo escribir usando el paquete de Python unittest del módulo.
Este es mi consumidor:
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"]})MI URL:
websocket_urlpatterns = [ re_path("bill/", consumers. DepartmentInfoConsumer.as_asgi(), name="billing-ws"), ]