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