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.

52 lines
1.8 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. # Bob's current team should now be None
  18. self.bobs_profile.refresh_from_db()
  19. self.assertIsNone(self.bobs_profile.current_project)
  20. # Check should be gone
  21. self.assertFalse(Check.objects.exists())
  22. # Subscription should have been canceled
  23. self.assertTrue(mock_cancel.called)
  24. # Subscription should be gone
  25. self.assertFalse(Subscription.objects.exists())
  26. def test_partner_removal_works(self):
  27. self.client.login(username="[email protected]", password="password")
  28. r = self.client.post("/accounts/close/")
  29. self.assertEqual(r.status_code, 302)
  30. # Alice should be still present
  31. self.alice.refresh_from_db()
  32. self.profile.refresh_from_db()
  33. # Bob should be gone
  34. bobs = User.objects.filter(username="bob")
  35. self.assertFalse(bobs.exists())
  36. def test_it_rejects_get(self):
  37. self.client.login(username="[email protected]", password="password")
  38. r = self.client.get("/accounts/close/")
  39. self.assertEqual(r.status_code, 405)