Skip to content

Commit

Permalink
Use role constants in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfischer committed Nov 18, 2024
1 parent 90a4a76 commit d15884e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
32 changes: 16 additions & 16 deletions adserver/tests/test_advertiser_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,13 @@ def test_flight_autorenew_view(self):

# Make it a reporter who can't access
member = UserAdvertiserMember.objects.get(user=self.user, advertiser=self.advertiser)
member.role = "Reporter"
member.role = UserAdvertiserMember.ROLE_REPORTER
member.save()

resp = self.client.get(url)
self.assertEqual(resp.status_code, 403)

member.role = "Manager"
member.role = UserAdvertiserMember.ROLE_MANAGER
member.save()

resp = self.client.get(url)
Expand Down Expand Up @@ -592,13 +592,13 @@ def test_flight_request_view(self):

# Make it a reporter who can't access
member = UserAdvertiserMember.objects.get(user=self.user, advertiser=self.advertiser)
member.role = "Reporter"
member.role = UserAdvertiserMember.ROLE_REPORTER
member.save()

resp = self.client.get(url)
self.assertEqual(resp.status_code, 403)

member.role = "Manager"
member.role = UserAdvertiserMember.ROLE_MANAGER
member.save()

self.client.force_login(self.user)
Expand Down Expand Up @@ -726,13 +726,13 @@ def test_ad_update_view(self):

# Make it a reporter who can't access
member = UserAdvertiserMember.objects.get(user=self.user, advertiser=self.advertiser)
member.role = "Reporter"
member.role = UserAdvertiserMember.ROLE_REPORTER
member.save()

response = self.client.get(url)
self.assertEqual(response.status_code, 403)

member.role = "Manager"
member.role = UserAdvertiserMember.ROLE_MANAGER
member.save()

response = self.client.get(url)
Expand Down Expand Up @@ -773,13 +773,13 @@ def test_ad_create_view(self):

# Make it a reporter who can't access
member = UserAdvertiserMember.objects.get(user=self.user, advertiser=self.advertiser)
member.role = "Reporter"
member.role = UserAdvertiserMember.ROLE_REPORTER
member.save()

response = self.client.get(url)
self.assertEqual(response.status_code, 403)

member.role = "Manager"
member.role = UserAdvertiserMember.ROLE_MANAGER
member.save()

response = self.client.get(url)
Expand Down Expand Up @@ -820,13 +820,13 @@ def test_ad_copy_view(self):

# Make it a reporter who can't access
member = UserAdvertiserMember.objects.get(user=self.user, advertiser=self.advertiser)
member.role = "Reporter"
member.role = UserAdvertiserMember.ROLE_REPORTER
member.save()

response = self.client.get(url)
self.assertEqual(response.status_code, 403)

member.role = "Manager"
member.role = UserAdvertiserMember.ROLE_MANAGER
member.save()

response = self.client.get(url)
Expand Down Expand Up @@ -892,7 +892,7 @@ def test_authorized_users(self):

# Make it a manager who can't invite users
member = UserAdvertiserMember.objects.get(user=self.user, advertiser=self.advertiser)
member.role = "Manager"
member.role = UserAdvertiserMember.ROLE_MANAGER
member.save()

self.client.force_login(self.user)
Expand Down Expand Up @@ -955,14 +955,14 @@ def test_authorized_users_invite(self):

# Make it a manager who can't invite users
member = UserAdvertiserMember.objects.get(user=self.user, advertiser=self.advertiser)
member.role = "Manager"
member.role = UserAdvertiserMember.ROLE_MANAGER
member.save()

self.client.force_login(self.user)
response = self.client.get(url)
self.assertEqual(response.status_code, 403)

member.role = "Admin"
member.role = UserAdvertiserMember.ROLE_ADMIN
member.save()

response = self.client.get(url)
Expand All @@ -971,7 +971,7 @@ def test_authorized_users_invite(self):

response = self.client.post(
url,
data={"name": "Another User", "email": "[email protected]", "role": "Manager"},
data={"name": "Another User", "email": "[email protected]", "role": UserAdvertiserMember.ROLE_MANAGER},
follow=True,
)
self.assertEqual(response.status_code, 200)
Expand All @@ -992,7 +992,7 @@ def test_authorized_users_invite_existing(self):

response = self.client.post(
url,
data={"name": name, "email": email, "role": "Manager"},
data={"name": name, "email": email, "role": UserAdvertiserMember.ROLE_MANAGER},
follow=True,
)
self.assertEqual(response.status_code, 200)
Expand All @@ -1002,7 +1002,7 @@ def test_authorized_users_invite_existing(self):
# Invite the same user again to check that the user isn't created again
response = self.client.post(
url,
data={"name": "Yet Another User", "email": email, "role": "Manager"},
data={"name": "Yet Another User", "email": email, "role": UserAdvertiserMember.ROLE_MANAGER},
follow=True,
)
self.assertEqual(response.status_code, 200)
Expand Down
32 changes: 16 additions & 16 deletions adserver/tests/test_publisher_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ def test_publisher_settings(self):
member = UserPublisherMember.objects.create(
user=self.user,
publisher=self.publisher1,
role="Manager",
role=UserPublisherMember.ROLE_MANAGER,
)
self.client.force_login(self.user)

