flake8 fixes

This commit is contained in:
Chris Meyers 2015-04-03 14:55:37 -04:00
parent f5600be39e
commit a769af0e83
8 changed files with 53 additions and 59 deletions

View File

@ -3,17 +3,13 @@
import logging
from datetime import datetime
import json
from django.core.management.base import NoArgsCommand
from awx.main.models import * # noqa
from awx.main.socket import Socket
import pymongo
from pymongo import MongoClient
_MODULES = [ 'packages', 'services', 'files' ]
_MODULES = ['packages', 'services', 'files']
logger = logging.getLogger('awx.main.commands.run_fact_cache_receiver')
class FactCacheReceiver(object):
@ -49,10 +45,10 @@ class FactCacheReceiver(object):
try:
host = FactHost.objects.get(hostname=hostname)
except FactHost.DoesNotExist as e:
except FactHost.DoesNotExist:
host = FactHost(hostname=hostname)
host.save()
except FactHost.MultipleObjectsReturned as e:
except FactHost.MultipleObjectsReturned:
query = "db['fact_host'].find(hostname=%s)" % hostname
print('Database inconsistent. Multiple FactHost "%s" exist. Try the query %s to find the records.' % (hostname, query))
return

View File

@ -1,15 +1,15 @@
from mongoengine import Document, DynamicDocument, DateTimeField, ReferenceField, StringField
class FactHost(Document):
hostname = StringField(max_length=100, required=True, unique=True)
hostname = StringField(max_length=100, required=True, unique=True)
# TODO: Consider using hashed index on hostname. django-mongo may not support this but
# executing raw js will
meta = {
meta = {
'indexes': [
'hostname'
'hostname'
]
}
}
class Fact(DynamicDocument):
timestamp = DateTimeField(required=True)

View File

@ -49,7 +49,7 @@ class MongoDBRequired(django.test.TestCase):
try:
self.db = get_db()
self.db.connection.drop_database(settings.MONGO_DB)
except ConnectionError as e:
except ConnectionError:
self.skipTest('MongoDB connection failed')
class QueueTestMixin(object):

View File

@ -2,4 +2,4 @@
# All Rights Reserved
from awx.main.tests.commands.run_fact_cache_receiver import * # noqa
from awx.main.tests.commands.commands_monolithic import * # noqa
from awx.main.tests.commands.commands_monolithic import * # noqa

View File

@ -5,16 +5,15 @@
import time
from datetime import datetime
import mock
import json
import unittest
from copy import deepcopy
from mock import Mock, MagicMock
from mock import MagicMock
# AWX
from awx.main.tests.base import BaseTest, MongoDBRequired
from awx.main.tests.commands.base import BaseCommandMixin
from awx.main.management.commands.run_fact_cache_receiver import FactCacheReceiver, _MODULES
from awx.main.models.fact import *
from awx.main.management.commands.run_fact_cache_receiver import FactCacheReceiver
from awx.main.models.fact import * # noqa
__all__ = ['RunFactCacheReceiverUnitTest', 'RunFactCacheReceiverFunctionalTest']
@ -27,28 +26,28 @@ TEST_MSG_BASE = {
TEST_MSG_MODULES = {
'packages': {
"accountsservice": [
{
"architecture": "amd64",
"name": "accountsservice",
"source": "apt",
"version": "0.6.35-0ubuntu7.1"
}
{
"architecture": "amd64",
"name": "accountsservice",
"source": "apt",
"version": "0.6.35-0ubuntu7.1"
}
],
"acpid": [
{
"architecture": "amd64",
"name": "acpid",
"source": "apt",
"version": "1:2.0.21-1ubuntu2"
}
{
"architecture": "amd64",
"name": "acpid",
"source": "apt",
"version": "1:2.0.21-1ubuntu2"
}
],
"adduser": [
{
"architecture": "all",
"name": "adduser",
"source": "apt",
"version": "3.113+nmu3ubuntu3"
}
{
"architecture": "all",
"name": "adduser",
"source": "apt",
"version": "3.113+nmu3ubuntu3"
}
],
},
'services': [
@ -135,7 +134,7 @@ class RunFactCacheReceiverUnitTest(BaseTest, MongoDBRequired):
# Ensure that the message flows from the socket through to process_fact_message()
@mock.patch('awx.main.socket.Socket.listen')
def test_run_receiver(self, listen_mock):
listen_mock.return_value = [ TEST_MSG ]
listen_mock.return_value = [TEST_MSG]
receiver = FactCacheReceiver()
receiver.process_fact_message = MagicMock(name='process_fact_message')

View File

@ -3,7 +3,6 @@
# Python
from datetime import datetime
from mongoengine.connection import get_db
from mongoengine import connect
# Django
@ -11,7 +10,7 @@ from django.conf import settings
# AWX
from awx.main.tests.base import BaseTest, MongoDBRequired
from awx.main.models.fact import *
from awx.main.models.fact import * # noqa
__all__ = ['DBTransformTest']
@ -75,4 +74,4 @@ class DBTransformTest(BaseTest, MongoDBRequired):
def test_key_transform_dollar_on_retreive(self):
self.create_dollar_fact()
self.check_transform()
self.check_transform()

View File

@ -1,4 +1,4 @@
# Copyright (c) 2015 Ansible, Inc.
# All Rights Reserved
from awx.main.tests.models.fact import * # noqa
from awx.main.tests.models.fact import * # noqa

View File

@ -7,7 +7,7 @@ from datetime import datetime
# Django
# AWX
from awx.main.models.fact import *
from awx.main.models.fact import * # noqa
from awx.main.tests.base import BaseTest, MongoDBRequired
__all__ = ['FactHostTest', 'FactTest']
@ -20,28 +20,28 @@ TEST_FACT_DATA = {
'module': 'packages',
'fact': {
"accountsservice": [
{
"architecture": "amd64",
"name": "accountsservice",
"source": "apt",
"version": "0.6.35-0ubuntu7.1"
}
{
"architecture": "amd64",
"name": "accountsservice",
"source": "apt",
"version": "0.6.35-0ubuntu7.1"
}
],
"acpid": [
{
"architecture": "amd64",
"name": "acpid",
"source": "apt",
"version": "1:2.0.21-1ubuntu2"
}
{
"architecture": "amd64",
"name": "acpid",
"source": "apt",
"version": "1:2.0.21-1ubuntu2"
}
],
"adduser": [
{
"architecture": "all",
"name": "adduser",
"source": "apt",
"version": "3.113+nmu3ubuntu3"
}
{
"architecture": "all",
"name": "adduser",
"source": "apt",
"version": "3.113+nmu3ubuntu3"
}
],
},
}