def test_subscribe_view_get_template_names_override_confirmation_false():
    """Tests get_template_names override works when confirmation is false."""
    view = views.SubscribeView()
    view.confirmation = False
    template = view.get_template_names()

    assert template == ['subscriptions/subscribe_preview.html']
def test_subscribe_view_hide_form():
    """Tests that hide_form converts all widgets to hidden inputs."""
    view = views.SubscribeView()
    form = forms.PaymentForm()
    hidden_form = view.hide_form(form)

    for _, field in hidden_form.fields.items():
        assert isinstance(field.widget, HiddenInput)
Ejemplo n.º 3
0
def test_subscribe_view_get_success_url():
    """Tests get_success_url method works as expected."""
    view = views.SubscribeView()
    success_url = view.get_success_url(
        transaction_id='11111111-1111-4111-a111-111111111111')

    assert success_url == (
        '/subscribe/thank-you/11111111-1111-4111-a111-111111111111/')
def test_subscribe_view_setup_subscription_no_group(dfs):
    """Tests that setup handles subscriptions with no groups."""
    group, _ = Group.objects.get_or_create(name='test')
    user_count = group.user_set.all().count()

    view = views.SubscribeView()
    view.subscription_plan = dfs.plan
    view.setup_subscription(dfs.user, dfs.cost)

    assert dfs.user not in group.user_set.all()
    assert group.user_set.all().count() == user_count
def test_subscribe_view_setup_subscription_user_subscription(dfs):
    """Tests that user subscription entry is setup properly."""
    sub_count = models.UserSubscription.objects.all().count()
    group, _ = Group.objects.get_or_create(name='test')
    dfs.plan.group = group

    view = views.SubscribeView()
    view.subscription_plan = dfs.plan
    view.setup_subscription(dfs.user, dfs.cost)

    assert models.UserSubscription.objects.all().count() == sub_count + 1
Ejemplo n.º 6
0
def test_subscribe_view_record_transaction_with_date(dfs):
    """Tests handling of record_transaction with date provided."""
    transaction_count = models.SubscriptionTransaction.objects.all().count()
    transaction_date = datetime(2018, 1, 2, 1, 1, 1)

    view = views.SubscribeView()
    transaction = view.record_transaction(dfs.subscription, transaction_date)

    assert models.SubscriptionTransaction.objects.all().count() == (
        transaction_count + 1)
    assert transaction.date_transaction == transaction_date
def test_subscribe_view_setup_subscription_user_group(dfs):
    """Tests that user is properly added to group."""
    group, _ = Group.objects.get_or_create(name='test')
    user_count = group.user_set.all().count()
    dfs.plan.group = group

    view = views.SubscribeView()
    view.subscription_plan = dfs.plan
    view.setup_subscription(dfs.user, dfs.cost)

    assert dfs.user in group.user_set.all()
    assert group.user_set.all().count() == user_count + 1
Ejemplo n.º 8
0
def test_subscribe_view_record_transaction_without_date(dfs):
    """Tests handling of record_transaction without providing a date.

        Patching the timezone module to ensure consistent test results.
    """
    transaction_count = models.SubscriptionTransaction.objects.all().count()

    view = views.SubscribeView()
    transaction = view.record_transaction(dfs.subscription)

    assert models.SubscriptionTransaction.objects.all().count() == (
        transaction_count + 1)
    assert transaction.date_transaction == datetime(2018, 1, 1, 1, 1, 1)
def test_subscribe_view_record_transaction_with_date(django_user_model):
    """Tests handling of record_transaction with date provided."""
    transaction_count = models.SubscriptionTransaction.objects.all().count()

    user = django_user_model.objects.create_user(username='******', password='******')
    subscription = create_subscription(user)
    transaction_date = datetime(2018, 1, 2, 1, 1, 1)

    view = views.SubscribeView()
    transaction = view.record_transaction(subscription, transaction_date)

    assert models.SubscriptionTransaction.objects.all().count() == (
        transaction_count + 1)
    assert transaction.date_transaction == transaction_date
def test_subscribe_view_setup_subscription_no_group(django_user_model):
    """Tests that setup handles subscriptions with no groups."""
    user = django_user_model.objects.create_user(username='******', password='******')
    group, _ = Group.objects.get_or_create(name='test')
    user_count = group.user_set.all().count()

    plan = create_plan()
    cost = create_cost(plan=plan)

    view = views.SubscribeView()
    view.subscription_plan = plan
    view.setup_subscription(user, cost.id)

    assert user not in group.user_set.all()
    assert group.user_set.all().count() == user_count
def test_subscribe_view_setup_subscription_user_group(django_user_model):
    """Tests that user is properly added to group."""
    user = django_user_model.objects.create_user(username='******', password='******')
    group, _ = Group.objects.get_or_create(name='test')
    user_count = group.user_set.all().count()

    plan = create_plan()
    plan.group = group
    cost = create_cost(plan=plan)

    view = views.SubscribeView()
    view.subscription_plan = plan
    view.setup_subscription(user, cost.id)

    assert user in group.user_set.all()
    assert group.user_set.all().count() == user_count + 1
def test_subscribe_view_record_transaction_without_date(django_user_model):
    """Tests handling of record_transaction without providing a date.

        Patching the timezone module to ensure consistent test results.
    """
    transaction_count = models.SubscriptionTransaction.objects.all().count()

    user = django_user_model.objects.create_user(username='******', password='******')
    subscription = create_subscription(user)

    view = views.SubscribeView()
    transaction = view.record_transaction(subscription)

    assert models.SubscriptionTransaction.objects.all().count() == (
        transaction_count + 1)
    assert transaction.date_transaction == datetime(2018, 1, 1, 1, 1, 1)
def test_subscribe_view_setup_subscription_user_subscription(
        django_user_model):
    """Tests that user subscription entry is setup properly."""
    sub_count = models.UserSubscription.objects.all().count()

    user = django_user_model.objects.create_user(username='******', password='******')
    group, _ = Group.objects.get_or_create(name='test')

    plan = create_plan()
    plan.group = group
    cost = create_cost(plan=plan)

    view = views.SubscribeView()
    view.subscription_plan = plan
    view.setup_subscription(user, cost.id)

    assert models.UserSubscription.objects.all().count() == sub_count + 1
def test_cancel_view_get_success_url():
    """Tests that get_success_url works properly."""
    view = views.SubscribeView()
    assert view.get_success_url() == '/subscriptions/'
def test_subscribe_view_get_success_url():
    """Tests get_success_url method works as expected."""
    view = views.SubscribeView()
    success_url = view.get_success_url()

    assert success_url == '/subscriptions/'