Fixing up more pep8 issues

This commit is contained in:
Matthew Jones
2015-02-04 16:32:04 -05:00
parent fb9e231189
commit 9e97783b13
16 changed files with 178 additions and 186 deletions

View File

@@ -348,7 +348,7 @@ class HostAccess(BaseAccess):
return obj and self.user.can_access(Inventory, 'read', obj.inventory) return obj and self.user.can_access(Inventory, 'read', obj.inventory)
def can_add(self, data): def can_add(self, data):
if not data or not 'inventory' in data: if not data or 'inventory' not in data:
return False return False
# Checks for admin or change permission on inventory. # Checks for admin or change permission on inventory.
@@ -419,7 +419,7 @@ class GroupAccess(BaseAccess):
return obj and self.user.can_access(Inventory, 'read', obj.inventory) return obj and self.user.can_access(Inventory, 'read', obj.inventory)
def can_add(self, data): def can_add(self, data):
if not data or not 'inventory' in data: if not data or 'inventory' not in data:
return False return False
# Checks for admin or change permission on inventory. # Checks for admin or change permission on inventory.
inventory_pk = get_pk_from_dict(data, 'inventory') inventory_pk = get_pk_from_dict(data, 'inventory')

View File

@@ -38,8 +38,7 @@ from django.utils.timezone import now
# AWX # AWX
from awx.main.constants import CLOUD_PROVIDERS from awx.main.constants import CLOUD_PROVIDERS
from awx.main.models import * # Job, JobEvent, ProjectUpdate, InventoryUpdate, from awx.main.models import *
# Schedule, UnifiedJobTemplate, Instance
from awx.main.queue import FifoQueue from awx.main.queue import FifoQueue
from awx.main.utils import (get_ansible_version, decrypt_field, update_scm_url, from awx.main.utils import (get_ansible_version, decrypt_field, update_scm_url,
ignore_inventory_computed_fields, emit_websocket_notification, ignore_inventory_computed_fields, emit_websocket_notification,

View File

@@ -170,8 +170,7 @@ class BaseTestMixin(QueueTestMixin):
contact_name='AWX Admin', contact_name='AWX Admin',
contact_email='awx@example.com', contact_email='awx@example.com',
license_date=int(time.time() + 3600), license_date=int(time.time() + 3600),
instance_count=instance_count, instance_count=instance_count)
)
handle, license_path = tempfile.mkstemp(suffix='.json') handle, license_path = tempfile.mkstemp(suffix='.json')
os.close(handle) os.close(handle)
writer.write_file(license_path) writer.write_file(license_path)
@@ -633,6 +632,7 @@ class URI(object):
def __string__(self): def __string__(self):
return self.get_uri() return self.get_uri()
def __repr__(self): def __repr__(self):
return self.get_uri() return self.get_uri()

View File