resp = self.client.get(url)
self.assertEqual(resp.status_code, 403)

member.role = "Admin"
member.role = UserPublisherMember.ROLE_ADMIN
member.save()

resp = self.client.get(url)
Expand Down Expand Up @@ -406,7 +406,7 @@ def test_authorized_users(self):
member = UserPublisherMember.objects.create(
user=self.user,
publisher=self.publisher1,
role="Manager",
role=UserPublisherMember.ROLE_MANAGER,
)
self.client.force_login(self.user)

Expand Down Expand Up @@ -473,15 +473,15 @@ def test_authorized_users_invite(self):
member = UserPublisherMember.objects.create(
user=self.user,
publisher=self.publisher1,
role="Manager",
role=UserPublisherMember.ROLE_MANAGER,
)

self.client.force_login(self.user)

response = self.client.get(url)
self.assertEqual(response.status_code, 403)

member.role = "Admin"
member.role = UserPublisherMember.ROLE_ADMIN
member.save()

response = self.client.get(url)
Expand All @@ -490,7 +490,7 @@ def test_authorized_users_invite(self):

response = self.client.post(
url,
data={"name": "Another User", "email": "[email protected]", "role": "Reporter"},
data={"name": "Another User", "email": "[email protected]", "role": UserPublisherMember.ROLE_REPORTER},
follow=True,
)
self.assertEqual(response.status_code, 200)
Expand All @@ -514,7 +514,7 @@ def test_authorized_users_invite_existing(self):

response = self.client.post(
url,
data={"name": name, "email": email, "role": "Reporter"},
data={"name": name, "email": email, "role": UserPublisherMember.ROLE_REPORTER},
follow=True,
)
self.assertEqual(response.status_code, 200)
Expand All @@ -524,7 +524,7 @@ def test_authorized_users_invite_existing(self):
# Invite the same user again to check that the user isn't created again
response = self.client.post(
url,
data={"name": "Yet Another User", "email": email, "role": "Reporter"},
data={"name": "Yet Another User", "email": email, "role": UserPublisherMember.ROLE_REPORTER},
follow=True,
)
self.assertEqual(response.status_code, 200)
Expand Down Expand Up @@ -603,15 +603,15 @@ def test_fallback_ads_list(self):
member = UserPublisherMember.objects.create(
user=self.user,
publisher=self.publisher,
role="Manager",
role=UserPublisherMember.ROLE_MANAGER,
)

resp = self.client.get(url)
self.assertEqual(resp.status_code, 200)
self.assertContains(resp, "Test Ad 1")
self.assertContains(resp, "Create fallback ad")

member.role = "Reporter"
member.role = UserPublisherMember.ROLE_REPORTER
member.save()

resp = self.client.get(url)
Expand All @@ -637,15 +637,15 @@ def test_fallback_ads_detail(self):
member = UserPublisherMember.objects.create(
user=self.user,
publisher=self.publisher,
role="Manager",
role=UserPublisherMember.ROLE_MANAGER,
)

resp = self.client.get(url)
self.assertEqual(resp.status_code, 200)
self.assertContains(resp, "Test Ad 1")
self.assertContains(resp, "Edit fallback ad")

member.role = "Reporter"
member.role = UserPublisherMember.ROLE_REPORTER
member.save()

resp = self.client.get(url)
Expand All @@ -671,14 +671,14 @@ def test_fallback_ads_update(self):
member = UserPublisherMember.objects.create(
user=self.user,
publisher=self.publisher,
role="Reporter",
role=UserPublisherMember.ROLE_REPORTER,
)

# Reporters can't edit
resp = self.client.get(url)
self.assertEqual(resp.status_code, 403)

member.role = "Manager"
member.role = UserPublisherMember.ROLE_MANAGER
member.save()

resp = self.client.get(url)
Expand Down Expand Up @@ -719,14 +719,14 @@ def test_fallback_ads_create(self):
member = UserPublisherMember.objects.create(
user=self.user,
publisher=self.publisher,
role="Reporter",
role=UserPublisherMember.ROLE_REPORTER,
)

# Reporter can't create
resp = self.client.get(url)
self.assertEqual(resp.status_code, 403)

member.role = "Manager"
member.role = UserPublisherMember.ROLE_MANAGER
member.save()

resp = self.client.get(url)
Expand Down

0 comments on commit d15884e

Please sign in to comment.