Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions pythonpro/checkout/migrations/0008_thiago_avelino_checkouts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Generated by Django 3.0.4 on 2020-03-16 20:26

from django.db import migrations


def setup_payment_configs(apps, schema_editor):
PagarmeFormConfig = apps.get_model('django_pagarme', 'PagarmeFormConfig')
PagarmeItemConfig = apps.get_model('django_pagarme', 'PagarmeItemConfig')
print()
setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)


def setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig):
""""""
config_card = PagarmeFormConfig.objects.all()[1]
bootcamp_d1_boleto = 'bootcamp-d1-boleto'
bootcamp_d1_config = PagarmeItemConfig(
name='Bootcamp DevPro - R$1000 Off',
slug=bootcamp_d1_boleto,
price=199700,
tangible=False,
default_config=config_card
)
bootcamp_d1_config.save()

webdev_downsell_slug = 'webdev-downsell'
webdev_downsell_config = PagarmeItemConfig(
name='Treinamento Webdev Django',
slug=webdev_downsell_slug,
price=49700,
tangible=False,
default_config=config_card
)
webdev_downsell_config.save()

webdev_downsell_boleto_slug = 'webdev-downsell-boleto'
webdev_downsell_boleto_config = PagarmeItemConfig(
name='Treinamento Webdev Django',
slug=webdev_downsell_boleto_slug,
price=49700,
tangible=False,
default_config=config_card
)
webdev_downsell_boleto_config.save()

aps_slug = 'aps'
aps_config = PagarmeItemConfig(
name='Acompanhamento de Processos Seletivos',
slug=aps_slug,
price=50000,
tangible=False,
default_config=config_card
)
aps_config.save()


class Migration(migrations.Migration):
dependencies = [
('checkout', '0007_webserie_and_webinar_boleto'),
]

operations = [
migrations.RunPython(setup_payment_configs, migrations.RunPython.noop)
]
2 changes: 2 additions & 0 deletions pythonpro/checkout/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
python_avancado_migration_module = import_module('pythonpro.checkout.migrations.0005_python_avancado_setup')
webinar_migration_module = import_module('pythonpro.checkout.migrations.0006_webinar_setup')
webserie_migration_module = import_module('pythonpro.checkout.migrations.0007_webserie_and_webinar_boleto')
thiago_avelino_migration_module = import_module('pythonpro.checkout.migrations.0008_thiago_avelino_checkouts')


@pytest.fixture(autouse=True)
Expand All @@ -24,6 +25,7 @@ def execute_migration(db, pytestconfig):
python_avancado_migration_module.setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)
webinar_migration_module.setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)
webserie_migration_module.setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)
thiago_avelino_migration_module.setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)


@pytest.fixture(autouse=True)
Expand Down
71 changes: 70 additions & 1 deletion pythonpro/checkout/tests/test_payment_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,23 @@ def test_item_bootcamp_webdev_50_discount(second_pagarme_form_config):
)


def test_item_bootcamp_d1_boleto(second_pagarme_form_config):
item_config = facade.find_payment_item_config('bootcamp-d1-boleto')
assert (
item_config.name,
item_config.slug,
item_config.price,
item_config.tangible,
item_config.default_config,
) == (
'Bootcamp DevPro - R$1000 Off',
'bootcamp-d1-boleto',
199700,
False,
second_pagarme_form_config
)


@pytest.fixture
def free_interest_form_config():
return PagarmeFormConfig.objects.order_by('id').all()[2]
Expand Down Expand Up @@ -466,4 +483,56 @@ def test_item_python_avancado(free_interest_form_config):
free_interest_form_config
)
for payment_item in PagarmeItemConfig.objects.filter(slug__startswith='bootcamp').all():
assert payment_item.upsell_id == item_config.id
if not payment_item.slug.startswith('bootcamp-d'):
assert payment_item.upsell_id == item_config.id


def test_item_webdev_downsell(second_pagarme_form_config):
item_config = facade.find_payment_item_config('webdev-downsell')
assert (
item_config.name,
item_config.slug,
item_config.price,
item_config.tangible,
item_config.default_config,
) == (
'Treinamento Webdev Django',
'webdev-downsell',
49700,
False,
second_pagarme_form_config
)


def test_item_webdev_downsell_boleto(second_pagarme_form_config):
item_config = facade.find_payment_item_config('webdev-downsell-boleto')
assert (
item_config.name,
item_config.slug,
item_config.price,
item_config.tangible,
item_config.default_config,
) == (
'Treinamento Webdev Django',
'webdev-downsell-boleto',
49700,
False,
second_pagarme_form_config
)


