Beispiel #1
0
def test_pagarme_payment_absent_item(db, tag_as_mock, remove_tags_mock,
                                     status):
    payment = baker.make(PagarmePayment)
    baker.make(PagarmeNotification, status=status, payment=payment)
    checkout_domain.payment_handler_task(payment.id)
    assert tag_as_mock.called is False
    assert remove_tags_mock.called is False
Beispiel #2
0
def test_pagarme_payment_with_item_but_do_nothing_status(
        db, tag_as_mock, remove_tags_mock, status):
    payment = baker.make(PagarmePayment)
    baker.make(PagarmeNotification, status=status, payment=payment)
    baker.make(PagarmeItemConfig, payments=[payment])
    checkout_domain.payment_handler_task(payment.id)
    assert tag_as_mock.called is False
    assert remove_tags_mock.called is False
Beispiel #3
0
def test_pagarme_payment_refused(db, tag_as_mock, remove_tags_mock,
                                 logged_user, send_purchase_notification_mock):
    payment = baker.make(PagarmePayment, user=logged_user)
    baker.make(PagarmeNotification, status=facade.REFUSED, payment=payment)
    config = baker.make(PagarmeItemConfig, payments=[payment])
    checkout_domain.payment_handler_task(payment.id)
    assert remove_tags_mock.called is False
    tag_as_mock.assert_called_once_with(logged_user.email, logged_user.id,
                                        f'{config.slug}-refused')
    send_purchase_notification_mock.asser_called_once_with(payment.id)
Beispiel #4
0
def test_pagarme_payment_paid_credit_card(db, tag_as_mock, remove_tags_mock,
                                          promote_user_mock, logged_user):
    payment = mommy.make(PagarmePayment,
                         payment_method=facade.CREDIT_CARD,
                         user=logged_user)
    mommy.make(PagarmeNotification, status=facade.PAID, payment=payment)
    config = mommy.make(PagarmeItemConfig, payments=[payment])
    checkout_domain.payment_handler_task(payment.id)
    assert tag_as_mock.called is False
    assert remove_tags_mock.called is False
    promote_user_mock.assert_called_once_with(logged_user, config.slug)
Beispiel #5
0
def test_payment_tag_removed_after_payment(resp_logged_user, active_product_item, remove_tags_mock, logged_user,
                                           tag_as_mock,
                                           mocker):
    payment = django_pagarme_facade.find_payment_by_transaction(TRANSACTION_ID)
    baker.make(django_pagarme_facade.PagarmeNotification, status=django_pagarme_facade.PAID, payment=payment)
    promote_mock = mocker.patch('pythonpro.domain.checkout_domain._promote')
    checkout_domain.payment_handler_task(payment.id)
    remove_tags_mock.assert_called_once_with(
        logged_user.email, logged_user.id, f'{active_product_item.slug}-boleto', f'{active_product_item.slug}-refused'
    )
    promote_mock.assert_called_once_with(logged_user, payment.first_item_slug())
Beispiel #6
0
def test_subscription_creation(db, tag_as_mock, remove_tags_mock,
                               promote_user_mock, logged_user,
                               send_purchase_notification_mock, responses,
                               api_key, mock_email_marketing_facade):
    payment = baker.make(PagarmePayment,
                         payment_method=facade.BOLETO,
                         user=logged_user)
    cohort = baker.make(Cohort)
    baker.make(PagarmeNotification, status=facade.PAID, payment=payment)
    config = baker.make(PagarmeItemConfig, payments=[payment])
    subscription_type = baker.make(SubscriptionType, include_on_cohort=True)
    PaymentItemConfigToSubscriptionType.objects.create(
        payment_item=config, subscription_type=subscription_type)
    user_response = {
        'bio':
        None,
        'blocked':
        False,
        'email':
        logged_user.email,
        'enrollments': [],
        'full_name':
        logged_user.get_full_name(),
        'id':
        1,
        'memberships': [{
            'expire_date': '2200-01-01',
            'membership_level_id': 4424,
            'status': 'active'
        }],
        'profile_image_url':
        None,
        'unlimited':
        True
    }
    responses.add(
        responses.POST,
        f'https://memberkit.com.br/api/v1/users?api_key={api_key}',
    )
    responses.add(
        responses.GET,
        f'https://memberkit.com.br/api/v1/users/{logged_user.email}?api_key={api_key}',
        json=user_response)
    checkout_domain.payment_handler_task(payment.id)
    subscription = Subscription.objects.first()
    assert subscription is not None
    assert subscription.subscriber_id == payment.user_id
    assert subscription.status == Subscription.Status.ACTIVE
    assert subscription.payment_id == payment.id
    assert list(subscription.subscription_types.all()) == [subscription_type]
    assert subscription.responsible is None
    assert 'Criação como resposta de pagamento no Pagarme' in subscription.observation
    assert cohort.students.filter(id=logged_user.id).exists()
    assert mock_email_marketing_facade.call_count == 1
