def test_message_list_filter_by_lobby(self): """ User should be able to filter messages by lobby primary key """ lobby_1 = LobbyFactory() lobby_2 = LobbyFactory() message_1 = MessageFactory(lobby=lobby_1) message_2 = MessageFactory(lobby=lobby_2) response = self.user_client.get( f"{reverse(self.MESSAGE_LIST)}?lobby={lobby_2.pk}") self.assert_response_length(response, 1) self.assert_ids_in_results(response.json().get("results"), [message_2.pk])
def test_lobby_list(self): """ User should be able to list all lobbies created """ quantity = 3 [LobbyFactory() for i in range(quantity)] response = self.user_client.get(reverse(self.LOBBY_LIST)) self.assert_response_length(response, quantity)
def test_lobby_delete_not_owner(self): """ User should not be able to delete a lobby someone else created """ user_2 = UserFactory() lobby_1: Lobby = LobbyFactory(user=user_2) response = self.user_client.delete( reverse(self.LOBBY_DETAIL, args=[lobby_1.pk])) assert response.status_code == status.HTTP_403_FORBIDDEN
def test_lobby_delete(self): """ User should be able to delete a lobby he created """ lobby_1: Lobby = LobbyFactory(user=self.user) response = self.user_client.delete( reverse(self.LOBBY_DETAIL, args=[lobby_1.pk])) assert response.status_code == status.HTTP_204_NO_CONTENT assert Lobby.objects.count() == 0
def test_lobby_retrieve_private_not_member(self): """ User should not be able to retrieve private lobbies he is not a part of """ user_2 = UserFactory() user_3 = UserFactory() lobby_1: Lobby = LobbyFactory(user=user_2, users=[user_3]) response = self.user_client.get( reverse(self.LOBBY_DETAIL, args=[lobby_1.pk])) assert response.status_code == status.HTTP_404_NOT_FOUND
def test_lobby_retrieve_private(self): """ User should be able to retrieve private lobbies he created or is a part of """ user_2 = UserFactory() lobby_1: Lobby = LobbyFactory(user=self.user, users=[user_2]) response = self.user_client.get( reverse(self.LOBBY_DETAIL, args=[lobby_1.pk])) assert response.status_code == status.HTTP_200_OK assert len(response.data.get("users")) == 1
def test_lobby_retrieve(self): """ User should be able to retrieve a single instance of a lobby model """ lobby_1: Lobby = LobbyFactory(user=self.user) response = self.user_client.get( reverse(self.LOBBY_DETAIL, args=[lobby_1.pk])) assert response.status_code == status.HTTP_200_OK assert response.data.get("title") == lobby_1.title assert response.data.get("user") == self.user.pk
def test_message_list_private_messages(self): """ User should not be able to list messages from private lobbies he is not a part of """ user_2 = UserFactory() user_3 = UserFactory() lobby_1 = LobbyFactory(user=user_2, users=[user_3]) message_1 = MessageFactory(lobby=lobby_1) response = self.user_client.get(reverse(self.MESSAGE_LIST)) self.assert_response_length(response, 0)