def test_item_aps(second_pagarme_form_config):
item_config = facade.find_payment_item_config('aps')
assert (
item_config.name,
item_config.slug,
item_config.price,
item_config.tangible,
item_config.default_config,
) == (
'Acompanhamento de Processos Seletivos',
'aps',
50000,
False,
second_pagarme_form_config
)
11 changes: 5 additions & 6 deletions pythonpro/domain/checkout_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,15 @@ def payment_handler_task(payment_id):
else:
email_marketing_facade.remove_tags.delay(user.email, user.id, f'{slug}-refused')
_promote(user, slug)
if slug.startswith('bootcamp'):
send_purchase_notification.delay(payment.id)
send_purchase_notification.delay(payment.id)
elif status == django_pagarme_facade.REFUSED:
user = payment.user
email_marketing_facade.tag_as.delay(user.email, user.id, f'{slug}-refused')
if slug.startswith('bootcamp'):
send_purchase_notification.delay(payment.id)
send_purchase_notification.delay(payment.id)
elif status == django_pagarme_facade.WAITING_PAYMENT:
user = payment.user
email_marketing_facade.tag_as.delay(user.email, user.id, f'{slug}-boleto')
if slug.startswith('bootcamp'):
send_purchase_notification.delay(payment.id)
send_purchase_notification.delay(payment.id)


def _promote(user, slug: str):
Expand All @@ -90,6 +87,8 @@ def _promote(user, slug: str):
user_domain.promote_pythonista(user, 'unknown')
elif slug.startswith('bootcamp'):
user_domain.promote_bootcamper(user, 'unknown')
elif slug == 'aps':
pass # no action required
else:
raise ValueError(f'{slug} should contain webdev or membership or data-science')

Expand Down
9 changes: 7 additions & 2 deletions pythonpro/domain/tests/test_checkout/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
python_avancado_migration_module = import_module('pythonpro.checkout.migrations.0005_python_avancado_setup')
webinar_migration_module = import_module('pythonpro.checkout.migrations.0006_webinar_setup')
webserie_migration_module = import_module('pythonpro.checkout.migrations.0007_webserie_and_webinar_boleto')
thiago_avelino_migration_module = import_module('pythonpro.checkout.migrations.0008_thiago_avelino_checkouts')

ALL_ACTIVE_PRODUCTS = [

'webdev',
'webdev-oto',
'data-science',
Expand All @@ -25,13 +25,16 @@
'bootcamp-webdev',
'bootcamp-webdev-35-discount',
'bootcamp-webdev-50-discount',
'pacote-proximo-nivel-67-discount',
'bootcamp-d1-boleto',
'treinamento-devpro-webinar',
'treinamento-devpro-webinar-boleto',
'treinamento-devpro-webserie',
'treinamento-devpro-webserie-boleto',
'treinamento-devpro-masterclass-oto',
'treinamento-devpro-masterclass-oto-boleto',
'webdev-downsell-boleto',
'webdev-downsell',
'aps',
]
ALL_INACTIVE_PRODUCTS = [
'pytools',
Expand All @@ -41,6 +44,7 @@
'membership-client',
'membership-client-first-day',
'membership-first-day',
'pacote-proximo-nivel-67-discount',
]
ALL_PRODUCTS = ALL_ACTIVE_PRODUCTS + ALL_INACTIVE_PRODUCTS

Expand All @@ -55,6 +59,7 @@ def execute_migration(db, pytestconfig):
python_avancado_migration_module.setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)
webinar_migration_module.setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)
webserie_migration_module.setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)
thiago_avelino_migration_module.setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)


@pytest.fixture(autouse=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def assert_user_promoted(user, slug):
assert core_facade.is_bootcamper(user)
elif slug == 'pacote-proximo-nivel-67-discount':
assert core_facade.is_pythonista(user)
elif slug == 'aps':
pass # no promotion required
else:
pytest.fail(f'Invalid slug prefix {slug}')

Expand All @@ -155,7 +157,7 @@ def test_user_is_subscribed_to_cohort(resp, django_user_model, cohort, active_pr

def assert_subscribed_to_cohort(cohort, slug, user):
if not (slug.startswith('webdev') or slug.startswith('treinamento-devpro') or slug.startswith(
'data-science') or slug == 'pacote-proximo-nivel-67-discount'):
'data-science') or slug == 'pacote-proximo-nivel-67-discount' or slug == 'aps'):
assert cohort.students.first() == user


Expand All @@ -165,6 +167,8 @@ def test_user_synced_on_discourse(resp, django_user_model, sync_on_discourse_moc
if active_product_item.slug in {'bootcamp', 'bootcamp-webdev'}:
user_sync_call = mocker.call(user.id)
assert sync_on_discourse_mock.mock_calls == [user_sync_call, user_sync_call]
elif active_product_item.slug == 'aps':
assert sync_on_discourse_mock.call_count == 0
else:
sync_on_discourse_mock.assert_called_once_with(user.id)

Expand Down Expand Up @@ -216,6 +220,8 @@ def test_logged_user_is_synced_on_discourse(resp_logged_user, logged_user, sync_
if active_product_item.slug in {'bootcamp', 'bootcamp-webdev'}:
user_sync_call = mocker.call(logged_user.id)
assert sync_on_discourse_mock.mock_calls == [user_sync_call, user_sync_call]
elif active_product_item.slug == 'aps':
assert sync_on_discourse_mock.call_count == 0
else:
sync_on_discourse_mock.assert_called_once_with(logged_user.id)

Expand Down