This repository has been archived by the owner on Aug 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconftest.py
96 lines (73 loc) · 2.69 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
from unittest import mock
import pytest
from django.contrib.auth import get_user_model
from django.core.cache import cache
from core.tests.helpers import create_response
@pytest.fixture(autouse=True)
def clear_cache():
cache.clear()
@pytest.fixture
def user():
SSOUser = get_user_model()
return SSOUser(id=1, pk=1, email='jim@example.com', session_id='123', has_user_profile=False)
@pytest.fixture
def user_with_profile():
SSOUser = get_user_model()
return SSOUser(id=1, pk=1, email='jim2@example.com', session_id='123', has_user_profile=True, first_name='No Name')
@pytest.fixture(autouse=True)
def feature_flags(settings):
# solves this issue: https://github.com/pytest-dev/pytest-django/issues/601
settings.FEATURE_FLAGS = {**settings.FEATURE_FLAGS}
yield settings.FEATURE_FLAGS
@pytest.fixture()
def captcha_stub():
# https://github.com/praekelt/django-recaptcha#id5
os.environ['RECAPTCHA_TESTING'] = 'True'
yield 'PASSED'
os.environ['RECAPTCHA_TESTING'] = 'False'
@pytest.fixture(autouse=True)
def auth_backend():
patch = mock.patch(
'directory_sso_api_client.sso_api_client.user.get_session_user', return_value=create_response(404)
)
yield patch.start()
patch.stop()
@pytest.fixture
def client(client, auth_backend, settings):
def force_login(user):
client.cookies[settings.SSO_SESSION_COOKIE] = '123'
if user.has_user_profile:
user_profile = {'first_name': user.first_name, 'last_name': user.last_name}
else:
user_profile = {}
auth_backend.return_value = create_response(
{'id': user.id, 'email': user.email, 'hashed_uuid': user.hashed_uuid, 'user_profile': user_profile}
)
client.force_login = force_login
return client
@pytest.fixture(autouse=True)
def mock_create_user_profile():
response = create_response(
{
'first_name': 'First Name',
'last_name': 'Last Name',
'job_title': 'Director',
'mobile_phone_number': '08888888888',
}
)
patch = mock.patch('directory_sso_api_client.sso_api_client.user.create_user_profile', return_value=response)
yield patch.start()
patch.stop()
@pytest.fixture(autouse=True)
def mock_update_user_profile():
response = create_response()
patch = mock.patch('directory_sso_api_client.sso_api_client.user.update_user_profile', return_value=response)
yield patch.start()
patch.stop()
@pytest.fixture(autouse=True)
def update_supplier_profile_name():
response = create_response()
patch = mock.patch('directory_api_client.api_client.supplier.profile_update', return_value=response)
yield patch.start()
patch.stop()