Exemplo n.º 1
0
    def test_keep_active_trials(self):
        """Recent trials are not expired."""
        stdout = StringIO()
        trialing = Account.AccountStatus.TRIALING
        account = AccountFactory(status=trialing, user__date_joined=timezone.now())
        command = Command(stdout=stdout)

        command.handle()

        account.refresh_from_db()
        assert account.status == Account.AccountStatus.TRIALING
Exemplo n.º 2
0
    def test_account_active(self):
        """An account is set to the active state."""
        account = AccountFactory(status=Account.AccountStatus.TRIALING)
        event = EventFactory(
            data={"object": {
                "client_reference_id": str(account.id)
            }})

        handle_checkout_session_completed(event)

        account.refresh_from_db()
        assert account.status == Account.AccountStatus.ACTIVE
Exemplo n.º 3
0
    def test_other_statuses_not_expired(self):
        """Only TRIALING is marked as expired."""
        stdout = StringIO()
        active = Account.AccountStatus.ACTIVE
        account = AccountFactory(
            status=active,
            user__date_joined=timezone.now()
            - datetime.timedelta(days=constants.TRIAL_DAYS + 5),
        )
        command = Command(stdout=stdout)

        command.handle()

        account.refresh_from_db()
        assert account.status == Account.AccountStatus.ACTIVE
Exemplo n.º 4
0
    def test_expires_trials(self):
        """Old trials are marked as expired."""
        stdout = StringIO()
        trialing = Account.AccountStatus.TRIALING
        account = AccountFactory(
            status=trialing,
            user__date_joined=timezone.now()
            - datetime.timedelta(days=constants.TRIAL_DAYS + 5),
        )
        command = Command(stdout=stdout)

        command.handle()

        account.refresh_from_db()
        assert account.status == Account.AccountStatus.TRIAL_EXPIRED
Exemplo n.º 5
0
    def test_non_trialing(self):
        """Non-TRIALING accounts do not see the banner."""
        account = AccountFactory(status=Account.AccountStatus.ACTIVE)
        request = self.rf.get("/")
        request.account = account
        context = {"request": request}

        context = accounts_tags.trial_banner(context)

        assert not context["display_banner"]
Exemplo n.º 6
0
    def test_creates_session(self, mock_stripe):
        """The gateway creates a checkout session for the price."""
        account = AccountFactory()
        mock_stripe.checkout.Session.create.return_value = {"id": "fake_session_id"}
        gateway = StripeGateway()

        session_id = gateway.create_checkout_session("price_fake_id", account)

        assert session_id == "fake_session_id"
        kwargs = mock_stripe.checkout.Session.create.call_args.kwargs
        assert kwargs["customer_email"] == account.email
        assert kwargs["client_reference_id"] == str(account.id)
        assert "subscription_data" in kwargs
Exemplo n.º 7
0
    def test_display_banner(self):
        """An old TRIALING account displays the trial banner."""
        old_trial_start = timezone.now() - datetime.timedelta(days=constants.TRIAL_DAYS)
        account = AccountFactory(
            status=Account.AccountStatus.TRIALING, user__date_joined=old_trial_start
        )
        request = self.rf.get("/")
        request.account = account
        context = {"request": request}

        context = accounts_tags.trial_banner(context)

        assert context["display_banner"]
Exemplo n.º 8
0
    def test_creates_billing_portal_session(self, mock_stripe):
        """The gateway creates a URL to a billing portal session."""
        account = AccountFactory()
        customer = CustomerFactory(email=account.email)
        mock_session = mock.Mock()
        mock_session.url = "/portal"
        mock_stripe.billing_portal.Session.create.return_value = mock_session
        gateway = StripeGateway()

        url = gateway.create_billing_portal_session(account)

        assert url == "/portal"
        kwargs = mock_stripe.billing_portal.Session.create.call_args.kwargs
        assert kwargs["customer"] == customer.id
        assert self.reverse("settings:dashboard") in kwargs["return_url"]
Exemplo n.º 9
0
    def test_no_trial_in_stripe_limits(self, mock_stripe):
        """A trial is not added to the session within Stripe's limit.

        Stripe does not permit a trial unless there are at least 48 hours from now.
        """
        too_close_date = timezone.now() - datetime.timedelta(
            days=constants.TRIAL_DAYS - 1  # Set the user 24 hours from trial ending.
        )
        account = AccountFactory(user__date_joined=too_close_date)
        gateway = StripeGateway()

        gateway.create_checkout_session("price_fake_id", account)

        kwargs = mock_stripe.checkout.Session.create.call_args.kwargs
        assert "subscription_data" not in kwargs
Exemplo n.º 10
0
    def test_factory(self):
        account = AccountFactory()

        assert account.user is not None
        assert account.status == Account.AccountStatus.TRIALING
Exemplo n.º 11
0
    def test_trial_end(self):
        """The account has a trial end date."""
        account = AccountFactory()

        assert account.trial_end == account.user.date_joined + datetime.timedelta(
            days=constants.TRIAL_DAYS)
Exemplo n.º 12
0
    def test_email(self):
        """The account proxies the account holder's email address."""
        account = AccountFactory()

        assert account.email == account.user.email