You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.1 KiB

6 years ago
  1. from django.contrib.auth.models import User
  2. from hc.api.models import Check
  3. from hc.payments.models import Subscription
  4. from hc.test import BaseTestCase
  5. from mock import patch
  6. class CloseAccountTestCase(BaseTestCase):
  7. @patch("hc.payments.models.Subscription.cancel")
  8. def test_it_works(self, mock_cancel):
  9. Check.objects.create(user=self.alice, tags="foo a-B_1 baz@",
  10. project=self.project)
  11. Subscription.objects.create(user=self.alice, subscription_id="123")
  12. self.client.login(username="[email protected]", password="password")
  13. r = self.client.post("/accounts/close/")
  14. self.assertEqual(r.status_code, 302)
  15. # Alice should be gone
  16. alices = User.objects.filter(username="alice")
  17. self.assertFalse(alices.exists())
  18. # Alice should be gone
  19. alices = User.objects.filter(username="alice")
  20. self.assertFalse(alices.exists())
  21. # Bob's current team should now be None
  22. self.bobs_profile.refresh_from_db()
  23. self.assertIsNone(self.bobs_profile.current_team)
  24. self.assertIsNone(self.bobs_profile.current_project)
  25. # Check should be gone
  26. self.assertFalse(Check.objects.exists())
  27. # Subscription should have been canceled
  28. self.assertTrue(mock_cancel.called)
  29. # Subscription should be gone
  30. self.assertFalse(Subscription.objects.exists())
  31. def test_partner_removal_works(self):
  32. self.client.login(username="[email protected]", password="password")
  33. r = self.client.post("/accounts/close/")
  34. self.assertEqual(r.status_code, 302)
  35. # Alice should be still present
  36. self.alice.refresh_from_db()
  37. self.profile.refresh_from_db()
  38. self.assertEqual(self.profile.current_team, None)
  39. # Bob should be gone
  40. bobs = User.objects.filter(username="bob")
  41. self.assertFalse(bobs.exists())
  42. def test_it_rejects_get(self):
  43. self.client.login(username="[email protected]", password="password")
  44. r = self.client.get("/accounts/close/")
  45. self.assertEqual(r.status_code, 405)