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.

65 lines
2.3 KiB

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