@@ -60,8 +60,7 @@ class InventoryTest(BaseTest):
self.perm_read = Permission.objects.create( self.perm_read = Permission.objects.create(
inventory = self.inventory_b, inventory = self.inventory_b,
user = self.other_django_user, user = self.other_django_user,
permission_type = 'read' permission_type = 'read')
)
def tearDown(self): def tearDown(self):
super(InventoryTest, self).tearDown() super(InventoryTest, self).tearDown()
@@ -346,8 +345,7 @@ class InventoryTest(BaseTest):
edit_perm = Permission.objects.create( edit_perm = Permission.objects.create(
user = self.other_django_user, user = self.other_django_user,
inventory = Inventory.objects.get(pk=inv.pk), inventory = Inventory.objects.get(pk=inv.pk),
permission_type = PERM_INVENTORY_WRITE permission_type = PERM_INVENTORY_WRITE)
)
host_data3 = self.post(hosts, data=new_host_c, expect=201, auth=self.get_other_credentials()) host_data3 = self.post(hosts, data=new_host_c, expect=201, auth=self.get_other_credentials())
# Port should be split out into host variables, other variables kept intact. # Port should be split out into host variables, other variables kept intact.
@@ -1143,15 +1141,15 @@ class InventoryUpdatesTest(BaseTransactionTest):
#print inventory_update.result_stdout #print inventory_update.result_stdout
if should_error: if should_error:
self.assertEqual(inventory_update.status, 'error', self.assertEqual(inventory_update.status, 'error',
inventory_update.result_stdout + \ inventory_update.result_stdout +
inventory_update.result_traceback) inventory_update.result_traceback)
elif should_fail: elif should_fail:
self.assertEqual(inventory_update.status, 'failed', self.assertEqual(inventory_update.status, 'failed',
inventory_update.result_stdout + \ inventory_update.result_stdout +
inventory_update.result_traceback) inventory_update.result_traceback)
elif should_fail is False: elif should_fail is False:
self.assertEqual(inventory_update.status, 'successful', self.assertEqual(inventory_update.status, 'successful',
inventory_update.result_stdout + \ inventory_update.result_stdout +
inventory_update.result_traceback) inventory_update.result_traceback)
else: else:
pass # If should_fail is None, we don't care. pass # If should_fail is None, we don't care.
@@ -1673,6 +1671,7 @@ class InventoryUpdatesTest(BaseTransactionTest):
return return
# Print out group/host tree for debugging. # Print out group/host tree for debugging.
print print
def draw_tree(g, d=0): def draw_tree(g, d=0):
print (' ' * d) + '+ ' + g.name print (' ' * d) + '+ ' + g.name
for h in g.hosts.order_by('name'): for h in g.hosts.order_by('name'):

View File

@@ -399,16 +399,14 @@ class BaseJobTestMixin(BaseTestMixin):
# Greg and Holly work on east, Greg and iris work on west. # Greg and Holly work on east, Greg and iris work on west.
self.team_ops_east = self.org_ops.teams.create( self.team_ops_east = self.org_ops.teams.create(
name='easterners', name='easterners',
created_by=self.user_sue, created_by=self.user_sue)
)
self.team_ops_east.projects.add(self.proj_prod) self.team_ops_east.projects.add(self.proj_prod)
self.team_ops_east.projects.add(self.proj_prod_east) self.team_ops_east.projects.add(self.proj_prod_east)
self.team_ops_east.users.add(self.user_greg) self.team_ops_east.users.add(self.user_greg)
self.team_ops_east.users.add(self.user_holly) self.team_ops_east.users.add(self.user_holly)
self.team_ops_west = self.org_ops.teams.create( self.team_ops_west = self.org_ops.teams.create(
name='westerners', name='westerners',
created_by=self.user_sue, created_by=self.user_sue)
)
self.team_ops_west.projects.add(self.proj_prod) self.team_ops_west.projects.add(self.proj_prod)
self.team_ops_west.projects.add(self.proj_prod_west) self.team_ops_west.projects.add(self.proj_prod_west)
self.team_ops_west.users.add(self.user_greg) self.team_ops_west.users.add(self.user_greg)

View File

