Skip to content

Commit

Permalink
feat: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
helllllllder committed Jul 18, 2023
1 parent 3ae6eb8 commit 6362c5a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
21 changes: 0 additions & 21 deletions chats/apps/api/v1/rooms/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from datetime import timedelta

from django.conf import settings
from django.db import connection, reset_queries
from django.db.models import (
BooleanField,
Case,
Expand Down Expand Up @@ -37,20 +36,6 @@
from chats.apps.rooms.models import Room


def database_debug(func, *args, **kwargs):
def inner_func(*args, **kwargs):
reset_queries()
results = func(*args, **kwargs)
query_info = connection.queries
print("function_name: {}".format(func.__name__))
print("query_count: {}".format(len(query_info)))
# queries = ["\n{}\n".format(query["sql"]) for query in query_info]
# print("queries: \n{}\n".format("".join(queries)))
return results

return inner_func


class RoomViewset(
mixins.ListModelMixin,
mixins.RetrieveModelMixin,
Expand All @@ -71,10 +56,6 @@ class RoomViewset(
pagination_class = CursorPagination
pagination_class.page_size_query_param = "limit"

@database_debug
def list(self, request, *args, **kwargs):
return super().list(request, *args, **kwargs)

def get_permissions(self):
permission_classes = [permissions.IsAuthenticated]
if self.action != "list":
Expand Down Expand Up @@ -110,9 +91,7 @@ def get_queryset(self):
output_field=BooleanField(),
),
)
# import pdb

# pdb.set_trace()
return qs

def get_serializer_class(self):
Expand Down
4 changes: 2 additions & 2 deletions chats/apps/rooms/tests/test_viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ def _ok_list_rooms(self, token, rooms: list, data: dict):
response, results = self._request_list_rooms(token, data)
self.assertEqual(response.status_code, status.HTTP_200_OK)

self.assertEqual(response.json().get("count"), len(rooms))
self.assertEqual(len(response.json().get("results")), len(rooms))
for result in results:
self.assertIn(result.get("uuid"), rooms)

def _not_ok_list_rooms(self, token, data: dict):
response, _ = self._request_list_rooms(token, data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.json().get("count"), 0)
self.assertEqual(len(response.json().get("results")), 0)

def test_list_rooms_given_agents(self):
self._ok_list_rooms(
Expand Down

0 comments on commit 6362c5a

Please sign in to comment.