convert py2 -> py3

This commit is contained in:
Ryan Petrello
2018-10-22 12:58:42 -04:00
parent f132ce9b64
commit f223df303f
202 changed files with 1137 additions and 2046 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ import pytest
from uuid import uuid4
import json
import yaml
import mock
from unittest import mock
from backports.tempfile import TemporaryDirectory
from django.conf import settings
+3 -11
View File
@@ -10,14 +10,14 @@ def test_encrypt_field():
field = Setting(pk=123, value='ANSIBLE')
encrypted = field.value = encryption.encrypt_field(field, 'value')
assert encryption.decrypt_field(field, 'value') == 'ANSIBLE'
assert encrypted.startswith('$encrypted$AESCBC$')
assert encrypted.startswith('$encrypted$UTF8$AESCBC$')
def test_encrypt_field_without_pk():
field = Setting(value='ANSIBLE')
encrypted = field.value = encryption.encrypt_field(field, 'value')
assert encryption.decrypt_field(field, 'value') == 'ANSIBLE'
assert encrypted.startswith('$encrypted$AESCBC$')
assert encrypted.startswith('$encrypted$UTF8$AESCBC$')
def test_encrypt_field_with_unicode_string():
@@ -28,19 +28,11 @@ def test_encrypt_field_with_unicode_string():
assert encrypted.startswith('$encrypted$UTF8$AESCBC$')
def test_encrypt_field_force_disable_unicode():
value = u"NothingSpecial"
field = Setting(value=value)
encrypted = field.value = encryption.encrypt_field(field, 'value', skip_utf8=True)
assert "UTF8" not in encrypted
assert encryption.decrypt_field(field, 'value') == value
def test_encrypt_subfield():
field = Setting(value={'name': 'ANSIBLE'})
encrypted = field.value = encryption.encrypt_field(field, 'value', subfield='name')
assert encryption.decrypt_field(field, 'value', subfield='name') == 'ANSIBLE'
assert encrypted.startswith('$encrypted$AESCBC$')
assert encrypted.startswith('$encrypted$UTF8$AESCBC$')
def test_encrypt_field_with_ask():
@@ -1,10 +1,9 @@
import pytest
import base64
import json
from StringIO import StringIO
from six.moves import xrange
from io import StringIO
from django.utils.encoding import smart_bytes, smart_str
from awx.main.utils import OutputEventFilter, OutputVerboseFilter
MAX_WIDTH = 78
@@ -12,14 +11,14 @@ EXAMPLE_UUID = '890773f5-fe6d-4091-8faf-bdc8021d65dd'
def write_encoded_event_data(fileobj, data):
b64data = base64.b64encode(json.dumps(data))
b64data = smart_str(base64.b64encode(smart_bytes(json.dumps(data))))
# pattern corresponding to OutputEventFilter expectation
fileobj.write(u'\x1b[K')
for offset in xrange(0, len(b64data), MAX_WIDTH):
fileobj.write('\x1b[K')
for offset in range(0, len(b64data), MAX_WIDTH):
chunk = b64data[offset:offset + MAX_WIDTH]
escaped_chunk = u'{}\x1b[{}D'.format(chunk, len(chunk))
escaped_chunk = '{}\x1b[{}D'.format(chunk, len(chunk))
fileobj.write(escaped_chunk)
fileobj.write(u'\x1b[K')
fileobj.write('\x1b[K')
@pytest.fixture
+2 -2
View File
@@ -1,7 +1,7 @@
# Python
import pytest
import mock
from unittest import mock
# AWX
from awx.main.utils.filters import SmartFilter, ExternalLoggerEnabled
@@ -120,7 +120,7 @@ class TestSmartFilterQueryFromString():
def test_invalid_filter_strings(self, mock_get_host_model, filter_string):
with pytest.raises(RuntimeError) as e:
SmartFilter.query_from_string(filter_string)
assert e.value.message == u"Invalid query " + filter_string
assert str(e.value) == u"Invalid query " + filter_string
@pytest.mark.parametrize("filter_string", [
'created_by__password__icontains=pbkdf2'
+7 -6
View File
@@ -1,15 +1,16 @@
# -*- coding: utf-8 -*-
import base64
import cStringIO
import logging
import socket
import datetime
from dateutil.tz import tzutc
from io import StringIO
from uuid import uuid4
import mock
from unittest import mock
from django.conf import LazySettings
from django.utils.encoding import smart_str
import pytest
import requests
from requests_futures.sessions import FuturesSession
@@ -52,7 +53,7 @@ def connection_error_adapter():
@pytest.fixture
def fake_socket(tmpdir_factory, request):
sok = socket._socketobject
sok = socket.socket
sok.send = mock.MagicMock()
sok.connect = mock.MagicMock()
sok.setblocking = mock.MagicMock()
@@ -255,7 +256,7 @@ def test_https_logging_handler_connection_error(connection_error_adapter,
handler.setFormatter(LogstashFormatter())
handler.session.mount('http://', connection_error_adapter)
buff = cStringIO.StringIO()
buff = StringIO()
logging.getLogger('awx.main.utils.handlers').addHandler(
logging.StreamHandler(buff)
)
@@ -308,7 +309,7 @@ def test_https_logging_handler_emit_logstash_with_creds(https_adapter,
assert len(https_adapter.requests) == 1
request = https_adapter.requests[0]
assert request.headers['Authorization'] == 'Basic %s' % base64.b64encode("user:pass")
assert request.headers['Authorization'] == 'Basic %s' % smart_str(base64.b64encode(b"user:pass"))
def test_https_logging_handler_emit_splunk_with_creds(https_adapter,
@@ -331,7 +332,7 @@ def test_https_logging_handler_emit_splunk_with_creds(https_adapter,
({u'测试键': u'测试值'}, '{"测试键": "测试值"}'),
])
def test_encode_payload_for_socket(payload, encoded_payload):
assert _encode_payload_for_socket(payload) == encoded_payload
assert _encode_payload_for_socket(payload).decode('utf-8') == encoded_payload
def test_udp_handler_create_socket_at_init():