forked from GithubBackups/healthchecks
Reduce usage of Profile.current_project cc: #336
This commit is contained in:
parent
6a0c90853b
commit
157711bc95
@ -2,12 +2,7 @@ from hc.accounts.models import Project
|
||||
from hc.test import BaseTestCase
|
||||
|
||||
|
||||
class RemoveProjectTestCase(BaseTestCase):
|
||||
def setUp(self):
|
||||
super(RemoveProjectTestCase, self).setUp()
|
||||
|
||||
self.url = "/projects/%s/remove/" % self.project.code
|
||||
|
||||
class AddProjectTestCase(BaseTestCase):
|
||||
def test_it_works(self):
|
||||
self.client.login(username="alice@example.org", password="password")
|
||||
r = self.client.post("/projects/add/", {"name": "My Second Project"})
|
||||
@ -16,10 +11,6 @@ class RemoveProjectTestCase(BaseTestCase):
|
||||
self.assertRedirects(r, "/projects/%s/checks/" % p.code)
|
||||
self.assertEqual(str(p.code), p.badge_key)
|
||||
|
||||
# Alice's current project should be the just created one
|
||||
self.profile.refresh_from_db()
|
||||
self.assertEqual(self.profile.current_project, p)
|
||||
|
||||
def test_it_rejects_get(self):
|
||||
self.client.login(username="alice@example.org", password="password")
|
||||
r = self.client.get("/projects/add/")
|
||||
|
@ -34,16 +34,12 @@ class MyChecksTestCase(BaseTestCase):
|
||||
delta = timezone.now() - self.profile.last_active_date
|
||||
self.assertTrue(delta.total_seconds() < 1)
|
||||
|
||||
def test_it_updates_current_project(self):
|
||||
self.profile.current_project = None
|
||||
self.profile.save()
|
||||
|
||||
def test_it_updates_session(self):
|
||||
self.client.login(username="alice@example.org", password="password")
|
||||
r = self.client.get(self.url)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
self.profile.refresh_from_db()
|
||||
self.assertEqual(self.profile.current_project, self.project)
|
||||
self.assertEqual(self.client.session["last_project_id"], self.project.id)
|
||||
|
||||
def test_it_checks_access(self):
|
||||
self.client.login(username="charlie@example.org", password="password")
|
||||
|
@ -2,9 +2,9 @@ from hc.api.models import Channel, Check
|
||||
from hc.test import BaseTestCase
|
||||
|
||||
|
||||
class TrabsferTestCase(BaseTestCase):
|
||||
class TransferTestCase(BaseTestCase):
|
||||
def setUp(self):
|
||||
super(TrabsferTestCase, self).setUp()
|
||||
super(TransferTestCase, self).setUp()
|
||||
|
||||
self.check = Check.objects.create(project=self.bobs_project)
|
||||
self.url = "/checks/%s/transfer/" % self.check.code
|
||||
@ -15,9 +15,6 @@ class TrabsferTestCase(BaseTestCase):
|
||||
self.assertContains(r, "Transfer to Another Project")
|
||||
|
||||
def test_it_works(self):
|
||||
self.bobs_profile.current_project = self.bobs_project
|
||||
self.bobs_profile.save()
|
||||
|
||||
self.client.login(username="bob@example.org", password="password")
|
||||
payload = {"project": self.project.code}
|
||||
r = self.client.post(self.url, payload, follow=True)
|
||||
@ -27,10 +24,6 @@ class TrabsferTestCase(BaseTestCase):
|
||||
check = Check.objects.get()
|
||||
self.assertEqual(check.project, self.project)
|
||||
|
||||
# Bob's current project should have been updated
|
||||
self.bobs_profile.refresh_from_db()
|
||||
self.assertEqual(self.bobs_profile.current_project, self.project)
|
||||
|
||||
def test_it_obeys_check_limit(self):
|
||||
# Alice's projects cannot accept checks due to limits:
|
||||
self.profile.check_limit = 0
|
||||
|
@ -154,9 +154,8 @@ def my_checks(request, code):
|
||||
request.profile.sort = request.GET["sort"]
|
||||
request.profile.save()
|
||||
|
||||
if request.profile.current_project_id != project.id:
|
||||
request.profile.current_project = project
|
||||
request.profile.save()
|
||||
if request.session.get("last_project_id") != project.id:
|
||||
request.session["last_project_id"] = project.id
|
||||
|
||||
q = Check.objects.filter(project=project)
|
||||
checks = list(q.prefetch_related("channel_set"))
|
||||
@ -257,7 +256,12 @@ def index(request):
|
||||
if request.user.is_authenticated:
|
||||
projects = list(request.profile.projects())
|
||||
|
||||
ctx = {"page": "projects", "projects": projects}
|
||||
ctx = {
|
||||
"page": "projects",
|
||||
"projects": projects,
|
||||
"last_project_id": request.session.get("last_project_id"),
|
||||
}
|
||||
|
||||
return render(request, "front/projects.html", ctx)
|
||||
|
||||
check = Check()
|
||||
@ -555,14 +559,9 @@ def transfer(request, code):
|
||||
|
||||
check.project = target_project
|
||||
check.save()
|
||||
|
||||
check.assign_all_channels()
|
||||
|
||||
request.profile.current_project = target_project
|
||||
request.profile.save()
|
||||
|
||||
messages.success(request, "Check transferred successfully!")
|
||||
|
||||
return redirect("hc-details", code)
|
||||
|
||||
ctx = {"check": check}
|
||||
|
@ -15,7 +15,7 @@
|
||||
{% for project in projects %}
|
||||
<a href="{% url 'hc-checks' project.code %}">
|
||||
<div class="col-sm-6 col-md-4">
|
||||
<div class="panel project {% if project == request.profile.current_project %}selected{% endif %}">
|
||||
<div class="panel project {% if project.id == last_project_id %}selected{% endif %}">
|
||||
<div class="status icon-{{ project.overall_status }}"></div>
|
||||
|
||||
<h4>{{ project }}</h4>
|
||||
|
Loading…
x
Reference in New Issue
Block a user