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

View File

@@ -3,7 +3,7 @@
# Python
import pytest
import mock
from unittest import mock
from dateutil.relativedelta import relativedelta
from datetime import timedelta
@@ -48,7 +48,7 @@ def test_cleanup_older_than(fact_scans, hosts, monkeypatch_jsonbfield_get_db_pre
hosts(5)
fact_scans(28, timestamp_epoch=epoch)
qs = Fact.objects.all().order_by('-timestamp')
fact_middle = qs[qs.count() / 2]
fact_middle = qs[int(qs.count() / 2)]
granularity = relativedelta()
cleanup_facts = CleanupFacts()
@@ -92,7 +92,7 @@ def test_cleanup_logic(fact_scans, hosts, monkeypatch_jsonbfield_get_db_prep_sav
facts = Fact.objects.filter(host__id=host_id, module=module, timestamp__lt=timestamp_middle).order_by('-timestamp')
host_facts[host_id] = facts
for host_id, facts in host_facts.iteritems():
for host_id, facts in host_facts.items():
assert 15 == len(facts)
timestamp_pivot = timestamp_middle
@@ -108,7 +108,7 @@ def test_system_tracking_feature_disabled(mocker):
cmd = Command()
with pytest.raises(CommandError) as err:
cmd.handle(None)
assert 'The System Tracking feature is not enabled for your instance' in err.value
assert 'The System Tracking feature is not enabled for your instance' in str(err.value)
@mock.patch('awx.main.management.commands.cleanup_facts.feature_enabled', new=mock_feature_enabled)
@@ -206,4 +206,4 @@ def test_parameters_fail(mocker):
cmd = Command()
with pytest.raises(CommandError) as err:
cmd.handle(None, older_than=kv['older_than'], granularity=kv['granularity'])
assert kv['msg'] in err.value
assert kv['msg'] in str(err.value)

View File

@@ -1,10 +1,7 @@
import sys
import pytest
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
from django.core.management import call_command

View File

@@ -49,7 +49,7 @@ class TestExpireSessionsCommand:
fake_username = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6))
with pytest.raises(CommandError) as excinfo:
self.run_command(fake_username)
assert excinfo.value.message.strip() == 'The user does not exist.'
assert str(excinfo.value).strip() == 'The user does not exist.'
def test_expire_one_user(self):
# alice should be logged out, but bob should not.

View File

@@ -3,7 +3,7 @@
# Python
import pytest
import mock
from unittest import mock
# Django
from django.core.management.base import CommandError
@@ -91,25 +91,25 @@ class TestInvalidOptionsFunctional:
# Give invalid file to the command
cmd = inventory_import.Command()
with mock.patch('django.db.transaction.rollback'):
with pytest.raises(IOError) as err:
with pytest.raises(OSError) as err:
cmd.handle(
inventory_id=inventory.id,
source='/tmp/pytest-of-root/pytest-7/inv_files0-invalid')
assert 'Source does not exist' in err.value.message
assert 'Source does not exist' in str(err.value)
def test_invalid_inventory_id(self):
cmd = inventory_import.Command()
with pytest.raises(CommandError) as err:
cmd.handle(inventory_id=42, source='/notapath/shouldnotmatter')
assert 'id = 42' in err.value.message
assert 'cannot be found' in err.value.message
assert 'id = 42' in str(err.value)
assert 'cannot be found' in str(err.value)
def test_invalid_inventory_name(self):
cmd = inventory_import.Command()
with pytest.raises(CommandError) as err:
cmd.handle(inventory_name='fooservers', source='/notapath/shouldnotmatter')
assert 'name = fooservers' in err.value.message
assert 'cannot be found' in err.value.message
assert 'name = fooservers' in str(err.value)
assert 'cannot be found' in str(err.value)
@pytest.mark.django_db

View File

@@ -2,7 +2,7 @@
import pytest
import string
import random
import StringIO
from io import StringIO
# Django
from django.contrib.auth.models import User
@@ -13,30 +13,29 @@ from django.core.management.base import CommandError
from awx.main.models.oauth import OAuth2AccessToken
@pytest.mark.django_db
@pytest.mark.inventory_import
class TestOAuth2CreateCommand:
def test_no_user_option(self):
out = StringIO.StringIO()
out = StringIO()
with pytest.raises(CommandError) as excinfo:
call_command('create_oauth2_token', stdout=out)
assert 'Username not supplied.' in excinfo.value.message
assert 'Username not supplied.' in str(excinfo.value)
out.close()
def test_non_existing_user(self):
out = StringIO.StringIO()
out = StringIO()
fake_username = ''
while fake_username == '' or User.objects.filter(username=fake_username).exists():
fake_username = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6))
arg = '--user=' + fake_username
with pytest.raises(CommandError) as excinfo:
call_command('create_oauth2_token', arg, stdout=out)
assert 'The user does not exist.' in excinfo.value.message
assert 'The user does not exist.' in str(excinfo.value)
out.close()
def test_correct_user(self, alice):
out = StringIO.StringIO()
out = StringIO()
arg = '--user=' + 'alice'
call_command('create_oauth2_token', arg, stdout=out)
generated_token = out.getvalue().strip()

View File

@@ -3,7 +3,7 @@ import datetime
import pytest
import string
import random
import StringIO
from io import StringIO
# Django
from django.core.management import call_command
@@ -19,12 +19,12 @@ from awx.api.versioning import reverse
class TestOAuth2RevokeCommand:
def test_non_existing_user(self):
out = StringIO.StringIO()
out = StringIO()
fake_username = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6))
arg = '--user=' + fake_username
with pytest.raises(CommandError) as excinfo:
call_command('revoke_oauth2_tokens', arg, stdout=out)
assert 'A user with that username does not exist' in excinfo.value.message
assert 'A user with that username does not exist' in str(excinfo.value)
out.close()
def test_revoke_all_access_tokens(self, post, admin, alice):