test: improve json response error (#14813)

This commit is contained in:
Josue Kouka 2017-02-06 10:31:40 +01:00
parent 9d1f6af57c
commit 905c44d0ae
1 changed files with 19 additions and 7 deletions

View File

@ -9,7 +9,7 @@ from django.conf import settings
from django.core.management import call_command
from django.http.request import HttpRequest, QueryDict
from django.forms.fields import DateField
from django.test.client import RequestFactory
from django.test.client import RequestFactory, Client
from django.core.urlresolvers import reverse
from mandayejs.mandaye.models import UserCredentials
@ -246,16 +246,28 @@ def test_signed_api_delete(client_service, url_signed):
@mock.patch('mandayejs.mandaye.utils.subprocess.Popen')
def test_phantom_invalid_json(mocked_popen, caplog):
@mock.patch('mandayejs.applications.Test.SITE_LOCATORS', MOCKED_SITE_LOCATORS)
def test_phantom_invalid_json(mocked_popen, caplog, user_john):
expected_output = ('This is not a valid JSON', None)
mocked_popen.return_value = MockedPopen(expected_output=expected_output)
result = exec_phantom(LOGIN_INFO)
for record in caplog.records():
assert record.levelname == 'ERROR'
assert record.message == 'This is not a valid JSON'
UserCredentials.objects.create(user=user_john,
locators={
'login': 'johnny', 'password': 'jumper',
'birth_date': '1995-06-11'})
assert result['result'] == "json_error"
client = Client()
client.login(username='john', password='john')
response = client.get(reverse('post-login-do'))
assert 'window.top.location = "/_mandaye/associate/"' in response.content
for message in response.context['messages']:
assert message.level_tag == 'error'
assert message.message == 'invalid response from server'
for record in caplog.records():
if record.levelname == 'ERROR':
assert record.message == 'invalid json: This is not a valid JSON'
@mock.patch('mandayejs.mandaye.utils.subprocess.Popen')