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
8 changes: 8 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,12 @@ def turn_active_campaign_on(settings):
settings.ACTIVE_CAMPAIGN_TURNED_ON = True


@pytest.fixture(autouse=True)
def turn_ssl_rediret_off_for_tests(settings):
"""
There is no need to place secure=True in all client requests
"""
settings.SECURE_SSL_REDIRECT = False


pytest_plugins = ['pythonpro.modules.tests.test_topics_view']
2 changes: 1 addition & 1 deletion pythonpro/analytics/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@pytest.fixture
def pre_request():
factory = RequestFactory()
request = factory.get('/', secure=True)
request = factory.get('/')
request.user = AnonymousUser()
return request

Expand Down
6 changes: 3 additions & 3 deletions pythonpro/analytics/tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def mocked_get_or_create_session(mocked_request_with_analytics, mocker):
def test_should_execute_get_or_create_session(client,
mocked_get_or_create_session):

client.get('/', secure=True)
client.get('/')
assert mocked_get_or_create_session.called


Expand All @@ -32,12 +32,12 @@ def mocked_create_pageview(mocked_request_with_analytics, mocker):
def test_should_execute_create_pageview(client, mocked_get_or_create_session,
mocked_create_pageview):

client.get('/', secure=True)
client.get('/')
assert mocked_create_pageview.called


@pytest.mark.django_db
def test_should_run_full_process(client):
client.get('/curso-de-python-gratis', secure=True)
client.get('/curso-de-python-gratis')
assert UserSession.objects.get()
assert PageView.objects.get()
2 changes: 1 addition & 1 deletion pythonpro/checkout/tests/test_landing_page_webdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@pytest.fixture
def resp(client_with_lead, db):
return client_with_lead.get(reverse('checkout:webdev_landing_page'), secure=True)
return client_with_lead.get(reverse('checkout:webdev_landing_page'))


def test_should_page_exists(resp):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@pytest.fixture
def resp(client_with_lead, db):
return client_with_lead.get(reverse('checkout:webdev_landing_page_50_off'), secure=True)
return client_with_lead.get(reverse('checkout:webdev_landing_page_50_off'))


def test_should_page_exists(resp):
Expand Down
2 changes: 1 addition & 1 deletion pythonpro/checkout/tests/test_landing_page_webdev_oto.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@pytest.fixture
def resp(client_with_lead, db):
return client_with_lead.get(reverse('checkout:webdev_landing_page_oto'), secure=True)
return client_with_lead.get(reverse('checkout:webdev_landing_page_oto'))


def test_should_page_exists(resp):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def tag_as_mock(mocker):
def resp(client, tag_as_mock, freezer, logged_user):
freezer.move_to(facade.launch_datetime_finish + timedelta(seconds=1))
client.force_login(logged_user)
return client.get(reverse('checkout:membership_lp'), secure=True)
return client.get(reverse('checkout:membership_lp'))


def test_tag_as_called(resp, logged_user, tag_as_mock):
Expand All @@ -34,7 +34,7 @@ def test_subscription_link_is_present(resp):
@pytest.fixture
def resp_no_user(client, freezer):
freezer.move_to(facade.launch_datetime_finish + timedelta(seconds=1))
resp = client.get(reverse('checkout:membership_lp'), secure=True)
resp = client.get(reverse('checkout:membership_lp'))
return resp


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def tag_as_mock(mocker):
@pytest.fixture
def resp_no_user_after_discount(client, tag_as_mock, freezer):
freezer.move_to(facade.discount_datetime_limit + timedelta(seconds=1))
return client.get(reverse('checkout:membership_lp'), secure=True)
return client.get(reverse('checkout:membership_lp'))


def test_no_user_status_code(resp_no_user_after_discount):
Expand All @@ -42,7 +42,7 @@ def test_no_user_no_discount(resp_no_user_after_discount):
@pytest.fixture
def resp_no_user_before_discount(client, tag_as_mock, freezer):
freezer.move_to(facade.discount_datetime_limit - timedelta(seconds=1))
return client.get(reverse('checkout:membership_lp'), secure=True)
return client.get(reverse('checkout:membership_lp'))


