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.

56 lines
1.9 KiB

  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(project=self.project, tags="foo a-B_1 baz@")
  10. Subscription.objects.create(user=self.alice, subscription_id="123")
  11. self.client.login(username="[email protected]", password="password")
  12. r = self.client.post("/accounts/close/")
  13. self.assertEqual(r.status_code, 302)
  14. # Alice should be gone
  15. alices = User.objects.filter(username="alice")
  16. self.assertFalse(alices.exists())
  17. # Alice should be gone
  18. alices = User.objects.filter(username="alice")
  19. self.assertFalse(alices.exists())
  20. # Bob's current team should now be None
  21. self.bobs_profile.refresh_from_db()
  22. self.assertIsNone(self.bobs_profile.current_project)
  23. # Check should be gone
  24. self.assertFalse(Check.objects.exists())
  25. # Subscription should have been canceled
  26. self.assertTrue(mock_cancel.called)
  27. # Subscription should be gone
  28. self.assertFalse(Subscription.objects.exists())
  29. def test_partner_removal_works(self):
  30. self.client.login(username="[email protected]", password="password")
  31. r = self.client.post("/accounts/close/")
  32. self.assertEqual(r.status_code, 302)
  33. # Alice should be still present
  34. self.alice.refresh_from_db()
  35. self.profile.refresh_from_db()
  36. # Bob should be gone
  37. bobs = User.objects.filter(username="bob")
  38. self.assertFalse(bobs.exists())
  39. def test_it_rejects_get(self):
  40. self.client.login(username="[email protected]", password="password")
  41. r = self.client.get("/accounts/close/")
  42. self.assertEqual(r.status_code, 405)