|
|
@ -7,6 +7,21 @@ from hc.test import BaseTestCase |
|
|
|
|
|
|
|
|
|
|
|
class CloseAccountTestCase(BaseTestCase): |
|
|
|
def test_it_requires_sudo_mode(self): |
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
|
|
|
|
|
r = self.client.get("/accounts/close/") |
|
|
|
self.assertContains(r, "We have sent a confirmation code") |
|
|
|
|
|
|
|
def test_it_shows_confirmation_form(self): |
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
|
self.set_sudo_flag() |
|
|
|
|
|
|
|
r = self.client.get("/accounts/close/") |
|
|
|
self.assertContains(r, "Close Account?") |
|
|
|
self.assertContains(r, "1 project") |
|
|
|
self.assertContains(r, "0 checks") |
|
|
|
|
|
|
|
@patch("hc.payments.models.braintree") |
|
|
|
def test_it_works(self, mock_braintree): |
|
|
|
Check.objects.create(project=self.project, tags="foo a-B_1 baz@") |
|
|
@ -15,8 +30,11 @@ class CloseAccountTestCase(BaseTestCase): |
|
|
|
) |
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
|
r = self.client.post("/accounts/close/") |
|
|
|
self.assertEqual(r.status_code, 302) |
|
|
|
self.set_sudo_flag() |
|
|
|
|
|
|
|
payload = {"confirmation": "[email protected]"} |
|
|
|
r = self.client.post("/accounts/close/", payload) |
|
|
|
self.assertRedirects(r, "/") |
|
|
|
|
|
|
|
# Alice should be gone |
|
|
|
alices = User.objects.filter(username="alice") |
|
|
@ -31,10 +49,26 @@ class CloseAccountTestCase(BaseTestCase): |
|
|
|
# Subscription should be gone |
|
|
|
self.assertFalse(Subscription.objects.exists()) |
|
|
|
|
|
|
|
def test_it_requires_confirmation(self): |
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
|
self.set_sudo_flag() |
|
|
|
|
|
|
|
payload = {"confirmation": "incorrect"} |
|
|
|
r = self.client.post("/accounts/close/", payload) |
|
|
|
self.assertContains(r, "Close Account?") |
|
|
|
self.assertContains(r, "has-error") |
|
|
|
|
|
|
|
# Alice should be still present |
|
|
|
self.alice.refresh_from_db() |
|
|
|
self.profile.refresh_from_db() |
|
|
|
|
|
|
|
def test_partner_removal_works(self): |
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
|
r = self.client.post("/accounts/close/") |
|
|
|
self.assertEqual(r.status_code, 302) |
|
|
|
self.set_sudo_flag() |
|
|
|
|
|
|
|
payload = {"confirmation": "[email protected]"} |
|
|
|
r = self.client.post("/accounts/close/", payload) |
|
|
|
self.assertRedirects(r, "/") |
|
|
|
|
|
|
|
# Alice should be still present |
|
|
|
self.alice.refresh_from_db() |
|
|
@ -43,8 +77,3 @@ class CloseAccountTestCase(BaseTestCase): |
|
|
|
# Bob should be gone |
|
|
|
bobs = User.objects.filter(username="bob") |
|
|
|
self.assertFalse(bobs.exists()) |
|
|
|
|
|
|
|
def test_it_rejects_get(self): |
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
|
r = self.client.get("/accounts/close/") |
|
|
|
self.assertEqual(r.status_code, 405) |