class CancelPlanTestCase(BaseTestCase): def setUp(self): super(CancelPlanTestCase, self).setUp() self.sub = Subscription(user=self.alice) self.sub.subscription_id = "test-id" self.sub.plan_id = "P5" self.sub.save() self.profile.ping_log_limit = 1000 self.profile.check_limit = 500 self.profile.sms_limit = 50 self.profile.save() @patch("hc.payments.models.braintree") def test_it_works(self, mock_braintree): self.client.login(username="******", 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, "") # User's profile should have standard limits profile = Profile.objects.get(user=self.alice) self.assertEqual(profile.ping_log_limit, 100) self.assertEqual(profile.check_limit, 20) self.assertEqual(profile.sms_limit, 0) self.assertFalse(profile.team_access_allowed)
class CancelPlanTestCase(BaseTestCase): def setUp(self): super(CancelPlanTestCase, self).setUp() 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="******", 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, "")
class CancelPlanTestCase(BaseTestCase): def setUp(self): super(CancelPlanTestCase, self).setUp() 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="******", 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, "")
class AddressTestCase(BaseTestCase): @patch("hc.payments.models.braintree") def test_it_retrieves_address(self, mock): mock.Address.find.return_value = {"company": "FooCo"} self.sub = Subscription(user=self.alice) self.sub.address_id = "aa" self.sub.save() self.client.login(username="******", password="******") r = self.client.get("/accounts/profile/billing/address/") self.assertContains(r, "FooCo") @patch("hc.payments.models.braintree") def test_it_creates_address(self, mock): mock.Address.create.return_value.is_success = True mock.Address.create.return_value.address.id = "bb" self.sub = Subscription(user=self.alice) self.sub.customer_id = "test-customer" self.sub.save() self.client.login(username="******", password="******") form = {"company": "BarCo"} r = self.client.post("/accounts/profile/billing/address/", form) self.assertRedirects(r, "/accounts/profile/billing/") self.sub.refresh_from_db() self.assertEqual(self.sub.address_id, "bb") @patch("hc.payments.models.braintree") def test_it_updates_address(self, mock): mock.Address.update.return_value.is_success = True self.sub = Subscription(user=self.alice) self.sub.customer_id = "test-customer" self.sub.address_id = "aa" self.sub.save() self.client.login(username="******", password="******") form = {"company": "BarCo"} r = self.client.post("/accounts/profile/billing/address/", form) self.assertRedirects(r, "/accounts/profile/billing/") @patch("hc.payments.models.braintree") def test_it_creates_customer(self, mock): mock.Address.create.return_value.is_success = True mock.Address.create.return_value.address.id = "bb" mock.Customer.create.return_value.is_success = True mock.Customer.create.return_value.customer.id = "test-customer-id" self.sub = Subscription(user=self.alice) self.sub.save() self.client.login(username="******", password="******") form = {"company": "BarCo"} self.client.post("/accounts/profile/billing/address/", form) self.sub.refresh_from_db() self.assertEqual(self.sub.customer_id, "test-customer-id")
class AddressTestCase(BaseTestCase): @patch("hc.payments.models.braintree") def test_it_retrieves_address(self, mock): mock.Address.find.return_value = {"company": "FooCo"} self.sub = Subscription(user=self.alice) self.sub.address_id = "aa" self.sub.save() self.client.login(username="******", password="******") r = self.client.get("/accounts/profile/billing/address/") self.assertContains(r, "FooCo") @patch("hc.payments.models.braintree") def test_it_creates_address(self, mock): mock.Address.create.return_value.is_success = True mock.Address.create.return_value.address.id = "bb" self.sub = Subscription(user=self.alice) self.sub.customer_id = "test-customer" self.sub.save() self.client.login(username="******", password="******") form = {"company": "BarCo"} r = self.client.post("/accounts/profile/billing/address/", form) self.assertRedirects(r, "/accounts/profile/billing/") self.sub.refresh_from_db() self.assertEqual(self.sub.address_id, "bb") @patch("hc.payments.models.braintree") def test_it_updates_address(self, mock): mock.Address.update.return_value.is_success = True self.sub = Subscription(user=self.alice) self.sub.customer_id = "test-customer" self.sub.address_id = "aa" self.sub.save() self.client.login(username="******", password="******") form = {"company": "BarCo"} r = self.client.post("/accounts/profile/billing/address/", form) self.assertRedirects(r, "/accounts/profile/billing/") @patch("hc.payments.models.braintree") def test_it_creates_customer(self, mock): mock.Address.create.return_value.is_success = True mock.Address.create.return_value.address.id = "bb" mock.Customer.create.return_value.is_success = True mock.Customer.create.return_value.customer.id = "test-customer-id" self.sub = Subscription(user=self.alice) self.sub.save() self.client.login(username="******", password="******") form = {"company": "BarCo"} self.client.post("/accounts/profile/billing/address/", form) self.sub.refresh_from_db() self.assertEqual(self.sub.customer_id, "test-customer-id")
class UpdatePaymentMethodTestCase(BaseTestCase): def _setup_mock(self, mock): """ Set up Braintree calls that the controller will use. """ mock.PaymentMethod.create.return_value.is_success = True mock.PaymentMethod.create.return_value.payment_method.token = "fake" @patch("hc.payments.models.braintree") def test_it_retrieves_paypal(self, mock): self._setup_mock(mock) mock.paypal_account.PayPalAccount = dict mock.credit_card.CreditCard = list mock.PaymentMethod.find.return_value = {"email": "*****@*****.**"} self.sub = Subscription(user=self.alice) self.sub.payment_method_token = "fake-token" self.sub.save() self.client.login(username="******", password="******") r = self.client.get("/accounts/profile/billing/payment_method/") self.assertContains(r, "*****@*****.**") @patch("hc.payments.models.braintree") def test_it_retrieves_cc(self, mock): self._setup_mock(mock) mock.paypal_account.PayPalAccount = list mock.credit_card.CreditCard = dict mock.PaymentMethod.find.return_value = {"masked_number": "1***2"} self.sub = Subscription(user=self.alice) self.sub.payment_method_token = "fake-token" self.sub.save() self.client.login(username="******", password="******") r = self.client.get("/accounts/profile/billing/payment_method/") self.assertContains(r, "1***2") @patch("hc.payments.models.braintree") def test_it_creates_payment_method(self, mock): self._setup_mock(mock) self.sub = Subscription(user=self.alice) self.sub.customer_id = "test-customer" self.sub.save() self.client.login(username="******", password="******") form = {"payment_method_nonce": "test-nonce"} r = self.client.post("/accounts/profile/billing/payment_method/", form) self.assertRedirects(r, "/accounts/profile/billing/") @patch("hc.payments.models.braintree") def test_it_creates_customer(self, mock): self._setup_mock(mock) mock.Customer.create.return_value.is_success = True mock.Customer.create.return_value.customer.id = "test-customer-id" self.sub = Subscription(user=self.alice) self.sub.save() self.client.login(username="******", password="******") form = {"payment_method_nonce": "test-nonce"} self.client.post("/accounts/profile/billing/payment_method/", form) self.sub.refresh_from_db() self.assertEqual(self.sub.customer_id, "test-customer-id") @patch("hc.payments.models.braintree") def test_it_updates_subscription(self, mock): self._setup_mock(mock) self.sub = Subscription(user=self.alice) self.sub.customer_id = "test-customer" self.sub.subscription_id = "fake-id" self.sub.save() mock.Customer.create.return_value.is_success = True mock.Customer.create.return_value.customer.id = "test-customer-id" self.client.login(username="******", password="******") form = {"payment_method_nonce": "test-nonce"} self.client.post("/accounts/profile/billing/payment_method/", form) self.assertTrue(mock.Subscription.update.called)