Commit 880da73a authored by Yuan Gao's avatar Yuan Gao
Browse files

Support Python 3 for tests

parent b6b0d993
......@@ -30,7 +30,7 @@ def setup_mocks(mocker):
mocker.patch('mount_efs.start_watchdog')
mocker.patch('mount_efs.get_tls_port_range', return_value=(DEFAULT_TLS_PORT, DEFAULT_TLS_PORT + 10))
mocker.patch('socket.socket', return_value=MagicMock())
mocker.patch('mount_efs.write_tls_tunnel_state_file')
mocker.patch('mount_efs.write_tls_tunnel_state_file', return_value="~mocktempfile")
mocker.patch('os.rename')
mocker.patch('os.kill')
......
......@@ -7,19 +7,26 @@
#
import mount_efs
import ConfigParser
import socket
import pytest
from mock import MagicMock
try:
import ConfigParser
except ImportError:
from configparser import ConfigParser
DEFAULT_TLS_PORT_RANGE_LOW = 20049
DEFAULT_TLS_PORT_RANGE_HIGH = 20449
def _get_config():
config = ConfigParser.SafeConfigParser()
try:
config = ConfigParser.SafeConfigParser()
except AttributeError:
config = ConfigParser()
config.add_section(mount_efs.CONFIG_SECTION)
config.set(mount_efs.CONFIG_SECTION, 'port_range_lower_bound', str(DEFAULT_TLS_PORT_RANGE_LOW))
config.set(mount_efs.CONFIG_SECTION, 'port_range_upper_bound', str(DEFAULT_TLS_PORT_RANGE_HIGH))
......
......@@ -63,7 +63,7 @@ def test_get_dns_name_bad_format_wrong_specifiers(mocker):
with pytest.raises(ValueError) as ex:
mount_efs.get_dns_name(config, FS_ID)
assert 'must include' in ex.value.message
assert 'must include' in str(ex)
def test_get_dns_name_bad_format_too_many_specifiers_1(mocker):
......@@ -72,7 +72,7 @@ def test_get_dns_name_bad_format_too_many_specifiers_1(mocker):
with pytest.raises(ValueError) as ex:
mount_efs.get_dns_name(config, FS_ID)
assert 'incorrect number' in ex.value.message
assert 'incorrect number' in str(ex)
def test_get_dns_name_bad_format_too_many_specifiers_2(mocker):
......@@ -81,7 +81,7 @@ def test_get_dns_name_bad_format_too_many_specifiers_2(mocker):
with pytest.raises(ValueError) as ex:
mount_efs.get_dns_name(config, FS_ID)
assert 'incorrect number' in ex.value.message
assert 'incorrect number' in str(ex)
def test_get_dns_name_unresolvable(mocker, capsys):
......
......@@ -11,7 +11,10 @@ import json
import pytest
from urllib2 import URLError
try:
from urllib2 import URLError
except ImportError:
from urllib.error import URLError
INSTANCE_DATA = {
'devpayProductCodes': None,
......
......@@ -7,13 +7,19 @@
#
import mount_efs
import ConfigParser
import pytest
try:
import ConfigParser
except ImportError:
from configparser import ConfigParser
def _get_config(stunnel_check_cert_validity):
config = ConfigParser.SafeConfigParser()
try:
config = ConfigParser.SafeConfigParser()
except AttributeError:
config = ConfigParser()
config.add_section(mount_efs.CONFIG_SECTION)
if stunnel_check_cert_validity is not None:
config.set(mount_efs.CONFIG_SECTION, 'stunnel_check_cert_validity', str(stunnel_check_cert_validity))
......
......@@ -7,11 +7,15 @@
#
import mount_efs
import ConfigParser
import os
import pytest
try:
import ConfigParser
except ImportError:
from configparser import ConfigParser
FS_ID = 'fs-deadbeef'
DNS_NAME = 'fs-deadbeef.com'
MOUNT_POINT = '/mnt'
......@@ -33,7 +37,10 @@ def _get_config(mocker, stunnel_debug_enabled=False, stunnel_check_cert_hostname
if stunnel_check_cert_validity is None:
stunnel_check_cert_validity = stunnel_check_cert_validity_supported
config = ConfigParser.SafeConfigParser()
try:
config = ConfigParser.SafeConfigParser()
except AttributeError:
config = ConfigParser()
config.add_section(mount_efs.CONFIG_SECTION)
config.set(mount_efs.CONFIG_SECTION, 'stunnel_debug_enabled', str(stunnel_debug_enabled))
config.set(mount_efs.CONFIG_SECTION, 'stunnel_check_cert_hostname', str(stunnel_check_cert_hostname))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment