Пример #1
0
    def test_get_game(self):
        """
        Ensure we can get an existing game.
        """
        event = Event()
        event.event_day = "1820-10-25"
        event.event_time = "14:39"
        event.game_id = 1
        event.location = "Tom's"
        event.gamer_id = 1

        event.save()

        # Make sure request is authenticated
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token)

        # Initiate request and store response
        response = self.client.get(f"/events/{event.id}")

        # Parse the JSON in the response body
        json_response = json.loads(response.content)

        # Assert that the game was retrieved
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Assert that the values are correct
        self.assertEqual(json_response["event_day"], "1820-10-25")
        self.assertEqual(json_response["event_time"], "14:39:00")
        self.assertEqual(json_response["location"], "Tom's")
Пример #2
0
    def test_get_event(self):
        """
        Ensure we can get an existing game.
        """

        # Seed the database with a game
        event = Event()
        event.event_time = "2020-08-28T14:51:39.989Z"
        event.location = "Shelbyville"
        event.game_id = 1
        event.gamer_id = 1
        event.save()
        # Make sure request is authenticated
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token)

        # Initiate request and store response
        response = self.client.get(f"/events/{event.id}")

        # Parse the JSON in the response body
        json_response = json.loads(response.content)

        # Assert that the game was retrieved
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Assert that the values are correct
        # self.assertEqual(json_response["event_time"], "2020-08-28T14:51:39.989Z")
        self.assertEqual(json_response["game"]["id"], 1)
        self.assertEqual(json_response["gamer"]["id"], 1)
        self.assertEqual(json_response["location"], "Shelbyville")
Пример #3
0
    def test_change_event(self):
        """
        Ensure we can get an existing game.
        """

        # Seed the database with a game
        event = Event()
        event.event_time = "2020-08-28T14:51:39.989Z"
        event.location = "Shelbyville"
        event.game_id = 1
        event.gamer_id = 1
        event.save()

        data = {
            "event_time": "2020-08-28T14:51:39.989Z",
            "gameId": 1,
            "gamerId": 1,
            "location": "Shelbyville"
        }
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token)
        response = self.client.put(f"/events/{event.id}", data, format="json")
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        # GET GAME AGAIN TO VERIFY CHANGES
        response = self.client.get(f"/events/{event.id}")
        json_response = json.loads(response.content)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Assert that the properties are correct
        self.assertEqual(json_response["event_time"],
                         "2020-08-28T14:51:39.989Z")
        self.assertEqual(json_response["game"]["id"], 1)
        self.assertEqual(json_response["gamer"]["id"], 1)
        self.assertEqual(json_response["location"], "Shelbyville")
Пример #4
0
    def test_delete_event(self):
        """
        Ensure we can delete an existing game.
        """
        event = Event()
        event.event_time = "2020-08-28T14:51:39.989Z"
        event.location = "Shelbyville"
        event.game_id = 1
        event.gamer_id = 1
        event.save()

        self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token)
        response = self.client.delete(f"/events/{event.id}")
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        # GET event AGAIN TO VERIFY 404 response
        response = self.client.get(f"/events/{event.id}")
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)