Skip to content

Commit

Permalink
Simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
XanderVertegaal committed Aug 24, 2024
1 parent da1e2ed commit db5b678
Showing 1 changed file with 12 additions and 113 deletions.
125 changes: 12 additions & 113 deletions backend/core/tests/test_contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand All @@ -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()

Expand All @@ -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()

Expand Down

0 comments on commit db5b678

Please sign in to comment.