diff --git a/hc/payments/tests/test_billing.py b/hc/payments/tests/test_billing.py new file mode 100644 index 00000000..77e1374a --- /dev/null +++ b/hc/payments/tests/test_billing.py @@ -0,0 +1,29 @@ +from django.contrib.auth.models import User +from django.test import TestCase +from hc.payments.models import Subscription +from mock import Mock, patch + + +class BillingTestCase(TestCase): + + def setUp(self): + self.alice = User(username="alice") + self.alice.set_password("password") + self.alice.save() + + self.sub = Subscription(user=self.alice) + self.sub.subscription_id = "test-id" + self.sub.customer_id = "test-customer-id" + self.sub.save() + + @patch("hc.payments.views.braintree") + def test_it_works(self, mock_braintree): + + m1 = Mock(id="abc123", amount=123) + m2 = Mock(id="def456", amount=456) + mock_braintree.Transaction.search.return_value = [m1, m2] + + self.client.login(username="alice", password="password") + r = self.client.get("/billing/") + self.assertContains(r, "123") + self.assertContains(r, "def456") diff --git a/hc/payments/tests/test_cancel_plan.py b/hc/payments/tests/test_cancel_plan.py new file mode 100644 index 00000000..9335a9df --- /dev/null +++ b/hc/payments/tests/test_cancel_plan.py @@ -0,0 +1,28 @@ +from django.contrib.auth.models import User +from django.test import TestCase +from hc.payments.models import Subscription +from mock import patch + + +class CancelPlanTestCase(TestCase): + + def setUp(self): + self.alice = User(username="alice") + self.alice.set_password("password") + self.alice.save() + + self.sub = Subscription(user=self.alice) + self.sub.subscription_id = "test-id" + self.sub.plan_id = "P5" + self.sub.save() + + @patch("hc.payments.views.braintree") + def test_it_works(self, mock_braintree): + + self.client.login(username="alice", password="password") + r = self.client.post("/pricing/cancel_plan/") + self.assertRedirects(r, "/pricing/") + + self.sub.refresh_from_db() + self.assertEqual(self.sub.subscription_id, "") + self.assertEqual(self.sub.plan_id, "") diff --git a/hc/payments/tests/test_invoice.py b/hc/payments/tests/test_invoice.py new file mode 100644 index 00000000..e73120df --- /dev/null +++ b/hc/payments/tests/test_invoice.py @@ -0,0 +1,43 @@ +from django.contrib.auth.models import User +from django.test import TestCase +from hc.payments.models import Subscription +from mock import Mock, patch + + +class InvoiceTestCase(TestCase): + + def setUp(self): + self.alice = User(username="alice") + self.alice.set_password("password") + self.alice.save() + + self.sub = Subscription(user=self.alice) + self.sub.subscription_id = "test-id" + self.sub.customer_id = "test-customer-id" + self.sub.save() + + @patch("hc.payments.views.braintree") + def test_it_works(self, mock_braintree): + + tx = Mock() + tx.id = "abc123" + tx.customer_details.id = "test-customer-id" + tx.created_at = None + mock_braintree.Transaction.find.return_value = tx + + self.client.login(username="alice", password="password") + r = self.client.get("/invoice/abc123/") + self.assertContains(r, "ABC123") # tx.id in uppercase + + @patch("hc.payments.views.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", password="password") + r = self.client.get("/invoice/abc123/") + self.assertEqual(r.status_code, 403)