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.

68 lines
2.5 KiB

  1. from unittest.mock import patch
  2. from hc.payments.models import Subscription
  3. from hc.test import BaseTestCase
  4. class AddressTestCase(BaseTestCase):
  5. @patch("hc.payments.models.braintree")
  6. def test_it_retrieves_address(self, mock):
  7. mock.Address.find.return_value = {"company": "FooCo"}
  8. self.sub = Subscription(user=self.alice)
  9. self.sub.address_id = "aa"
  10. self.sub.save()
  11. self.client.login(username="[email protected]", password="password")
  12. r = self.client.get("/accounts/profile/billing/address/")
  13. self.assertContains(r, "FooCo")
  14. @patch("hc.payments.models.braintree")
  15. def test_it_creates_address(self, mock):
  16. mock.Address.create.return_value.is_success = True
  17. mock.Address.create.return_value.address.id = "bb"
  18. self.sub = Subscription(user=self.alice)
  19. self.sub.customer_id = "test-customer"
  20. self.sub.save()
  21. self.client.login(username="[email protected]", password="password")
  22. form = {"company": "BarCo"}
  23. r = self.client.post("/accounts/profile/billing/address/", form)
  24. self.assertRedirects(r, "/accounts/profile/billing/")
  25. self.sub.refresh_from_db()
  26. self.assertEqual(self.sub.address_id, "bb")
  27. @patch("hc.payments.models.braintree")
  28. def test_it_updates_address(self, mock):
  29. mock.Address.update.return_value.is_success = True
  30. self.sub = Subscription(user=self.alice)
  31. self.sub.customer_id = "test-customer"
  32. self.sub.address_id = "aa"
  33. self.sub.save()
  34. self.client.login(username="[email protected]", password="password")
  35. form = {"company": "BarCo"}
  36. r = self.client.post("/accounts/profile/billing/address/", form)
  37. self.assertRedirects(r, "/accounts/profile/billing/")
  38. @patch("hc.payments.models.braintree")
  39. def test_it_creates_customer(self, mock):
  40. mock.Address.create.return_value.is_success = True
  41. mock.Address.create.return_value.address.id = "bb"
  42. mock.Customer.create.return_value.is_success = True
  43. mock.Customer.create.return_value.customer.id = "test-customer-id"
  44. self.sub = Subscription(user=self.alice)
  45. self.sub.save()
  46. self.client.login(username="[email protected]", password="password")
  47. form = {"company": "BarCo"}
  48. self.client.post("/accounts/profile/billing/address/", form)
  49. self.sub.refresh_from_db()
  50. self.assertEqual(self.sub.customer_id, "test-customer-id")