@ -0,0 +1,27 @@ | |||
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 | |||
def test_it_works(self): | |||
self.client.login(username="[email protected]", password="password") | |||
r = self.client.post("/projects/add/", {"name": "My Second Project"}) | |||
p = Project.objects.get(owner=self.alice, name="My Second Project") | |||
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="[email protected]", password="password") | |||
r = self.client.get("/projects/add/") | |||
self.assertEqual(r.status_code, 405) |
@ -108,3 +108,22 @@ class ProfileTestCase(BaseTestCase): | |||
self.assertEqual(len(mail.outbox), 1) | |||
expected_subject = "Change email address on %s" % settings.SITE_NAME | |||
self.assertEqual(mail.outbox[0].subject, expected_subject) | |||
def test_leaving_works(self): | |||
self.client.login(username="[email protected]", password="password") | |||
form = {"code": str(self.project.code), "leave_project": "1"} | |||
r = self.client.post("/accounts/profile/", form) | |||
self.assertContains(r, "Left project") | |||
self.assertNotContains(r, "Alice's Project") | |||
self.bobs_profile.refresh_from_db() | |||
self.assertIsNone(self.bobs_profile.current_project) | |||
self.assertFalse(self.bob.memberships.exists()) | |||
def test_leaving_checks_membership(self): | |||
self.client.login(username="[email protected]", password="password") | |||
form = {"code": str(self.project.code), "leave_project": "1"} | |||
r = self.client.post("/accounts/profile/", form) | |||
self.assertEqual(r.status_code, 400) |
@ -11,6 +11,11 @@ class ProfileTestCase(BaseTestCase): | |||
self.url = "/projects/%s/settings/" % self.project.code | |||
def test_it_checks_access(self): | |||
self.client.login(username="[email protected]", password="password") | |||
r = self.client.get(self.url) | |||
self.assertEqual(r.status_code, 404) | |||
def test_it_shows_api_keys(self): | |||
self.project.api_key_readonly = "R" * 32 | |||
self.project.save() | |||
@ -44,7 +49,7 @@ class ProfileTestCase(BaseTestCase): | |||
form = {"revoke_api_keys": "1"} | |||
r = self.client.post(self.url, form) | |||
assert r.status_code == 200 | |||
self.assertEqual(r.status_code, 200) | |||
self.project.refresh_from_db() | |||
self.assertEqual(self.project.api_key, "") | |||
@ -69,8 +74,8 @@ class ProfileTestCase(BaseTestCase): | |||
self.assertFalse(member.user.project_set.exists()) | |||
# And an email should have been sent | |||
subj = ('You have been invited to join' | |||
' [email protected] on %s' % settings.SITE_NAME) | |||
subj = ("You have been invited to join" | |||
" Alice's Project on %s" % settings.SITE_NAME) | |||
self.assertEqual(mail.outbox[0].subject, subj) | |||
def test_it_checks_team_size(self): | |||
@ -0,0 +1,37 @@ | |||
from hc.api.models import Check | |||
from hc.test import BaseTestCase | |||
class RemoveProjectTestCase(BaseTestCase): | |||
def setUp(self): | |||
super(RemoveProjectTestCase, self).setUp() | |||
self.url = "/projects/%s/remove/" % self.project.code | |||
def test_it_works(self): | |||
Check.objects.create(project=self.project, tags="foo a-B_1 baz@") | |||
self.client.login(username="[email protected]", password="password") | |||
r = self.client.post(self.url) | |||
self.assertRedirects(r, "/") | |||
# Alice's current project should be not set | |||
self.profile.refresh_from_db() | |||
self.assertEqual(self.profile.current_project, None) | |||
# Alice should not own any projects | |||
self.assertFalse(self.alice.project_set.exists()) | |||
# Check should be gone | |||
self.assertFalse(Check.objects.exists()) | |||
def test_it_rejects_get(self): | |||
self.client.login(username="[email protected]", password="password") | |||
r = self.client.get(self.url) | |||
self.assertEqual(r.status_code, 405) | |||
def test_it_checks_access(self): | |||
self.client.login(username="[email protected]", password="password") | |||
r = self.client.post(self.url) | |||
self.assertEqual(r.status_code, 404) |