Skip to content

Commit 11bcbb6

Browse files
author
renzon
committed
Created Thiago Avelino Corhort Chekcouts
close #3389
1 parent 8adccea commit 11bcbb6

6 files changed

Lines changed: 157 additions & 10 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Generated by Django 3.0.4 on 2020-03-16 20:26
2+
3+
from django.db import migrations
4+
5+
6+
def setup_payment_configs(apps, schema_editor):
7+
PagarmeFormConfig = apps.get_model('django_pagarme', 'PagarmeFormConfig')
8+
PagarmeItemConfig = apps.get_model('django_pagarme', 'PagarmeItemConfig')
9+
print()
10+
setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)
11+
12+
13+
def setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig):
14+
""""""
15+
config_card = PagarmeFormConfig.objects.all()[1]
16+
bootcamp_d1_boleto = 'bootcamp-d1-boleto'
17+
bootcamp_d1_config = PagarmeItemConfig(
18+
name='Bootcamp DevPro - R$1000 Off',
19+
slug=bootcamp_d1_boleto,
20+
price=199700,
21+
tangible=False,
22+
default_config=config_card
23+
)
24+
bootcamp_d1_config.save()
25+
26+
webdev_downsell_slug = 'webdev-downsell'
27+
webdev_downsell_config = PagarmeItemConfig(
28+
name='Treinamento Webdev Django',
29+
slug=webdev_downsell_slug,
30+
price=49700,
31+
tangible=False,
32+
default_config=config_card
33+
)
34+
webdev_downsell_config.save()
35+
36+
webdev_downsell_boleto_slug = 'webdev-downsell-boleto'
37+
webdev_downsell_boleto_config = PagarmeItemConfig(
38+
name='Treinamento Webdev Django',
39+
slug=webdev_downsell_boleto_slug,
40+
price=49700,
41+
tangible=False,
42+
default_config=config_card
43+
)
44+
webdev_downsell_boleto_config.save()
45+
46+
aps_slug = 'aps'
47+
aps_config = PagarmeItemConfig(
48+
name='Acompanhamento de Processos Seletivos',
49+
slug=aps_slug,
50+
price=50000,
51+
tangible=False,
52+
default_config=config_card
53+
)
54+
aps_config.save()
55+
56+
57+
58+
59+
class Migration(migrations.Migration):
60+
dependencies = [
61+
('checkout', '0007_webserie_and_webinar_boleto'),
62+
]
63+
64+
operations = [
65+
migrations.RunPython(setup_payment_configs, migrations.RunPython.noop)
66+
]

pythonpro/checkout/tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
python_avancado_migration_module = import_module('pythonpro.checkout.migrations.0005_python_avancado_setup')
1313
webinar_migration_module = import_module('pythonpro.checkout.migrations.0006_webinar_setup')
1414
webserie_migration_module = import_module('pythonpro.checkout.migrations.0007_webserie_and_webinar_boleto')
15+
thiago_avelino_migration_module = import_module('pythonpro.checkout.migrations.0008_thiago_avelino_checkouts')
1516

1617

1718
@pytest.fixture(autouse=True)
@@ -24,6 +25,7 @@ def execute_migration(db, pytestconfig):
2425
python_avancado_migration_module.setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)
2526
webinar_migration_module.setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)
2627
webserie_migration_module.setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)
28+
thiago_avelino_migration_module.setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)
2729

2830

2931
@pytest.fixture(autouse=True)

pythonpro/checkout/tests/test_payment_setup.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,23 @@ def test_item_bootcamp_webdev_50_discount(second_pagarme_form_config):
427427
)
428428

429429

430+
def test_item_bootcamp_d1_boleto(second_pagarme_form_config):
431+
item_config = facade.find_payment_item_config('bootcamp-d1-boleto')
432+
assert (
433+
item_config.name,
434+
item_config.slug,
435+
item_config.price,
436+
item_config.tangible,
437+
item_config.default_config,
438+
) == (
439+
'Bootcamp DevPro - R$1000 Off',
440+
'bootcamp-d1-boleto',
441+
199700,
442+
False,
443+
second_pagarme_form_config
444+
)
445+
446+
430447
@pytest.fixture
431448
def free_interest_form_config():
432449
return PagarmeFormConfig.objects.order_by('id').all()[2]
@@ -466,4 +483,56 @@ def test_item_python_avancado(free_interest_form_config):
466483
free_interest_form_config
467484
)
468485
for payment_item in PagarmeItemConfig.objects.filter(slug__startswith='bootcamp').all():
469-
assert payment_item.upsell_id == item_config.id
486+
if not payment_item.slug.startswith('bootcamp-d'):
487+
assert payment_item.upsell_id == item_config.id
488+
489+
490+
def test_item_webdev_downsell(second_pagarme_form_config):
491+
item_config = facade.find_payment_item_config('webdev-downsell')
492+
assert (
493+
item_config.name,
494+
item_config.slug,
495+
item_config.price,
496+
item_config.tangible,
497+
item_config.default_config,
498+
) == (
499+
'Treinamento Webdev Django',
500+
'webdev-downsell',
501+
49700,
502+
False,
503+
second_pagarme_form_config
504+
)
505+
506+
507+
def test_item_webdev_downsell_boleto(second_pagarme_form_config):
508+
item_config = facade.find_payment_item_config('webdev-downsell-boleto')
509+
assert (
510+
item_config.name,
511+
item_config.slug,
512+
item_config.price,
513+
item_config.tangible,
514+
item_config.default_config,
515+
) == (
516+
'Treinamento Webdev Django',
517+
'webdev-downsell-boleto',
518+
49700,
519+
False,
520+
second_pagarme_form_config
521+
)
522+
523+
524+
def test_item_aps(second_pagarme_form_config):
525+
item_config = facade.find_payment_item_config('aps')
526+
assert (
527+
item_config.name,
528+
item_config.slug,
529+
item_config.price,
530+
item_config.tangible,
531+
item_config.default_config,
532+
) == (
533+
'Acompanhamento de Processos Seletivos',
534+
'aps',
535+
50000,
536+
False,
537+
second_pagarme_form_config
538+
)

