diff --git a/pythonpro/analytics/tests/test_middleware.py b/pythonpro/analytics/tests/test_middleware.py deleted file mode 100644 index bde55f8b..00000000 --- a/pythonpro/analytics/tests/test_middleware.py +++ /dev/null @@ -1,43 +0,0 @@ -import pytest - -from pythonpro.analytics.models import UserSession, PageView - - -def test_should_assert_that_middleware_exists(): - from pythonpro.analytics import middleware - assert middleware.AnalyticsMiddleware - - -@pytest.fixture -def mocked_get_or_create_session(mocked_request_with_analytics, mocker): - return mocker.patch('pythonpro.analytics.middleware.get_or_create_session', - return_value=mocked_request_with_analytics) - - -@pytest.mark.django_db -def test_should_execute_get_or_create_session(client, - mocked_get_or_create_session): - - client.get('/') - assert mocked_get_or_create_session.called - - -@pytest.fixture -def mocked_create_pageview(mocked_request_with_analytics, mocker): - return mocker.patch('pythonpro.analytics.middleware.create_pageview', - return_value=mocked_request_with_analytics) - - -@pytest.mark.django_db -def test_should_execute_create_pageview(client, mocked_get_or_create_session, - mocked_create_pageview): - - client.get('/') - assert mocked_create_pageview.called - - -@pytest.mark.django_db -def test_should_run_full_process(client): - client.get('/curso-de-python-gratis') - assert UserSession.objects.get() - assert PageView.objects.get() diff --git a/pythonpro/domain/user_domain.py b/pythonpro/domain/user_domain.py index 5ade9ff5..fe101de3 100644 --- a/pythonpro/domain/user_domain.py +++ b/pythonpro/domain/user_domain.py @@ -247,7 +247,7 @@ def subscribe_to_waiting_list(session_id, user: _User, phone: str, source: str) """ _core_facade.subscribe_to_waiting_list(user, source) subscribe_with_no_role.delay( - session_id, user.first_name, user.email, 'lista-de-espera', id=user.id, phone=phone + None, user.first_name, user.email, 'lista-de-espera', id=user.id, phone=phone ) @@ -264,9 +264,9 @@ def subscribe_anonymous_user_to_waiting_list(session_id, email: str, name: str, try: user = _core_facade.find_user_by_email(email) except _User.DoesNotExist: - subscribe_with_no_role.delay(session_id, name, email, 'lista-de-espera', phone=phone) + subscribe_with_no_role.delay(None, name, email, 'lista-de-espera', phone=phone) else: - subscribe_to_waiting_list(session_id, user, phone, source) + subscribe_to_waiting_list(None, user, phone, source) def activate_user(user: _User, source: str) -> None: diff --git a/pythonpro/launch/tests/test_lead_form.py b/pythonpro/launch/tests/test_lead_form.py index 0a33ff0c..0ea1f200 100644 --- a/pythonpro/launch/tests/test_lead_form.py +++ b/pythonpro/launch/tests/test_lead_form.py @@ -81,7 +81,7 @@ def resp_with_user(client_with_user, logged_user, cohort, subscribe_with_no_role def test_user_first_name(resp_with_user, logged_user, subscribe_with_no_role, cohort): subscribe_with_no_role.assert_called_once_with( - resp_with_user.cookies['sessionid'].value, + None, 'Moacir', logged_user.email, f'turma-{cohort.slug}-semana-do-programador', diff --git a/pythonpro/launch/views.py b/pythonpro/launch/views.py index 41909e2a..65db2d83 100644 --- a/pythonpro/launch/views.py +++ b/pythonpro/launch/views.py @@ -7,8 +7,8 @@ from pythonpro.absolute_uri import build_absolute_uri from pythonpro.cohorts.facade import find_most_recent_cohort -from pythonpro.domain import user_domain from pythonpro.domain import subscription_domain +from pythonpro.domain import user_domain from pythonpro.launch.facade import ( get_launch_status, get_opened_cpls, @@ -40,16 +40,15 @@ def lead_form(request): email = form.cleaned_data['email'] first_name = form.cleaned_data['name'] user = request.user - session_id = request.session.session_key if user.is_authenticated: subscription_domain.subscribe_with_no_role.delay( - session_id, + None, first_name, email, f'turma-{find_most_recent_cohort().slug}-semana-do-programador', id=user.id) else: subscription_domain.subscribe_with_no_role.delay( - session_id, + None, first_name, email, f'turma-{find_most_recent_cohort().slug}-semana-do-programador') diff --git a/pythonpro/pages/tests/test_bootcamp_vip_landing_page.py b/pythonpro/pages/tests/test_bootcamp_vip_landing_page.py index 644f4325..c9916a7b 100644 --- a/pythonpro/pages/tests/test_bootcamp_vip_landing_page.py +++ b/pythonpro/pages/tests/test_bootcamp_vip_landing_page.py @@ -65,14 +65,14 @@ def test_should_call_update_when_with_correct_parameters(subscribe_with_no_role, # TODO: move this phone tests do generic context def test_should_call_update_when_logged_with_correct_parameters(subscribe_with_no_role, client_with_user): - resp_with_user = client_with_user.post( + client_with_user.post( reverse('pages:bootcamp_vip_landing_page'), {'name': 'Moacir', 'email': 'moacir@python.pro.br', 'phone': '(11) 99999-9999'}, secure=True ) subscribe_with_no_role.assert_called_with( - resp_with_user.cookies['sessionid'].value, + None, 'Moacir', 'moacir@python.pro.br', mock.ANY, diff --git a/pythonpro/pages/views.py b/pythonpro/pages/views.py index c3c6478f..787c5509 100644 --- a/pythonpro/pages/views.py +++ b/pythonpro/pages/views.py @@ -1,14 +1,14 @@ from datetime import timedelta -from inflection import underscore -from django.views.generic import FormView, TemplateView from django.urls import reverse_lazy from django.utils import timezone +from django.views.generic import FormView, TemplateView from django_pagarme import facade +from inflection import underscore from pythonpro.cohorts.facade import find_most_recent_cohort -from pythonpro.pages.forms import NameEmailForm, NameEmailPhoneForm from pythonpro.domain.subscription_domain import subscribe_with_no_role +from pythonpro.pages.forms import NameEmailForm, NameEmailPhoneForm class TemplateNameMixin: @@ -36,8 +36,7 @@ def form_valid(self, form): kwargs['id'] = self.request.user.id kwargs['phone'] = f"+55{form.cleaned_data['phone']}" - session_id = self.request.session.session_key - subscribe_with_no_role.delay(session_id, *args, **kwargs) + subscribe_with_no_role.delay(None, *args, **kwargs) return super().form_valid(form) diff --git a/pythonpro/settings.py b/pythonpro/settings.py index c2d0c995..c5b9ba99 100644 --- a/pythonpro/settings.py +++ b/pythonpro/settings.py @@ -120,7 +120,6 @@ 'django_otp.middleware.OTPMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'pythonpro.analytics.middleware.AnalyticsMiddleware', ] if DEBUG: