tests: adapt import StringIO to run tests in python3 (#40012)
This commit is contained in:
parent
932e6da8f3
commit
f128b00b61
|
@ -1,6 +1,6 @@
|
|||
import os
|
||||
import json
|
||||
import StringIO
|
||||
from django.utils.six import StringIO
|
||||
|
||||
import pytest
|
||||
from mock import call, mock_open, patch, Mock
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
""" unit tests (mainly for code coverage)
|
||||
"""
|
||||
import StringIO
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
@ -9,6 +8,8 @@ import pytest
|
|||
from mock import call, patch, Mock
|
||||
from requests import Response, exceptions
|
||||
|
||||
from django.utils.six import StringIO
|
||||
|
||||
from hobo.agent.common.management.commands.hobo_deploy import (
|
||||
replace_file, Command, CommandError)
|
||||
from hobo.agent.hobo.management.commands.hobo_deploy import Command as HoboCommand
|
||||
|
@ -87,14 +88,14 @@ def test_handle_from_scratch():
|
|||
# handle from file
|
||||
command.deploy.reset_mock()
|
||||
with patch('hobo.agent.common.management.commands.hobo_deploy.open') as mocked_open:
|
||||
mocked_open.side_effect = [StringIO.StringIO(CONTENT)]
|
||||
mocked_open.side_effect = [StringIO(CONTENT)]
|
||||
command.handle('https://combo.dev.publik.love/', 'envbof.json')
|
||||
assert command.deploy.mock_calls == EXPECTED
|
||||
|
||||
# handle using a pipe
|
||||
command.deploy.reset_mock()
|
||||
backup = sys.stdin
|
||||
sys.stdin = StringIO.StringIO(CONTENT)
|
||||
sys.stdin = StringIO(CONTENT)
|
||||
command.handle('https://combo.dev.publik.love/', '-')
|
||||
sys.stdin = backup
|
||||
assert command.deploy.mock_calls == EXPECTED
|
||||
|
@ -102,7 +103,7 @@ def test_handle_from_scratch():
|
|||
# JSON having syntax error
|
||||
command.deploy.reset_mock()
|
||||
with patch('hobo.agent.common.management.commands.hobo_deploy.open') as mocked_open:
|
||||
mocked_open.side_effect = [StringIO.StringIO('malformated JSON')]
|
||||
mocked_open.side_effect = [StringIO('malformated JSON')]
|
||||
with pytest.raises(ValueError, match='No JSON object could be decoded'):
|
||||
command.handle('https://combo.dev.publik.love/', 'env.json')
|
||||
assert command.deploy.mock_calls == []
|
||||
|
|
|
@ -5,7 +5,7 @@ import sys
|
|||
from hobo.multitenant.middleware import TenantMiddleware
|
||||
from django.core.management import call_command
|
||||
from django.db import connection
|
||||
import StringIO
|
||||
from django.utils.six import StringIO
|
||||
|
||||
from passerelle.utils import export_site
|
||||
os.sys.path.append('%s/tests' % os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
@ -41,7 +41,7 @@ def test_deploy_specifics(db, tenant_base):
|
|||
]
|
||||
}
|
||||
old_stdin = sys.stdin
|
||||
sys.stdin = StringIO.StringIO(json.dumps(hobo_json))
|
||||
sys.stdin = StringIO(json.dumps(hobo_json))
|
||||
try:
|
||||
call_command('hobo_deploy', 'http://passerelle.example.net', '-')
|
||||
finally:
|
||||
|
|
Loading…
Reference in New Issue