pythonpro/domain/checkout_domain.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,15 @@ def payment_handler_task(payment_id):
6262
else:
6363
email_marketing_facade.remove_tags.delay(user.email, user.id, f'{slug}-refused')
6464
_promote(user, slug)
65-
if slug.startswith('bootcamp'):
66-
send_purchase_notification.delay(payment.id)
65+
send_purchase_notification.delay(payment.id)
6766
elif status == django_pagarme_facade.REFUSED:
6867
user = payment.user
6968
email_marketing_facade.tag_as.delay(user.email, user.id, f'{slug}-refused')
70-
if slug.startswith('bootcamp'):
71-
send_purchase_notification.delay(payment.id)
69+
send_purchase_notification.delay(payment.id)
7270
elif status == django_pagarme_facade.WAITING_PAYMENT:
7371
user = payment.user
7472
email_marketing_facade.tag_as.delay(user.email, user.id, f'{slug}-boleto')
75-
if slug.startswith('bootcamp'):
76-
send_purchase_notification.delay(payment.id)
73+
send_purchase_notification.delay(payment.id)
7774

7875

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

pythonpro/domain/tests/test_checkout/conftest.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
python_avancado_migration_module = import_module('pythonpro.checkout.migrations.0005_python_avancado_setup')
1414
webinar_migration_module = import_module('pythonpro.checkout.migrations.0006_webinar_setup')
1515
webserie_migration_module = import_module('pythonpro.checkout.migrations.0007_webserie_and_webinar_boleto')
16+
thiago_avelino_migration_module = import_module('pythonpro.checkout.migrations.0008_thiago_avelino_checkouts')
1617

1718
ALL_ACTIVE_PRODUCTS = [
18-
1919
'webdev',
2020
'webdev-oto',
2121
'data-science',
@@ -25,13 +25,16 @@
2525
'bootcamp-webdev',
2626
'bootcamp-webdev-35-discount',
2727
'bootcamp-webdev-50-discount',
28-
'pacote-proximo-nivel-67-discount',
28+
'bootcamp-d1-boleto',
2929
'treinamento-devpro-webinar',
3030
'treinamento-devpro-webinar-boleto',
3131
'treinamento-devpro-webserie',
3232
'treinamento-devpro-webserie-boleto',
3333
'treinamento-devpro-masterclass-oto',
3434
'treinamento-devpro-masterclass-oto-boleto',
35+
'webdev-downsell-boleto',
36+
'webdev-downsell',
37+
'aps',
3538
]
3639
ALL_INACTIVE_PRODUCTS = [
3740
'pytools',
@@ -41,6 +44,7 @@
4144
'membership-client',
4245
'membership-client-first-day',
4346
'membership-first-day',
47+
'pacote-proximo-nivel-67-discount',
4448
]
4549
ALL_PRODUCTS = ALL_ACTIVE_PRODUCTS + ALL_INACTIVE_PRODUCTS
4650

@@ -55,6 +59,7 @@ def execute_migration(db, pytestconfig):
5559
python_avancado_migration_module.setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)
5660
webinar_migration_module.setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)
5761
webserie_migration_module.setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)
62+
thiago_avelino_migration_module.setup_payment_configs_function(PagarmeFormConfig, PagarmeItemConfig)
5863

5964

6065
@pytest.fixture(autouse=True)

pythonpro/domain/tests/test_checkout/test_credit_card_payment.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ def assert_user_promoted(user, slug):
142142
assert core_facade.is_bootcamper(user)
143143
elif slug == 'pacote-proximo-nivel-67-discount':
144144
assert core_facade.is_pythonista(user)
145+
elif slug == 'aps':
146+
pass # no promotion required
145147
else:
146148
pytest.fail(f'Invalid slug prefix {slug}')
147149

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

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

161163

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

@@ -216,6 +220,8 @@ def test_logged_user_is_synced_on_discourse(resp_logged_user, logged_user, sync_
216220
if active_product_item.slug in {'bootcamp', 'bootcamp-webdev'}:
217221
user_sync_call = mocker.call(logged_user.id)
218222
assert sync_on_discourse_mock.mock_calls == [user_sync_call, user_sync_call]
223+
elif active_product_item.slug == 'aps':
224+
assert sync_on_discourse_mock.call_count == 0
219225
else:
220226
sync_on_discourse_mock.assert_called_once_with(logged_user.id)
221227

0 commit comments

Comments
 (0)