From db5b6786b9fed71b8571d6e7841ef9037f6ede14 Mon Sep 17 00:00:00 2001 From: Xander Vertegaal Date: Sat, 24 Aug 2024 10:57:38 +0200 Subject: [PATCH] Simplify tests --- backend/core/tests/test_contributors.py | 125 +++--------------------- 1 file changed, 12 insertions(+), 113 deletions(-) diff --git a/backend/core/tests/test_contributors.py b/backend/core/tests/test_contributors.py index 5596d377..fbaf8f03 100644 --- a/backend/core/tests/test_contributors.py +++ b/backend/core/tests/test_contributors.py @@ -40,18 +40,10 @@ def test_single_contributor_one_contribution(self): query=self.UPDATE_EPISODE_MUTATION, input_data={"id": self.episode.pk, "name": "Palpatine"}, ) - self.assertResponseNoErrors(response) - content = json.loads(response.content) - - self.assertTrue(content["data"]["updateEpisode"]["ok"]) - self.assertEqual(len(content["data"]["updateEpisode"]["errors"]), 0) - episode = Episode.objects.get(id=self.episode.pk) - self.assertEqual(episode.name, "Palpatine") - first_contributor = episode.contributors.first() if not first_contributor: @@ -66,34 +58,16 @@ def test_one_contributor_multiple_contributions(self): query=self.UPDATE_EPISODE_MUTATION, input_data={"id": self.episode.pk, "name": "Palpatine"}, ) - self.assertResponseNoErrors(response) - content = json.loads(response.content) - - self.assertTrue(content["data"]["updateEpisode"]["ok"]) - self.assertEqual(len(content["data"]["updateEpisode"]["errors"]), 0) - - episode = Episode.objects.get(id=self.episode.pk) - - self.assertEqual(episode.name, "Palpatine") - self.assertEqual(len(episode.contributors.all()), 1) - response = self.query( query=self.UPDATE_EPISODE_MUTATION, input_data={"id": self.episode.pk, "name": "Darth Vader"}, ) - self.assertResponseNoErrors(response) - content = json.loads(response.content) - - self.assertTrue(content["data"]["updateEpisode"]["ok"]) - self.assertEqual(len(content["data"]["updateEpisode"]["errors"]), 0) - episode = Episode.objects.get(id=self.episode.pk) - self.assertEqual(episode.name, "Darth Vader") self.assertEqual( len(episode.contributors.all()), 1, @@ -102,43 +76,21 @@ def test_one_contributor_multiple_contributions(self): def test_multiple_contributors_one_contribution(self): self.client.force_login(self.user_1) - response = self.query( query=self.UPDATE_EPISODE_MUTATION, input_data={"id": self.episode.pk, "name": "Han"}, ) - self.assertResponseNoErrors(response) - content = json.loads(response.content) - - self.assertTrue(content["data"]["updateEpisode"]["ok"]) - self.assertEqual(len(content["data"]["updateEpisode"]["errors"]), 0) - - episode = Episode.objects.get(id=self.episode.pk) - - self.assertEqual(episode.name, "Han") - self.assertEqual(len(episode.contributors.all()), 1) - self.client.force_login(self.user_2) - response = self.query( query=self.UPDATE_EPISODE_MUTATION, input_data={"id": self.episode.pk, "name": "Leia"}, ) - self.assertResponseNoErrors(response) - content = json.loads(response.content) - - self.assertTrue(content["data"]["updateEpisode"]["ok"]) - self.assertEqual(len(content["data"]["updateEpisode"]["errors"]), 0) - episode = Episode.objects.get(id=self.episode.pk) - self.assertEqual(episode.name, "Leia") - self.assertEqual(len(episode.contributors.all()), 2) - first_contributor = episode.contributors.first() second_contributor = episode.contributors.last() @@ -150,85 +102,32 @@ def test_multiple_contributors_one_contribution(self): def test_multiple_contributors_multiple_contributions(self): self.client.force_login(self.user_1) - - # First contribution by user 1 - response = self.query( + response_1_1 = self.query( query=self.UPDATE_EPISODE_MUTATION, input_data={"id": self.episode.pk, "name": "Jabba"}, ) - - self.assertResponseNoErrors(response) - - content = json.loads(response.content) - - self.assertTrue(content["data"]["updateEpisode"]["ok"]) - self.assertEqual(len(content["data"]["updateEpisode"]["errors"]), 0) - - episode = Episode.objects.get(id=self.episode.pk) - - self.assertEqual(episode.name, "Jabba") - self.assertEqual(len(episode.contributors.all()), 1) - - self.client.force_login(self.user_2) - - # First contribution by user 2 - response = self.query( + response_1_2 = self.query( query=self.UPDATE_EPISODE_MUTATION, - input_data={"id": self.episode.pk, "name": "Jango"}, + input_data={"id": self.episode.pk, "name": "Anakin"}, ) - self.assertResponseNoErrors(response) - - content = json.loads(response.content) - - self.assertTrue(content["data"]["updateEpisode"]["ok"]) - self.assertEqual(len(content["data"]["updateEpisode"]["errors"]), 0) - - episode = Episode.objects.get(id=self.episode.pk) - - self.assertEqual(episode.name, "Jango") - self.assertEqual(len(episode.contributors.all()), 2) - - self.client.force_login(self.user_1) - - # Second contribution by user 1 - response = self.query( + self.client.force_login(self.user_2) + response_2_1 = self.query( query=self.UPDATE_EPISODE_MUTATION, - input_data={"id": self.episode.pk, "name": "Luke"}, + input_data={"id": self.episode.pk, "name": "Jango"}, ) - - self.assertResponseNoErrors(response) - - content = json.loads(response.content) - - self.assertTrue(content["data"]["updateEpisode"]["ok"]) - self.assertEqual(len(content["data"]["updateEpisode"]["errors"]), 0) - - episode = Episode.objects.get(id=self.episode.pk) - - self.assertEqual(episode.name, "Luke") - self.assertEqual(len(episode.contributors.all()), 2) - - self.client.force_login(self.user_2) - - # Second contribution by user 2 - response = self.query( + response_2_2 = self.query( query=self.UPDATE_EPISODE_MUTATION, - input_data={"id": self.episode.pk, "name": "Jar-Jar"}, + input_data={"id": self.episode.pk, "name": "Boba"}, ) - self.assertResponseNoErrors(response) - - content = json.loads(response.content) - - self.assertTrue(content["data"]["updateEpisode"]["ok"]) - self.assertEqual(len(content["data"]["updateEpisode"]["errors"]), 0) + self.assertResponseNoErrors(response_1_1) + self.assertResponseNoErrors(response_1_2) + self.assertResponseNoErrors(response_2_1) + self.assertResponseNoErrors(response_2_2) episode = Episode.objects.get(id=self.episode.pk) - self.assertEqual(episode.name, "Jar-Jar") - self.assertEqual(len(episode.contributors.all()), 2) - first_contributor = episode.contributors.first() second_contributor = episode.contributors.last()