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.

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