0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-15 09:24:11 +00:00
healthchecks_healthchecks/hc/payments/tests/test_pdf_invoice.py
2018-01-09 13:31:43 +02:00

66 lines
2.3 KiB
Python

from mock import Mock, patch
from unittest import skipIf
from django.utils.timezone import now
from hc.payments.models import Subscription
from hc.test import BaseTestCase
import six
try:
import reportlab
except ImportError:
reportlab = None
class PdfInvoiceTestCase(BaseTestCase):
def setUp(self):
super(PdfInvoiceTestCase, self).setUp()
self.sub = Subscription(user=self.alice)
self.sub.subscription_id = "test-id"
self.sub.customer_id = "test-customer-id"
self.sub.save()
self.tx = Mock()
self.tx.id = "abc123"
self.tx.customer_details.id = "test-customer-id"
self.tx.created_at = now()
self.tx.currency_iso_code = "USD"
self.tx.amount = 5
self.tx.subscription_details.billing_period_start_date = now()
self.tx.subscription_details.billing_period_end_date = now()
@skipIf(reportlab is None, "reportlab not installed")
@patch("hc.payments.models.braintree")
def test_it_works(self, mock_braintree):
mock_braintree.Transaction.find.return_value = self.tx
self.client.login(username="alice@example.org", password="password")
r = self.client.get("/invoice/pdf/abc123/")
self.assertTrue(six.b("ABC123") in r.content)
self.assertTrue(six.b("alice@example.org") in r.content)
@patch("hc.payments.models.braintree")
def test_it_checks_customer_id(self, mock_braintree):
tx = Mock()
tx.id = "abc123"
tx.customer_details.id = "test-another-customer-id"
tx.created_at = None
mock_braintree.Transaction.find.return_value = tx
self.client.login(username="alice@example.org", password="password")
r = self.client.get("/invoice/pdf/abc123/")
self.assertEqual(r.status_code, 403)
@skipIf(reportlab is None, "reportlab not installed")
@patch("hc.payments.models.braintree")
def test_it_shows_company_data(self, mock_braintree):
self.profile.bill_to = "Alice and Partners"
self.profile.save()
mock_braintree.Transaction.find.return_value = self.tx
self.client.login(username="alice@example.org", password="password")
r = self.client.get("/invoice/pdf/abc123/")
self.assertTrue(six.b("Alice and Partners") in r.content)