Révision 905c44d0
Ajouté par Josué Kouka il y a plus de 7 ans
tests/test_mandayejs.py | ||
---|---|---|
9 | 9 |
from django.core.management import call_command |
10 | 10 |
from django.http.request import HttpRequest, QueryDict |
11 | 11 |
from django.forms.fields import DateField |
12 |
from django.test.client import RequestFactory |
|
12 |
from django.test.client import RequestFactory, Client
|
|
13 | 13 |
from django.core.urlresolvers import reverse |
14 | 14 |
|
15 | 15 |
from mandayejs.mandaye.models import UserCredentials |
... | ... | |
246 | 246 |
|
247 | 247 |
|
248 | 248 |
@mock.patch('mandayejs.mandaye.utils.subprocess.Popen') |
249 |
def test_phantom_invalid_json(mocked_popen, caplog): |
|
249 |
@mock.patch('mandayejs.applications.Test.SITE_LOCATORS', MOCKED_SITE_LOCATORS) |
|
250 |
def test_phantom_invalid_json(mocked_popen, caplog, user_john): |
|
250 | 251 |
expected_output = ('This is not a valid JSON', None) |
251 | 252 |
mocked_popen.return_value = MockedPopen(expected_output=expected_output) |
252 | 253 |
|
253 |
result = exec_phantom(LOGIN_INFO) |
|
254 |
for record in caplog.records(): |
|
255 |
assert record.levelname == 'ERROR' |
|
256 |
assert record.message == 'This is not a valid JSON' |
|
254 |
UserCredentials.objects.create(user=user_john, |
|
255 |
locators={ |
|
256 |
'login': 'johnny', 'password': 'jumper', |
|
257 |
'birth_date': '1995-06-11'}) |
|
258 |
|
|
259 |
client = Client() |
|
260 |
client.login(username='john', password='john') |
|
261 |
response = client.get(reverse('post-login-do')) |
|
262 |
assert 'window.top.location = "/_mandaye/associate/"' in response.content |
|
257 | 263 |
|
258 |
assert result['result'] == "json_error" |
|
264 |
for message in response.context['messages']: |
|
265 |
assert message.level_tag == 'error' |
|
266 |
assert message.message == 'invalid response from server' |
|
267 |
|
|
268 |
for record in caplog.records(): |
|
269 |
if record.levelname == 'ERROR': |
|
270 |
assert record.message == 'invalid json: This is not a valid JSON' |
|
259 | 271 |
|
260 | 272 |
|
261 | 273 |
@mock.patch('mandayejs.mandaye.utils.subprocess.Popen') |
Formats disponibles : Unified diff
test: improve json response error (#14813)