forked from GithubBackups/healthchecks
runserver and tests work without reportlab installed.
This commit is contained in:
parent
a174aa0faa
commit
80523787c3
@ -1,20 +1,22 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
from reportlab.lib.pagesizes import A4
|
try:
|
||||||
from reportlab.lib.units import inch
|
from reportlab.lib.pagesizes import A4
|
||||||
from reportlab.pdfgen import canvas
|
from reportlab.lib.units import inch
|
||||||
|
from reportlab.pdfgen.canvas import Canvas
|
||||||
|
W, H = A4
|
||||||
W, H = A4
|
except ImportError:
|
||||||
|
# Don't crash if reportlab is not installed.
|
||||||
|
Canvas = object
|
||||||
|
|
||||||
|
|
||||||
def f(dt):
|
def f(dt):
|
||||||
return dt.strftime("%b. %-d, %Y")
|
return dt.strftime("%b. %-d, %Y")
|
||||||
|
|
||||||
|
|
||||||
class PdfInvoice(canvas.Canvas):
|
class PdfInvoice(Canvas):
|
||||||
def __init__(self, fileobj):
|
def __init__(self, fileobj):
|
||||||
canvas.Canvas.__init__(self, fileobj, pagesize=A4, pageCompression=0)
|
Canvas.__init__(self, fileobj, pagesize=A4, pageCompression=0)
|
||||||
self.head_y = H - inch * 0.5
|
self.head_y = H - inch * 0.5
|
||||||
|
|
||||||
def linefeed(self):
|
def linefeed(self):
|
||||||
@ -52,7 +54,6 @@ class PdfInvoice(canvas.Canvas):
|
|||||||
self.head_y -= inch / 8
|
self.head_y -= inch / 8
|
||||||
|
|
||||||
def render(self, tx, bill_to):
|
def render(self, tx, bill_to):
|
||||||
width, height = A4
|
|
||||||
invoice_id = "MS-HC-%s" % tx.id.upper()
|
invoice_id = "MS-HC-%s" % tx.id.upper()
|
||||||
self.setTitle(invoice_id)
|
self.setTitle(invoice_id)
|
||||||
|
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
from mock import Mock, patch
|
from mock import Mock, patch
|
||||||
|
from unittest import skipIf
|
||||||
|
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from hc.payments.models import Subscription
|
from hc.payments.models import Subscription
|
||||||
from hc.test import BaseTestCase
|
from hc.test import BaseTestCase
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
try:
|
||||||
|
import reportlab
|
||||||
|
except ImportError:
|
||||||
|
reportlab = None
|
||||||
|
|
||||||
|
|
||||||
class PdfInvoiceTestCase(BaseTestCase):
|
class PdfInvoiceTestCase(BaseTestCase):
|
||||||
|
|
||||||
@ -24,9 +30,9 @@ class PdfInvoiceTestCase(BaseTestCase):
|
|||||||
self.tx.subscription_details.billing_period_start_date = now()
|
self.tx.subscription_details.billing_period_start_date = now()
|
||||||
self.tx.subscription_details.billing_period_end_date = now()
|
self.tx.subscription_details.billing_period_end_date = now()
|
||||||
|
|
||||||
|
@skipIf(reportlab is None, "reportlab not installed")
|
||||||
@patch("hc.payments.views.braintree")
|
@patch("hc.payments.views.braintree")
|
||||||
def test_it_works(self, mock_braintree):
|
def test_it_works(self, mock_braintree):
|
||||||
|
|
||||||
mock_braintree.Transaction.find.return_value = self.tx
|
mock_braintree.Transaction.find.return_value = self.tx
|
||||||
|
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
@ -47,6 +53,7 @@ class PdfInvoiceTestCase(BaseTestCase):
|
|||||||
r = self.client.get("/invoice/pdf/abc123/")
|
r = self.client.get("/invoice/pdf/abc123/")
|
||||||
self.assertEqual(r.status_code, 403)
|
self.assertEqual(r.status_code, 403)
|
||||||
|
|
||||||
|
@skipIf(reportlab is None, "reportlab not installed")
|
||||||
@patch("hc.payments.views.braintree")
|
@patch("hc.payments.views.braintree")
|
||||||
def test_it_shows_company_data(self, mock_braintree):
|
def test_it_shows_company_data(self, mock_braintree):
|
||||||
self.profile.bill_to = "Alice and Partners"
|
self.profile.bill_to = "Alice and Partners"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user