def test_no_user_with_first_day_discount(resp_no_user_before_discount):
Expand All @@ -60,7 +60,7 @@ def test_no_user_with_first_day_discount(resp_no_user_before_discount):
def resp_with_lead_after_discount(client_with_lead, logged_user, tag_as_mock, freezer):
freezer.move_to(facade.discount_datetime_limit + timedelta(seconds=1))
client_with_lead.force_login(logged_user) # freezer for some reason logout user, so must be logged again
return client_with_lead.get(reverse('checkout:membership_lp'), secure=True)
return client_with_lead.get(reverse('checkout:membership_lp'))


def test_tag_as_called(resp_with_lead_after_discount, logged_user, tag_as_mock):
Expand All @@ -74,14 +74,14 @@ def test_lead_without_discount(resp_with_lead_after_discount):
def test_lead_with_first_day_discount(client_with_lead, logged_user, tag_as_mock, freezer):
freezer.move_to(facade.discount_datetime_limit - timedelta(seconds=1))
client_with_lead.force_login(logged_user) # freezer for some reason logout user, so must be logged again
resp = client_with_lead.get(reverse('checkout:membership_lp'), secure=True)
resp = client_with_lead.get(reverse('checkout:membership_lp'))
test_no_user_with_first_day_discount(resp)