@@ -47,8 +47,7 @@ class LicenseTests(BaseTest):
contact_name='Michael DeHaan', contact_name='Michael DeHaan',
contact_email='michael@ansibleworks.com', contact_email='michael@ansibleworks.com',
license_date=25000, # seconds since epoch license_date=25000, # seconds since epoch
instance_count=500 instance_count=500)
)
data = writer.get_data() data = writer.get_data()
@@ -69,12 +68,12 @@ class LicenseTests(BaseTest):
assert vdata['available_instances'] == 500 assert vdata['available_instances'] == 500
assert vdata['current_instances'] == 12 assert vdata['current_instances'] == 12
assert vdata['free_instances'] == 488 assert vdata['free_instances'] == 488
assert vdata['date_warning'] == True assert vdata['date_warning'] is True
assert vdata['date_expired'] == True assert vdata['date_expired'] is True
assert vdata['license_date'] == 25000 assert vdata['license_date'] == 25000
assert vdata['time_remaining'] < 0 assert vdata['time_remaining'] < 0
assert vdata['valid_key'] == True assert vdata['valid_key'] is True
assert vdata['compliant'] == False assert vdata['compliant'] is False
def test_expired_licenses(self): def test_expired_licenses(self):
reader = TaskSerializer() reader = TaskSerializer()
@@ -88,7 +87,7 @@ class LicenseTests(BaseTest):
strdata = writer.get_string() strdata = writer.get_string()
vdata = reader.from_string(strdata) vdata = reader.from_string(strdata)
assert vdata['compliant'] == False assert vdata['compliant'] is False
assert vdata['grace_period_remaining'] < 0 assert vdata['grace_period_remaining'] < 0
writer = TaskEngager( writer = TaskEngager(
@@ -101,7 +100,7 @@ class LicenseTests(BaseTest):
strdata = writer.get_string() strdata = writer.get_string()
vdata = reader.from_string(strdata) vdata = reader.from_string(strdata)
assert vdata['compliant'] == False assert vdata['compliant'] is False
assert vdata['grace_period_remaining'] < 0 assert vdata['grace_period_remaining'] < 0
writer = TaskEngager( writer = TaskEngager(
@@ -114,5 +113,5 @@ class LicenseTests(BaseTest):
strdata = writer.get_string() strdata = writer.get_string()
vdata = reader.from_string(strdata) vdata = reader.from_string(strdata)
assert vdata['compliant'] == False assert vdata['compliant'] is False
assert vdata['grace_period_remaining'] > 0 assert vdata['grace_period_remaining'] > 0

View File

@@ -932,6 +932,7 @@ class ProjectUpdatesTest(BaseTransactionTest):
# FIXME: Add some invalid URLs. # FIXME: Add some invalid URLs.
] ]
def is_exception(e): def is_exception(e):
return bool(isinstance(e, Exception) or return bool(isinstance(e, Exception) or
(isinstance(e, type) and issubclass(e, Exception))) (isinstance(e, type) and issubclass(e, Exception)))
@@ -1320,8 +1321,7 @@ class ProjectUpdatesTest(BaseTransactionTest):
scm_password=scm_password, scm_password=scm_password,
) )
should_error = bool('github.com' in scm_url and scm_username != 'git') should_error = bool('github.com' in scm_url and scm_username != 'git')
self.check_project_update(project2, should_fail=None)#, self.check_project_update(project2, should_fail=None) # , should_error=should_error)
#should_error=should_error)
def test_scm_key_unlock_on_project_update(self): def test_scm_key_unlock_on_project_update(self):
scm_url = 'git@github.com:ansible/ansible.github.com.git' scm_url = 'git@github.com:ansible/ansible.github.com.git'
@@ -1630,8 +1630,7 @@ class ProjectUpdatesTest(BaseTransactionTest):
name='my public git project over https', name='my public git project over https',
scm_type='git', scm_type='git',
scm_url=scm_url, scm_url=scm_url,
scm_update_on_launch=True, scm_update_on_launch=True)
)
# First update triggered by saving a new project with SCM. # First update triggered by saving a new project with SCM.
self.assertEqual(self.project.project_updates.count(), 1) self.assertEqual(self.project.project_updates.count(), 1)
self.check_project_update(self.project) self.check_project_update(self.project)

View File

