def test_it_cancels(self, mock):
        self._setup_mock(mock)

        self.sub = Subscription(user=self.alice)
        self.sub.subscription_id = "test-id"
        self.sub.plan_id = "P20"
        self.sub.plan_name = "Business ($20/mo)"
        self.sub.save()

        self.profile.sms_limit = 1
        self.profile.sms_sent = 1
        self.profile.save()

        r = self.run_update("")
        self.assertRedirects(r, "/accounts/profile/billing/")
        self.assertContains(r, "Your billing plan has been updated!")

        # Subscription should be cleared
        sub = Subscription.objects.get(user=self.alice)
        self.assertEqual(sub.subscription_id, "")
        self.assertEqual(sub.plan_id, "")
        self.assertEqual(sub.plan_name, "")

        # User's profile should have standard limits
        self.profile.refresh_from_db()
        self.assertEqual(self.profile.ping_log_limit, 100)
        self.assertEqual(self.profile.check_limit, 20)
        self.assertEqual(self.profile.team_limit, 2)
        self.assertEqual(self.profile.sms_limit, 5)

        self.assertTrue(mock.Subscription.cancel.called)
Beispiel #2
0
def billing(request):
    # Don't use Subscription.objects.for_user method here, so a
    # subscription object is not created just by viewing a page.
    sub = Subscription.objects.filter(user_id=request.user.id).first()
    if sub is None:
        sub = Subscription(user=request.user)

    send_invoices_status = "default"
    if request.method == "POST":
        form = InvoiceEmailingForm(request.POST)
        if form.is_valid():
            sub = Subscription.objects.for_user(request.user)
            form.update_subscription(sub)
            send_invoices_status = "success"

    ctx = {
        "page": "billing",
        "profile": request.profile,
        "sub": sub,
        "send_invoices_status": send_invoices_status,
        "set_plan_status": "default",
        "address_status": "default",
        "payment_method_status": "default",
    }

    if "set_plan_status" in request.session:
        ctx["set_plan_status"] = request.session.pop("set_plan_status")

    if "address_status" in request.session:
        ctx["address_status"] = request.session.pop("address_status")

    if "payment_method_status" in request.session:
        ctx["payment_method_status"] = request.session.pop("payment_method_status")

    return render(request, "accounts/billing.html", ctx)
Beispiel #3
0
    def test_it_cancels(self, mock):
        self._setup_mock(mock)

        self.sub = Subscription(user=self.alice)
        self.sub.subscription_id = "test-id"
        self.sub.plan_id = "P20"
        self.sub.save()

        self.profile.sms_limit = 1
        self.profile.sms_sent = 1
        self.profile.save()

        r = self.run_set_plan("")
        self.assertRedirects(r, "/accounts/profile/billing/")

        # Subscription should be cleared
        sub = Subscription.objects.get(user=self.alice)
        self.assertEqual(sub.subscription_id, "")
        self.assertEqual(sub.plan_id, "")

        # User's profile should have standard limits
        self.profile.refresh_from_db()
        self.assertEqual(self.profile.ping_log_limit, 100)
        self.assertEqual(self.profile.check_limit, 20)
        self.assertEqual(self.profile.team_limit, 2)
        self.assertEqual(self.profile.sms_limit, 0)

        assert mock.Subscription.cancel.called
    def setUp(self):
        super(CancelPlanTestCase, self).setUp()
        self.alice = User(username="******", email="*****@*****.**")
        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()
    def test_it_cancels_previous_subscription(self, mock):
        self._setup_mock(mock)

        sub = Subscription(user=self.alice)
        sub.subscription_id = "prev-sub"
        sub.save()

        r = self.run_create_plan()
        self.assertRedirects(r, "/pricing/")
        assert mock.Subscription.cancel.called
Beispiel #6
0
    def setUp(self):
        super(BillingTestCase, self).setUp()
        self.alice = User(username="******", email="*****@*****.**")
        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()
Beispiel #7
0
    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")
    def test_it_cancels_previous_subscription(self, mock):
        self._setup_mock(mock)

        sub = Subscription(user=self.alice)
        sub.subscription_id = "prev-sub"
        sub.save()

        r = self.run_update()
        self.assertRedirects(r, "/accounts/profile/billing/")
        self.assertTrue(mock.Subscription.cancel.called)
Beispiel #9
0
    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.save()
Beispiel #10
0
    def test_it_shows_active_plan(self):
        self.sub = Subscription(user=self.alice)
        self.sub.subscription_id = "test-id"
        self.sub.plan_id = "P5"
        self.sub.save()

        self.client.login(username="******", password="******")

        r = self.client.get("/pricing/")
        self.assertContains(r, "Standard (monthly)", status_code=200)
Beispiel #11
0
    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/")
Beispiel #12
0
    def test_it_works(self, mock_braintree):
        sub = Subscription(user=self.alice)
        sub.customer_id = "fake-customer-id"
        sub.save()

        mock_braintree.ClientToken.generate.return_value = "test-token"
        self.client.login(username="******", password="******")

        r = self.client.get("/pricing/token/")
        self.assertContains(r, "test-token", status_code=200)

        # A subscription object should have been created
        assert Subscription.objects.count() == 1
Beispiel #13
0
    def test_it_shows_active_plan(self):
        self.sub = Subscription(user=self.alice)
        self.sub.subscription_id = "test-id"
        self.sub.plan_id = "P20"
        self.sub.plan_name = "Business ($20 / month)"
        self.sub.save()

        self.client.login(username="******", password="******")

        r = self.client.get("/pricing/")
        self.assertContains(r, "Business ($20 / month)", status_code=200)

        r = self.client.get("/projects/%s/pricing/" % self.project.code)
        self.assertContains(r, "Business ($20 / month)", status_code=200)
Beispiel #14
0
    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()
Beispiel #15
0
    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")
 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()
Beispiel #17
0
 def setUp(self):
     super(BillingHistoryTestCase, self).setUp()
     self.sub = Subscription(user=self.alice)
     self.sub.subscription_id = "test-id"
     self.sub.customer_id = "test-customer-id"
     self.sub.save()
 def setUp(self):
     super().setUp()
     self.sub = Subscription(user=self.alice)
     self.sub.subscription_id = "test-id"
     self.sub.customer_id = "test-customer-id"
     self.sub.save()