def test_client_without_first_day_discount(client_with_client, logged_user, tag_as_mock, freezer):
freezer.move_to(facade.discount_datetime_limit + timedelta(seconds=1))
client_with_client.force_login(logged_user) # freezer for some reason logout user, so must be logged again
resp = client_with_client.get(reverse('checkout:membership_lp'), secure=True)
resp = client_with_client.get(reverse('checkout:membership_lp'))
assert resp.context['payment_item_config'].slug == 'membership-client'
assert resp.context['client_discount'] == 10000
assert resp.context['first_day_discount'] == 0
Expand All @@ -95,7 +95,7 @@ def test_client_without_first_day_discount(client_with_client, logged_user, tag_
def test_client_with_first_day_discount(client_with_client, logged_user, tag_as_mock, freezer):
freezer.move_to(facade.discount_datetime_limit - timedelta(seconds=1))
client_with_client.force_login(logged_user) # freezer for some reason logout user, so must be logged again
resp = client_with_client.get(reverse('checkout:membership_lp'), secure=True)
resp = client_with_client.get(reverse('checkout:membership_lp'))
assert resp.context['payment_item_config'].slug == 'membership-client-first-day'
assert resp.context['client_discount'] == 10000
assert resp.context['first_day_discount'] == 40000
Expand Down
6 changes: 3 additions & 3 deletions pythonpro/checkout/tests/test_waiting_list_ty.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def resp(subscription_closed, client_with_lead, logged_user, create_or_update_wi
'first_name': logged_user.first_name,
'phone': logged_user.phone
}
yield client_with_lead.post(reverse('checkout:membership_lp'), data, secure=True)
yield client_with_lead.post(reverse('checkout:membership_lp'), data)


def test_logged_user_updated(resp, logged_user, create_or_update_with_no_role_mock):
Expand All @@ -51,7 +51,7 @@ def resp_anonymous_user_existing_email(subscription_closed, client, logged_user,
'first_name': logged_user.first_name,
'phone': logged_user.phone
}
yield client.post(reverse('checkout:membership_lp'), data, secure=True)
yield client.post(reverse('checkout:membership_lp'), data)


def test_anonymous_user_existing_email_updated(resp_anonymous_user_existing_email, logged_user,
Expand All @@ -73,7 +73,7 @@ def anonymous_form_data():
@pytest.fixture
def resp_anonymous_user_missing_email(subscription_closed, client, create_or_update_with_no_role_mock,
anonymous_form_data, db):
yield client.post(reverse('checkout:membership_lp'), anonymous_form_data, secure=True)
yield client.post(reverse('checkout:membership_lp'), anonymous_form_data)


def test_anonymous_user_missing_email_updated(resp_anonymous_user_missing_email, anonymous_form_data,
Expand Down
12 changes: 6 additions & 6 deletions pythonpro/cohorts/tests/test_cohorts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

@pytest.fixture
def resp(client_with_member, cohort):
return client_with_member.get(reverse('cohorts:detail', kwargs={'slug': cohort.slug}), secure=True)
return client_with_member.get(reverse('cohorts:detail', kwargs={'slug': cohort.slug}))


@pytest.fixture
def resp_without_user(client, db):
image = SimpleUploadedFile(name='renzo-nuccitelli.jpeg', content=open(img_path, 'rb').read(),
content_type='image/png')
cohort = mommy.make(Cohort, slug='guido-van-rossum', image=image)
resp = client.get(reverse('cohorts:detail', kwargs={'slug': cohort.slug}), secure=True)
resp = client.get(reverse('cohorts:detail', kwargs={'slug': cohort.slug}))
return resp


Expand All @@ -39,7 +39,7 @@ def test_cohort_links_for_logged_user(client, django_user_model):
image = SimpleUploadedFile(name='renzo-nuccitelli.jpeg', content=open(img_path, 'rb').read(),
content_type='image/png')
cohorts = mommy.make(Cohort, 4, image=image)
resp = client.get(reverse('dashboard:home'), secure=True)
resp = client.get(reverse('dashboard:home'))
for c in cohorts:
dj_assert_contains(resp, c.get_absolute_url())

Expand All @@ -49,7 +49,7 @@ def test_cohort_links_not_avaliable_for_no_user(client):
image = SimpleUploadedFile(name='renzo-nuccitelli.jpeg', content=open(img_path, 'rb').read(),
content_type='image/png')
cohorts = mommy.make(Cohort, 4, image=image)
resp = client.get('/', secure=True)
resp = client.get('/')
for c in cohorts:
dj_assert_not_contains(resp, c.get_absolute_url())

Expand Down Expand Up @@ -111,7 +111,7 @@ def future_live_classes(cohort, fake):

@pytest.fixture
def resp_with_classes(recorded_live_classes, future_live_classes, cohort, client_with_member):
return client_with_member.get(reverse('cohorts:detail', kwargs={'slug': cohort.slug}), secure=True)
return client_with_member.get(reverse('cohorts:detail', kwargs={'slug': cohort.slug}))


def test_live_classes_are_sorted(recorded_live_classes, cohort):
Expand Down Expand Up @@ -175,7 +175,7 @@ def test_future_webinars_in_cohort(recorded_webinars, future_webinars, cohort):

@pytest.fixture
def resp_with_webnars(recorded_webinars, future_webinars, cohort, client_with_member):
return client_with_member.get(reverse('cohorts:detail', kwargs={'slug': cohort.slug}), secure=True)
return client_with_member.get(reverse('cohorts:detail', kwargs={'slug': cohort.slug}))


def test_webnars_are_sorted(recorded_webinars: list, cohort):
Expand Down
10 changes: 5 additions & 5 deletions pythonpro/cohorts/tests/test_live_class_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ def live_class(db, cohort, fake) -> LiveClass:

@pytest.fixture
def resp(client_with_member, live_class: LiveClass):
return client_with_member.get(reverse('cohorts:live_class', kwargs={'pk': live_class.id}), secure=True)
return client_with_member.get(reverse('cohorts:live_class', kwargs={'pk': live_class.id}))


def test_logged_user(resp):
assert resp.status_code == 200


def test_link_unavailable_for_non_users(client):
resp = client.get(reverse('cohorts:live_class', kwargs={'pk': 1}), secure=True)
resp = client.get(reverse('cohorts:live_class', kwargs={'pk': 1}))
assert resp.status_code == 302


Expand All @@ -48,7 +48,7 @@ def test_cohort_title(cohort, resp):
def resp_video_not_recorded(client_with_member, live_class: LiveClass):
live_class.vimeo_id = ''
live_class.save()
return client_with_member.get(reverse('cohorts:live_class', kwargs={'pk': live_class.id}), secure=True)
return client_with_member.get(reverse('cohorts:live_class', kwargs={'pk': live_class.id}))


def test_pending_live_class_msg(resp_video_not_recorded):
Expand All @@ -72,7 +72,7 @@ def test_vimeo_player_not_present(resp_video_not_recorded):

@pytest.fixture
def resp_client(client_with_client, live_class: LiveClass, mocker, logged_user):
return client_with_client.get(reverse('cohorts:live_class', kwargs={'pk': live_class.id}), secure=True)
return client_with_client.get(reverse('cohorts:live_class', kwargs={'pk': live_class.id}))


def test_live_class_landing_for_client(cohort, resp_client):
Expand All @@ -82,7 +82,7 @@ def test_live_class_landing_for_client(cohort, resp_client):

@pytest.fixture
def resp_lead(client_with_lead, live_class: LiveClass, mocker, logged_user):
return client_with_lead.get(reverse('cohorts:live_class', kwargs={'pk': live_class.id}), secure=True)
return client_with_lead.get(reverse('cohorts:live_class', kwargs={'pk': live_class.id}))


def test_live_class_landing_for_lead(cohort, resp_lead):
Expand Down
10 changes: 5 additions & 5 deletions pythonpro/cohorts/tests/test_webinar_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ def webinar(cohort) -> Webinar:

@pytest.fixture
def resp(client_with_member, webinar: Webinar):
return client_with_member.get(reverse('cohorts:webinar', kwargs={'slug': webinar.slug}), secure=True)
return client_with_member.get(reverse('cohorts:webinar', kwargs={'slug': webinar.slug}))


def test_logged_user(resp):
assert resp.status_code == 200


def test_link_unavailable_for_non_users(client):
resp = client.get(reverse('cohorts:webinar', kwargs={'slug': 'foo'}), secure=True)
resp = client.get(reverse('cohorts:webinar', kwargs={'slug': 'foo'}))
assert resp.status_code == 302


Expand All @@ -38,7 +38,7 @@ def test_basic_contents(resp, webinar, property_name):
def resp_video_not_recorded(client_with_member, webinar: Webinar):
webinar.vimeo_id = ''
webinar.save()
return client_with_member.get(reverse('cohorts:webinar', kwargs={'slug': webinar.slug}), secure=True)
return client_with_member.get(reverse('cohorts:webinar', kwargs={'slug': webinar.slug}))


def test_pending_webinar_msg(resp_video_not_recorded):
Expand All @@ -57,7 +57,7 @@ def test_vimeo_player_not_present(resp_video_not_recorded):

@pytest.fixture
def resp_client(client_with_client, webinar: Webinar, mocker, logged_user):
return client_with_client.get(reverse('cohorts:webinar', kwargs={'slug': webinar.slug}), secure=True)
return client_with_client.get(reverse('cohorts:webinar', kwargs={'slug': webinar.slug}))


def test_webinar_landing_for_client(cohort, resp_client):
Expand All @@ -67,7 +67,7 @@ def test_webinar_landing_for_client(cohort, resp_client):

@pytest.fixture
def resp_lead(client_with_lead, webinar: Webinar, mocker, logged_user):
return client_with_lead.get(reverse('cohorts:webinar', kwargs={'slug': webinar.slug}), secure=True)
return client_with_lead.get(reverse('cohorts:webinar', kwargs={'slug': webinar.slug}))


def test_webinar_landing_for_lead(cohort, resp_lead):
Expand Down
8 changes: 4 additions & 4 deletions pythonpro/cohorts/tests/test_webinars.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

@pytest.fixture
def resp(client_with_user, webinars):
return client_with_user.get(reverse('cohorts:webinars'), secure=True)
return client_with_user.get(reverse('cohorts:webinars'))


def test_link_for_logged_user(client_with_user):
resp = client_with_user.get(reverse('dashboard:home'), secure=True)
resp = client_with_user.get(reverse('dashboard:home'))
dj_assert_contains(resp, reverse('cohorts:webinars'))


def test_link_unavailable_for_non_users(client):
resp = client.get('/', secure=True)
resp = client.get('/')
dj_assert_not_contains(resp, reverse('cohorts:webinars'))


Expand Down Expand Up @@ -45,7 +45,7 @@ def not_recorded_webinars(webinars):

@pytest.fixture
def resp_not_recorded_webinars(client_with_user, not_recorded_webinars):
return client_with_user.get(reverse('cohorts:webinars'), secure=True)
return client_with_user.get(reverse('cohorts:webinars'))


def test_not_recorded_webinar_url_not_present(resp_not_recorded_webinars, not_recorded_webinars):
Expand Down
4 changes: 4 additions & 0 deletions pythonpro/core/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,7 @@ def is_webdev(user: User):

def is_data_scientist(user):
return has_role(user, 'data_scientist')


def has_any_webdev_role(user):
return has_role(user, 'lead client webdev member'.split())
22 changes: 0 additions & 22 deletions pythonpro/core/middleware.py

This file was deleted.

Loading