4
4
import mock
5
5
6
6
from unittest import TestCase
7
- from src .api import CmixAPI , CMIX_SERVICES
8
- from src .error import CmixError
7
+ from CmixAPIClient .api import CmixAPI , CMIX_SERVICES
8
+ from CmixAPIClient .error import CmixError
9
9
10
10
11
11
def default_cmix_api ():
@@ -72,15 +72,15 @@ def test_create_export_archive(self):
72
72
self .assertEqual (response ['response' ], 1 )
73
73
74
74
def test_create_export_archive_errors_handled (self ):
75
- with mock .patch ('src .api.requests.post' ) as mock_post :
75
+ with mock .patch ('CmixAPIClient .api.requests.post' ) as mock_post :
76
76
mock_post_response = mock .Mock ()
77
77
mock_post_response .status_code = 200
78
78
mock_post_response .json .return_value = {
79
79
'response' : 1 ,
80
80
'error' : 'Oops!' ,
81
81
}
82
82
mock_post .return_value = mock_post_response
83
- with mock .patch ('src .api.requests.get' ) as mock_get :
83
+ with mock .patch ('CmixAPIClient .api.requests.get' ) as mock_get :
84
84
# Check CmixError is raised if POST response JSON includes an error.
85
85
mock_response = mock .Mock ()
86
86
mock_response .status_code = 200
@@ -95,7 +95,7 @@ def test_create_export_archive_errors_handled(self):
95
95
# Remove error from POST response.
96
96
mock_post_response .json .return_value = {'response' : 1 }
97
97
98
- with mock .patch ('src .api.requests.get' ) as mock_get :
98
+ with mock .patch ('CmixAPIClient .api.requests.get' ) as mock_get :
99
99
# Check CmixError is raised on GET 500 response. (layout response)
100
100
mock_response = mock .Mock ()
101
101
mock_response .status_code = 500
@@ -119,7 +119,7 @@ def test_create_export_archive_errors_handled(self):
119
119
def test_get_survey_status (self ):
120
120
self .cmix_api ._authentication_headers = {'Authentication' : 'Bearer test' }
121
121
122
- with mock .patch ('src .api.requests' ) as mock_request :
122
+ with mock .patch ('CmixAPIClient .api.requests' ) as mock_request :
123
123
mock_get = mock .Mock ()
124
124
mock_get .status_code = 200
125
125
mock_get .json .return_value = {'status' : 'LIVE' }
@@ -134,7 +134,7 @@ def test_get_survey_status(self):
134
134
def test_get_survey_status_error_handled (self ):
135
135
self .cmix_api ._authentication_headers = {'Authentication' : 'Bearer test' }
136
136
137
- with mock .patch ('src .api.requests' ) as mock_request :
137
+ with mock .patch ('CmixAPIClient .api.requests' ) as mock_request :
138
138
mock_get = mock .Mock ()
139
139
mock_get .status_code = 200
140
140
mock_get .json .return_value = {}
@@ -148,7 +148,7 @@ def test_get_survey_test_url(self):
148
148
correct_test_link = '{}/#/?cmixSvy={}&cmixTest={}' .format (
149
149
CMIX_SERVICES ['test' ]['BASE_URL' ], self .survey_id , 'test' )
150
150
151
- with mock .patch ('src .api.requests' ) as mock_request :
151
+ with mock .patch ('CmixAPIClient .api.requests' ) as mock_request :
152
152
mock_get = mock .Mock ()
153
153
mock_get .status_code = 200
154
154
mock_get .json .return_value = {'testToken' : 'test' }
@@ -158,7 +158,7 @@ def test_get_survey_test_url(self):
158
158
159
159
def test_get_survey_test_url_no_token_handled (self ):
160
160
self .cmix_api ._authentication_headers = {'Authentication' : 'Bearer test' }
161
- with mock .patch ('src .api.requests' ) as mock_request :
161
+ with mock .patch ('CmixAPIClient .api.requests' ) as mock_request :
162
162
mock_get = mock .Mock ()
163
163
mock_get .status_code = 200
164
164
mock_get .json .return_value = {}
@@ -168,7 +168,7 @@ def test_get_survey_test_url_no_token_handled(self):
168
168
self .cmix_api .get_survey_test_url (self .survey_id )
169
169
170
170
def test_get_survey_completes (self ):
171
- with mock .patch ('src .api.requests' ) as mock_request :
171
+ with mock .patch ('CmixAPIClient .api.requests' ) as mock_request :
172
172
mock_post = mock .Mock ()
173
173
mock_post .status_code = 200
174
174
mock_post .json .return_value = {
@@ -184,7 +184,7 @@ def test_get_survey_completes(self):
184
184
self .assertEqual (self .cmix_api .get_survey_completes (self .survey_id ), mock_respondents )
185
185
186
186
def test_get_surveys (self ):
187
- with mock .patch ('src .api.requests' ) as mock_request :
187
+ with mock .patch ('CmixAPIClient .api.requests' ) as mock_request :
188
188
mock_post = mock .Mock ()
189
189
mock_post .status_code = 200
190
190
mock_post .json .return_value = {
@@ -208,7 +208,7 @@ def test_get_surveys(self):
208
208
mock_request .get .assert_any_call (expected_url_with_params , headers = self .cmix_api ._authentication_headers )
209
209
210
210
def test_fetch_banner_filter (self ):
211
- with mock .patch ('src .api.requests' ) as mock_request :
211
+ with mock .patch ('CmixAPIClient .api.requests' ) as mock_request :
212
212
mock_post = mock .Mock ()
213
213
mock_post .status_code = 200
214
214
mock_post .json .return_value = {
@@ -245,7 +245,7 @@ def test_get_archive_status(self):
245
245
survey_id = 1337
246
246
archive_id = 12
247
247
layout_id = 1
248
- with mock .patch ('src .api.requests.get' ) as mock_request :
248
+ with mock .patch ('CmixAPIClient .api.requests.get' ) as mock_request :
249
249
mock_response = mock .Mock ()
250
250
mock_response .status_code = 200
251
251
mock_response .json .return_value = {
0 commit comments