Reduce usage of request.project cc: #336

This commit is contained in:
Pēteris Caune 2020-02-25 15:39:54 +02:00
parent 318934697f
commit bb808852d9
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
4 changed files with 9 additions and 4 deletions

View File

@ -161,6 +161,9 @@ class ProjectTestCase(BaseTestCase):
self.assertEqual(r.status_code, 403) self.assertEqual(r.status_code, 403)
def test_it_checks_membership_when_removing_team_member(self): def test_it_checks_membership_when_removing_team_member(self):
self.profile.current_project = self.project
self.profile.save()
self.client.login(username="charlie@example.org", password="password") self.client.login(username="charlie@example.org", password="password")
url = "/projects/%s/settings/" % self.charlies_project.code url = "/projects/%s/settings/" % self.charlies_project.code

View File

@ -1,4 +1,4 @@
from hc.api.models import Channel from hc.api.models import Channel, Check
from hc.test import BaseTestCase from hc.test import BaseTestCase
@ -9,11 +9,14 @@ class ChannelChecksTestCase(BaseTestCase):
self.channel.value = "alice@example.org" self.channel.value = "alice@example.org"
self.channel.save() self.channel.save()
Check.objects.create(project=self.project, name="Database Backups")
def test_it_works(self): def test_it_works(self):
url = "/integrations/%s/checks/" % self.channel.code url = "/integrations/%s/checks/" % self.channel.code
self.client.login(username="alice@example.org", password="password") self.client.login(username="alice@example.org", password="password")
r = self.client.get(url) r = self.client.get(url)
self.assertContains(r, "Database Backups")
self.assertContains(r, "Assign Checks to Integration", status_code=200) self.assertContains(r, "Assign Checks to Integration", status_code=200)
def test_team_access_works(self): def test_team_access_works(self):

View File

@ -706,7 +706,7 @@ def channel_checks(request, code):
channel = _get_channel_for_user(request, code) channel = _get_channel_for_user(request, code)
assigned = set(channel.checks.values_list("code", flat=True).distinct()) assigned = set(channel.checks.values_list("code", flat=True).distinct())
checks = Check.objects.filter(project=request.project).order_by("created") checks = Check.objects.filter(project=channel.project).order_by("created")
ctx = {"checks": checks, "assigned": assigned, "channel": channel} ctx = {"checks": checks, "assigned": assigned, "channel": channel}
@ -1147,7 +1147,7 @@ def add_pushbullet(request, code):
ctx = { ctx = {
"page": "channels", "page": "channels",
"project": request.project, "project": project,
"authorize_url": authorize_url, "authorize_url": authorize_url,
} }

View File

@ -20,7 +20,6 @@ class BaseTestCase(TestCase):
self.profile = Profile(user=self.alice) self.profile = Profile(user=self.alice)
self.profile.sms_limit = 50 self.profile.sms_limit = 50
self.profile.current_project = self.project
self.profile.save() self.profile.save()
# Bob is on Alice's team and should have access to her stuff # Bob is on Alice's team and should have access to her stuff