def test_get_event(self): """ Ensure we can get an existing event. """ # Seed the database with an event event = Event() event.event_time = "2020-08-29T13:24:27.172Z" event.game_id = 1 event.location = "Nashville, TN" event.scheduler_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 event 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-29T13:24:27.172000Z") self.assertEqual(json_response["game"]["id"], 1) self.assertEqual(json_response["location"], "Nashville, TN") self.assertEqual(json_response["scheduler"]["user"]["id"], 1)
def test_change_event(self): """ Ensure we can change an existing event """ event = Event() event.event_time = "2020-08-29T13:24:27.172Z" event.game_id = 1 event.location = "Nashville, TN" event.scheduler_id = 1 event.save() # Define new properties for game data = { "time": "2020-08-29T13:24:27.172000Z", "gameId": 1, "location": "Columbus, GA", "scheduler": 1 } 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 Event 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-29T13:24:27.172000Z") self.assertEqual(json_response["game"]["id"], 1) self.assertEqual(json_response["location"], "Columbus, GA") self.assertEqual(json_response["scheduler"]["user"]["id"], 1)
def test_change_event(self): """ Ensure we can change an existing game. """ event = Event() event.event_time = "2021-02-12 12:47:00" event.location = "Sorry" event.scheduler_id = 1 event.game_id = 1 event.save() # DEFINE NEW PROPERTIES FOR GAME data = { "event_time": "2021-03-12 12:47:00", "location": "your moms house", "gameId": 1, "gamerId": 1 } 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["location"], "your moms house") self.assertEqual(json_response["event_time"], "2021-03-12T12:47:00Z") self.assertEqual(json_response["game"]["id"], 1) self.assertEqual(json_response["scheduler"]["id"], 1)
def test_get_event(self): event = Event() event.game_id = 1 event.scheduler_id = 1 event.location = "The moon" event.event_time = "2021-02-05 17:00:00" event.save() self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token) response = self.client.get(f"/events/{event.id}") json_response = json.loads(response.content) self.assertEqual(json_response["location"], "The moon")
def test_delete_game(self): """ Ensure we can delete an existing game. """ event = Event() event.event_time = "2020-08-29T13:24:27.172Z" event.game_id = 1 event.location = "Nashville, TN" event.scheduler_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 again to verify 404 response = self.client.get(f"/events/{event.id}") self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_delete_event(self): """ Ensure we can delete an existing game. """ event = Event() event.event_time = "2021-02-12 12:47:00" event.location = "Sorry" event.scheduler_id = 1 event.game_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)