def test_outstanding_payment_plans_exclude_deleted():
    obj = ObjectPaymentPlanFactory(
        content_object=ContactFactory(),
        deleted=True,
    )
    ObjectPaymentPlanInstalmentFactory(object_payment_plan=obj)
    ObjectPaymentPlanInstalmentFactory(
        object_payment_plan=ObjectPaymentPlanFactory(
            content_object=ContactFactory(),
        ),
    )
    assert 1 == ObjectPaymentPlan.objects.outstanding_payment_plans.count()
def test_outstanding_payment_plans_exclude_success():
    ObjectPaymentPlanInstalmentFactory(
        object_payment_plan=ObjectPaymentPlanFactory(
            content_object=ContactFactory(),
        ),
    )
    ObjectPaymentPlanInstalmentFactory(
        state=CheckoutState.objects.success,
        object_payment_plan=ObjectPaymentPlanFactory(
            content_object=ContactFactory(),
        ),
    )
    assert 1 == ObjectPaymentPlan.objects.outstanding_payment_plans.count()
def test_report_card_expiry_dates():
    object_payment_plan = ObjectPaymentPlanFactory(
        content_object=ContactFactory()
    )
    ObjectPaymentPlanInstalmentFactory(object_payment_plan=object_payment_plan)
    obj = ObjectPaymentPlanInstalmentFactory(
        object_payment_plan=ObjectPaymentPlanFactory(
            content_object=ContactFactory()
        ),
    )
    CustomerFactory(
        email=obj.object_payment_plan.content_object.checkout_email
    )
    ObjectPaymentPlan.objects.report_card_expiry_dates
def test_refresh_card_expiry_dates_refreshed():
    """Customer card already marked for 'refresh', so don't send an email."""
    with mock.patch('stripe.Customer.retrieve') as mock_retrieve:
        mock_retrieve.return_value = {
            'default_card': '1234',
            'cards': {
                'data': [
                    {
                        'id': '1234',
                        'exp_month': '8',
                        'exp_year': '1986',
                    },
                ],
            },
        }
        obj = ObjectPaymentPlanFactory(content_object=ContactFactory())
        ObjectPaymentPlanInstalmentFactory(
            object_payment_plan=obj
        )
        ObjectPaymentPlanInstalmentFactory(
            object_payment_plan=obj,
            due=date.today() + relativedelta(months=+1),
        )
        customer = CustomerFactory(
            email=obj.content_object.checkout_email,
            refresh=True,
        )
        ObjectPaymentPlan.objects.refresh_card_expiry_dates()
        customer.refresh_from_db()
        assert True == customer.refresh
        # check we didn't send a notification email
        assert 0 == Message.objects.count()
Ejemplo n.º 5
0
 def test_object_payment_plan_instalment_paid(self):
     obj = ObjectPaymentPlanInstalmentFactory(
         object_payment_plan=ObjectPaymentPlanFactory(
             content_object=ContactFactory(), ), )
     self.assert_staff_only(
         reverse('checkout.object.payment.plan.instalment.paid',
                 args=[obj.pk]))
def test_outstanding_payment_plans_filter_two():
    obj = ObjectPaymentPlanFactory(content_object=ContactFactory())
    ObjectPaymentPlanInstalmentFactory(
        object_payment_plan=obj
    )
    ObjectPaymentPlanInstalmentFactory(
        object_payment_plan=obj,
        due=date.today() + relativedelta(months=+1),
    )
    assert 1 == ObjectPaymentPlan.objects.outstanding_payment_plans.count()
def test_save_not_in_use():
    ObjectPaymentPlanFactory(
        payment_plan=PaymentPlanFactory(),
        content_object=ContactFactory(),
    )
    obj = PaymentPlanFactory()
    obj.name = 'Another Name'
    obj.save()
    obj.refresh_from_db()
    assert obj.name == 'Another Name'
def test_save_in_use():
    obj = PaymentPlanFactory()
    ObjectPaymentPlanFactory(
        payment_plan=obj,
        content_object=ContactFactory(),
    )
    obj.name = 'Another Name'
    with pytest.raises(CheckoutError) as e:
        obj.save()
    assert 'Payment plan in use.  Cannot be updated.' in str(e.value)
def test_create_instalments_corrupt():
    object_payment_plan = ObjectPaymentPlanFactory(
        content_object=ContactFactory()
    )
    obj = ObjectPaymentPlanInstalmentFactory(
        object_payment_plan=object_payment_plan,
        count=2,
    )
    with pytest.raises(CheckoutError) as e:
        obj.object_payment_plan.create_instalments()
    assert 'no deposit record' in str(e.value)
def test_refresh_card_expiry_dates():
    MailTemplateFactory(slug=Customer.MAIL_TEMPLATE_CARD_EXPIRY)
    with mock.patch('stripe.Customer.retrieve') as mock_retrieve:
        mock_retrieve.return_value = {
            'default_card': '1234',
            'cards': {
                'data': [
                    {
                        'id': '1234',
                        'exp_month': '8',
                        'exp_year': '1986',
                    },
                ],
            },
        }
        obj = ObjectPaymentPlanFactory(content_object=ContactFactory())
        ObjectPaymentPlanInstalmentFactory(
            object_payment_plan=obj
        )
        ObjectPaymentPlanInstalmentFactory(
            object_payment_plan=obj,
            due=date.today() + relativedelta(months=+1),
        )
        customer = CustomerFactory(
            email=obj.content_object.checkout_email
        )
        ObjectPaymentPlan.objects.refresh_card_expiry_dates()
        customer.refresh_from_db()
        assert True == customer.refresh
        # check email template context
        assert 1 == Message.objects.count()
        message = Message.objects.first()
        assert 1 == message.mail_set.count()
        mail = message.mail_set.first()
        assert 1 == mail.mailfield_set.count()
        assert {
            'name': customer.name,
        } == {f.key: f.value for f in mail.mailfield_set.all()}
def test_str():
    str(ObjectPaymentPlanFactory(content_object=ContactFactory()))
def test_factory():
    ObjectPaymentPlanFactory(content_object=ContactFactory())
def test_create_instalments_no_deposit():
    obj = ObjectPaymentPlanFactory(content_object=ContactFactory())
    with pytest.raises(CheckoutError) as e:
        obj.create_instalments()
    assert 'no deposit/instalment record' in str(e.value)
Ejemplo n.º 14
0
def test_create_instalments_no_deposit():
    obj = ObjectPaymentPlanFactory(content_object=ContactFactory())
    with pytest.raises(CheckoutError) as e:
        obj.create_instalments()
    assert "no deposit/instalment record" in str(e.value)