Beispiel #7
0
def test_pagarme_payment_paid_boleto(db, tag_as_mock, remove_tags_mock,
                                     promote_user_mock, logged_user):
    payment = mommy.make(PagarmePayment,
                         payment_method=facade.BOLETO,
                         user=logged_user)
    mommy.make(PagarmeNotification, status=facade.PAID, payment=payment)
    config = mommy.make(PagarmeItemConfig, payments=[payment])
    checkout_domain.payment_handler_task(payment.id)
    assert tag_as_mock.called is False
    remove_tags_mock.assert_called_once_with(logged_user.email, logged_user.id,
                                             f'{config.slug}-boleto')
    promote_user_mock.assert_called_once_with(logged_user, config.slug)
Beispiel #8
0
def test_pagarme_payment_paid_credit_card(db, tag_as_mock, remove_tags_mock,
                                          promote_user_mock, logged_user,
                                          send_purchase_notification_mock):
    payment = baker.make(PagarmePayment,
                         payment_method=facade.CREDIT_CARD,
                         user=logged_user)
    baker.make(PagarmeNotification, status=facade.PAID, payment=payment)
    config = baker.make(PagarmeItemConfig, payments=[payment])
    checkout_domain.payment_handler_task(payment.id)
    assert tag_as_mock.called is False
    remove_tags_mock.assert_called_once_with(logged_user.email, logged_user.id,
                                             f'{config.slug}-refused')
    promote_user_mock.assert_called_once_with(logged_user, config.slug)
    send_purchase_notification_mock.asser_called_once_with(payment.id)
Beispiel #9
0
def test_pagarme_payment_waiting_payment_boleto(
        mock_subscription_creation, db, tag_as_mock, remove_tags_mock,
        logged_user, send_purchase_notification_mock):
    payment = baker.make(PagarmePayment,
                         payment_method=facade.BOLETO,
                         user=logged_user)
    baker.make(PagarmeNotification,
               status=facade.WAITING_PAYMENT,
               payment=payment)
    config = baker.make(PagarmeItemConfig, payments=[payment])
    checkout_domain.payment_handler_task(payment.id)
    assert remove_tags_mock.called is False
    tag_as_mock.assert_called_once_with(logged_user.email, logged_user.id,
                                        f'{config.slug}-boleto')
    send_purchase_notification_mock.asser_called_once_with(payment.id)
Beispiel #10
0
def test_pagarme_payment_paid_credit_card(mock_subscription_creation, db,
                                          tag_as_mock, remove_tags_mock,
                                          logged_user,
                                          send_purchase_notification_mock):
    payment = baker.make(PagarmePayment,
                         payment_method=facade.CREDIT_CARD,
                         user=logged_user)
    baker.make(PagarmeNotification, status=facade.PAID, payment=payment)
    config = baker.make(PagarmeItemConfig, payments=[payment])
    subscription_type = baker.make(SubscriptionType)
    PaymentItemConfigToSubscriptionType.objects.create(
        payment_item=config, subscription_type=subscription_type)
    checkout_domain.payment_handler_task(payment.id)
    assert tag_as_mock.called is False
    remove_tags_mock.assert_called_once_with(logged_user.email, logged_user.id,
                                             f'{config.slug}-refused')
    send_purchase_notification_mock.asser_called_once_with(payment.id)
Beispiel #11
0
def test_pagarme_subscription_inactivation(
        db, tag_as_mock, remove_tags_mock, status,
        inactivate_subscription_on_all_services):
    payment = baker.make(PagarmePayment)
    baker.make(PagarmeNotification, status=status, payment=payment)
    config = baker.make(PagarmeItemConfig, payments=[payment])
    subscription_type = baker.make(SubscriptionType)
    subscription = baker.make(Subscription, payment=payment)
    subscription.subscription_types.add(subscription_type)
    PaymentItemConfigToSubscriptionType.objects.create(
        payment_item=config, subscription_type=subscription_type)

    checkout_domain.payment_handler_task(payment.id)

    assert tag_as_mock.called is False
    assert remove_tags_mock.called is False
    inactivate_subscription_on_all_services.assert_called_once_with(
        subscription)
def test_subscription_creation(db, tag_as_mock, remove_tags_mock,
                               promote_user_mock, logged_user,
                               send_purchase_notification_mock):
    payment = baker.make(PagarmePayment,
                         payment_method=facade.BOLETO,
                         user=logged_user)
    baker.make(PagarmeNotification, status=facade.PAID, payment=payment)
    config = baker.make(PagarmeItemConfig, payments=[payment])
    subscription_type = baker.make(SubscriptionType)
    PaymentItemConfigToSubscriptionType.objects.create(
        payment_item=config, subscription_type=subscription_type)
    checkout_domain.payment_handler_task(payment.id)
    subscription = Subscription.objects.first()
    assert subscription is not None
    assert subscription.subscriber_id == payment.user_id
    assert subscription.status == Subscription.Status.INACTIVE
    assert subscription.payment_id == payment.id
    assert list(subscription.subscription_types.all()) == [subscription_type]
    assert subscription.responsible is None
    assert subscription.observation == 'Criação como resposta de pagamento no Pagarme'