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.

59 lines
2.1 KiB

7 years ago
  1. from mock import Mock, patch
  2. from django.utils.timezone import now
  3. from hc.payments.models import Subscription
  4. from hc.test import BaseTestCase
  5. import six
  6. class PdfInvoiceTestCase(BaseTestCase):
  7. def setUp(self):
  8. super(PdfInvoiceTestCase, self).setUp()
  9. self.sub = Subscription(user=self.alice)
  10. self.sub.subscription_id = "test-id"
  11. self.sub.customer_id = "test-customer-id"
  12. self.sub.save()
  13. self.tx = Mock()
  14. self.tx.id = "abc123"
  15. self.tx.customer_details.id = "test-customer-id"
  16. self.tx.created_at = now()
  17. self.tx.currency_iso_code = "USD"
  18. self.tx.amount = 5
  19. self.tx.subscription_details.billing_period_start_date = now()
  20. self.tx.subscription_details.billing_period_end_date = now()
  21. @patch("hc.payments.views.braintree")
  22. def test_it_works(self, mock_braintree):
  23. mock_braintree.Transaction.find.return_value = self.tx
  24. self.client.login(username="[email protected]", password="password")
  25. r = self.client.get("/invoice/pdf/abc123/")
  26. self.assertTrue(six.b("ABC123") in r.content)
  27. self.assertTrue(six.b("[email protected]") in r.content)
  28. @patch("hc.payments.views.braintree")
  29. def test_it_checks_customer_id(self, mock_braintree):
  30. tx = Mock()
  31. tx.id = "abc123"
  32. tx.customer_details.id = "test-another-customer-id"
  33. tx.created_at = None
  34. mock_braintree.Transaction.find.return_value = tx
  35. self.client.login(username="[email protected]", password="password")
  36. r = self.client.get("/invoice/pdf/abc123/")
  37. self.assertEqual(r.status_code, 403)
  38. @patch("hc.payments.views.braintree")
  39. def test_it_shows_company_data(self, mock_braintree):
  40. self.profile.bill_to = "Alice and Partners"
  41. self.profile.save()
  42. mock_braintree.Transaction.find.return_value = self.tx
  43. self.client.login(username="[email protected]", password="password")
  44. r = self.client.get("/invoice/pdf/abc123/")
  45. self.assertTrue(six.b("Alice and Partners") in r.content)