@@ -36,8 +36,7 @@ GOOD_SCHEDULES = ["DTSTART:20500331T055000Z RRULE:FREQ=MINUTELY;INTERVAL=10;COUN
"DTSTART:20140331T075000Z RRULE:FREQ=YEARLY;INTERVAL=1;BYSETPOS=-1;BYMONTH=8;BYDAY=SU", "DTSTART:20140331T075000Z RRULE:FREQ=YEARLY;INTERVAL=1;BYSETPOS=-1;BYMONTH=8;BYDAY=SU",
"DTSTART:20140331T075000Z RRULE:FREQ=WEEKLY;INTERVAL=1;UNTIL=20230401T075000Z;BYDAY=MO,WE,FR", "DTSTART:20140331T075000Z RRULE:FREQ=WEEKLY;INTERVAL=1;UNTIL=20230401T075000Z;BYDAY=MO,WE,FR",
"DTSTART:20140331T075000Z RRULE:FREQ=HOURLY;INTERVAL=1;UNTIL=20230610T075000Z", "DTSTART:20140331T075000Z RRULE:FREQ=HOURLY;INTERVAL=1;UNTIL=20230610T075000Z",
"DTSTART:20140411T040000Z RRULE:FREQ=WEEKLY;INTERVAL=1;UNTIL=20140411T040000Z;BYDAY=WE", "DTSTART:20140411T040000Z RRULE:FREQ=WEEKLY;INTERVAL=1;UNTIL=20140411T040000Z;BYDAY=WE"]
]
BAD_SCHEDULES = ["", "DTSTART:20140331T055000 RRULE:FREQ=MINUTELY;INTERVAL=10;COUNT=5", BAD_SCHEDULES = ["", "DTSTART:20140331T055000 RRULE:FREQ=MINUTELY;INTERVAL=10;COUNT=5",
"RRULE:FREQ=MINUTELY;INTERVAL=10;COUNT=5", "RRULE:FREQ=MINUTELY;INTERVAL=10;COUNT=5",
"FREQ=MINUTELY;INTERVAL=10;COUNT=5", "FREQ=MINUTELY;INTERVAL=10;COUNT=5",
@@ -51,8 +50,7 @@ BAD_SCHEDULES = ["", "DTSTART:20140331T055000 RRULE:FREQ=MINUTELY;INTERVAL=10;CO
"DTSTART:20140331T055000Z RRULE:FREQ=YEARLY;BYYEARDAY=120;INTERVAL=1", "DTSTART:20140331T055000Z RRULE:FREQ=YEARLY;BYYEARDAY=120;INTERVAL=1",
"DTSTART:20140331T055000Z RRULE:FREQ=YEARLY;BYWEEKNO=10;INTERVAL=1", "DTSTART:20140331T055000Z RRULE:FREQ=YEARLY;BYWEEKNO=10;INTERVAL=1",
"DTSTART:20140331T055000Z RRULE:FREQ=HOURLY;INTERVAL=1 DTSTART:20140331T055000Z RRULE:FREQ=HOURLY;INTERVAL=1", "DTSTART:20140331T055000Z RRULE:FREQ=HOURLY;INTERVAL=1 DTSTART:20140331T055000Z RRULE:FREQ=HOURLY;INTERVAL=1",
"DTSTART:20140331T055000Z RRULE:FREQ=HOURLY;INTERVAL=1 RRULE:FREQ=HOURLY;INTERVAL=1", "DTSTART:20140331T055000Z RRULE:FREQ=HOURLY;INTERVAL=1 RRULE:FREQ=HOURLY;INTERVAL=1"]
]
class ScheduleTest(BaseTest): class ScheduleTest(BaseTest):
def setUp(self): def setUp(self):

View File

@@ -52,7 +52,7 @@ class BaseScriptTest(BaseLiveServerTest):
pargs = [name] pargs = [name]
for k,v in options.items(): for k,v in options.items():
pargs.append('%s%s' % ('-' if len(k) == 1 else '--', k)) pargs.append('%s%s' % ('-' if len(k) == 1 else '--', k))
if not v is True: if v is not True:
pargs.append(str(v)) pargs.append(str(v))
for arg in args: for arg in args:
pargs.append(str(arg)) pargs.append(str(arg))

View File

@@ -14,4 +14,4 @@
# W391 - Blank line at end of file # W391 - Blank line at end of file
# W293 - Blank line contains whitespace # W293 - Blank line contains whitespace
ignore=E201,E203,E221,E225,E231,E241,E251,E261,E265,E302,E303,E501,W291,W391,W293 ignore=E201,E203,E221,E225,E231,E241,E251,E261,E265,E302,E303,E501,W291,W391,W293
exclude=awx/lib/site-packages,awx/ui,awx/api/urls.py,awx/main/migrations exclude=awx/lib/site-packages,awx/ui,awx/api/urls.py,awx/main/migrations,awx/main/tests/data