From e93cada4a60a970ffb8c25b8e9499486e16d21a0 Mon Sep 17 00:00:00 2001 From: renzon Date: Thu, 30 May 2019 07:19:59 -0300 Subject: [PATCH] Created client landing page path close #1174 --- pythonpro/modules/tests/test_topics_view.py | 3 ++- pythonpro/modules/topics_views.py | 6 +++--- .../payments/client_landing_page.html} | 0 .../payments/tests/test_landing_pages.py | 11 +++++++++++ pythonpro/payments/urls.py | 1 + pythonpro/payments/views.py | 19 +++++++++++++++++-- 6 files changed, 34 insertions(+), 6 deletions(-) rename pythonpro/{modules/templates/topics/content_client_landing_page.html => payments/templates/payments/client_landing_page.html} (100%) create mode 100644 pythonpro/payments/tests/test_landing_pages.py diff --git a/pythonpro/modules/tests/test_topics_view.py b/pythonpro/modules/tests/test_topics_view.py index bf8928eb..5070a453 100644 --- a/pythonpro/modules/tests/test_topics_view.py +++ b/pythonpro/modules/tests/test_topics_view.py @@ -205,7 +205,8 @@ def resp_lead_accesing_client_content(client_with_lead, topic_client, django_use def test_lead_hitting_client_landing_page(resp_lead_accesing_client_content): - dj_assert_template_used(resp_lead_accesing_client_content, 'topics/content_client_landing_page.html') + assert resp_lead_accesing_client_content.status_code == 302 + assert resp_lead_accesing_client_content.url == reverse('payments:client_landing_page') @pytest.fixture diff --git a/pythonpro/modules/topics_views.py b/pythonpro/modules/topics_views.py index 073551ed..7fd57644 100644 --- a/pythonpro/modules/topics_views.py +++ b/pythonpro/modules/topics_views.py @@ -12,11 +12,11 @@ def content_landing_page(request, content: Content): + if is_client_content(content): + tag_as(request.user.email, 'potencial-client') + return redirect(reverse('payments:client_landing_page'), permanent=False) template = 'topics/content_member_landing_page.html' tag = 'potencial-member' - if is_client_content(content): - template = 'topics/content_client_landing_page.html' - tag = 'potencial-client' tag_as(request.user.email, tag) return render(request, template, { diff --git a/pythonpro/modules/templates/topics/content_client_landing_page.html b/pythonpro/payments/templates/payments/client_landing_page.html similarity index 100% rename from pythonpro/modules/templates/topics/content_client_landing_page.html rename to pythonpro/payments/templates/payments/client_landing_page.html diff --git a/pythonpro/payments/tests/test_landing_pages.py b/pythonpro/payments/tests/test_landing_pages.py new file mode 100644 index 00000000..8b95ac2b --- /dev/null +++ b/pythonpro/payments/tests/test_landing_pages.py @@ -0,0 +1,11 @@ +import pytest +from django.urls import reverse + + +@pytest.fixture +def client_lp_resp(client_with_lead): + return client_with_lead.get(reverse('payments:client_landing_page'), secure=True) + + +def test_non_logged_status_code(client_lp_resp): + assert client_lp_resp.status_code == 200 diff --git a/pythonpro/payments/urls.py b/pythonpro/payments/urls.py index 49ac18f8..362cf5a4 100644 --- a/pythonpro/payments/urls.py +++ b/pythonpro/payments/urls.py @@ -9,5 +9,6 @@ path('pytools/obrigado/', views.pytools_thanks, name='pytools_thanks'), path('pytools/captura/', views.pytools_capture, name='pytools_capture'), path('pytools/boleto/', views.pytools_boleto, name='pytools_boleto'), + path('curso-de-python-intermediario', views.client_landing_page, name='client_landing_page'), path('pargarme/notificacao/', views.pagarme_notification, name='pagarme_notification'), ] diff --git a/pythonpro/payments/views.py b/pythonpro/payments/views.py index fbaf5b7c..81cfa55e 100644 --- a/pythonpro/payments/views.py +++ b/pythonpro/payments/views.py @@ -13,6 +13,7 @@ from pythonpro.mailchimp import facade as mailchimp_facade from pythonpro.payments import facade as payment_facade +from pythonpro.payments.facade import PYTOOLS_PRICE def options(request): @@ -61,9 +62,23 @@ def _extract_boleto_params(dct): return {k: dct[k] for k in ['boleto_barcode', 'boleto_url']} +@login_required +def client_landing_page(request): + notification_url = reverse('payments:pagarme_notification', kwargs={'user_id': request.user.id}) + return render( + request, + 'payments/client_landing_page.html', { + 'PAGARME_CRYPTO_KEY': settings.PAGARME_CRYPTO_KEY, + 'price': PYTOOLS_PRICE, + 'notification_url': request.build_absolute_uri( + notification_url + ) + }) + + def pagarme_notification(request, user_id: int): if request.method != 'POST': - return HttpResponseNotAllowed(['POST']) + return HttpResponseNotAllowed([request.method]) paymento_ok = payment_facade.confirm_boleto_payment( user_id, request.POST, request.body.decode('utf8'), request.headers['X-Hub-Signature']) @@ -78,7 +93,7 @@ def pagarme_notification(request, user_id: int): } ) send_mail( - 'Inscrição no curso Pytool realizad, confira o link com detalhes!', + 'Inscrição no curso Pytool realizada! Confira o link com detalhes.', msg, settings.DEFAULT_FROM_EMAIL, [user.email]