Move tests under libra package subdir.

Based on recommended change by Monty Taylor. The package tests do
belong with the package they are testing rather than outside of it.
Moving it requires making it pep8 and pyflakes happy.

Change-Id: If45e2e5240c2e07ca0bb945a103dd3f409546ea4
This commit is contained in:
David Shrewsbury
2013-04-04 16:46:04 -04:00
parent a6405d0ed4
commit 8ede409117
8 changed files with 25 additions and 24 deletions

View File

@@ -1,4 +1,4 @@
[DEFAULT]
test_command=${PYTHON:-python} -m subunit.run discover -t ./ ./tests $LISTOPT $IDOPTION
test_command=${PYTHON:-python} -m subunit.run discover -t ./ ./ $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

View File

@@ -0,0 +1,2 @@
{"server": {"status": "ACTIVE", "updated": "2012-10-10T11:55:55Z", "hostId": "", "user_id": "18290556240782", "name": "lbass_0", "links": [{"href": "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/58012755801586/servers/417773", "rel": "self"}, {"href": "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/58012755801586/servers/417773", "rel": "bookmark"}], "created": "2012-10-10T11:55:55Z", "tenant_id": "58012755801586", "image": {"id": "8419", "links": [{"href": "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/58012755801586/images/8419", "rel": "bookmark"}]}, "adminPass": "u2LKPA73msRTxDMC", "uuid": "14984389-8cc5-4780-be64-2d31ace662ad", "accessIPv4": "", "metadata": {}, "accessIPv6": "", "key_name": "default", "flavor": {"id": "100", "links": [{"href": "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/58012755801586/flavors/100", "rel": "bookmark"}]}, "config_drive": "", "id": 417773, "security_groups": [{"name": "default", "links": [{"href": "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/58012755801586/os-security-groups/4008", "rel": "bookmark"}], "id": 4008}], "addresses": {}}}

View File

@@ -61,5 +61,3 @@ class MockLoggingHandler(logging.Handler):
'error': [],
'critical': [],
}

View File

@@ -1,12 +1,11 @@
import testtools
import tests.mock_objects
from libra.worker.drivers.haproxy.driver import HAProxyDriver
class TestHAProxyDriver(testtools.TestCase):
def setUp(self):
super(TestHAProxyDriver, self).setUp()
self.driver = HAProxyDriver('tests.mock_objects.FakeOSServices',
self.driver = HAProxyDriver('libra.tests.mock_objects.FakeOSServices',
None, None)
def testInit(self):
@@ -80,14 +79,12 @@ class TestHAProxyDriver(testtools.TestCase):
""" Test setting string server weights """
proto = 'http'
self.driver.add_protocol(proto, None)
e = self.assertRaises(
Exception,
self.driver.add_server, proto, '1.2.3.4', 7777, 257)
e = self.assertRaises(Exception, self.driver.add_server,
proto, '1.2.3.4', 7777, 257)
self.assertEqual("Server 'weight' 257 exceeds max of 256", e.message)
e = self.assertRaises(
Exception,
self.driver.add_server, proto, '1.2.3.4', 7777, "abc")
e = self.assertRaises(Exception, self.driver.add_server,
proto, '1.2.3.4', 7777, "abc")
self.assertEqual("Non-integer 'weight' value: 'abc'", e.message)
def testArchive(self):

View File

@@ -1,13 +1,14 @@
import testtools
import logging
import mock
import os
import requests
import json
import testtools
import mock_objects
from libra.mgm.nova import Node, BuildError
fake_body = json.dumps({u'server': {u'status': u'ACTIVE', u'updated': u'2012-10-10T11:55:55Z', u'hostId': u'', u'user_id': u'18290556240782', u'name': u'lbass_0', u'links': [{u'href': u'https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/58012755801586/servers/417773', u'rel': u'self'}, {u'href': u'https://az-1.region-a.geo-1.compute.hpcloudsvc.com/58012755801586/servers/417773', u'rel': u'bookmark'}], u'created': u'2012-10-10T11:55:55Z', u'tenant_id': u'58012755801586', u'image': {u'id': u'8419', u'links': [{u'href': u'https://az-1.region-a.geo-1.compute.hpcloudsvc.com/58012755801586/images/8419', u'rel': u'bookmark'}]}, u'adminPass': u'u2LKPA73msRTxDMC', u'uuid': u'14984389-8cc5-4780-be64-2d31ace662ad', u'accessIPv4': u'', u'metadata': {}, u'accessIPv6': u'', u'key_name': u'default', u'flavor': {u'id': u'100', u'links': [{u'href': u'https://az-1.region-a.geo-1.compute.hpcloudsvc.com/58012755801586/flavors/100', u'rel': u'bookmark'}]}, u'config_drive': u'', u'id': 417773, u'security_groups': [{u'name': u'default', u'links': [{u'href': u'https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/58012755801586/os-security-groups/4008', u'rel': u'bookmark'}], u'id': 4008}], u'addresses': {}}})
fake_body = open(
os.path.join(os.path.dirname(__file__), "fake_body.json"), 'r').read()
class TestResponse(requests.Response):

View File

@@ -21,7 +21,8 @@ class TestLBStatistics(testtools.TestCase):
def testSetBytesIn(self):
self.stats.bytes_in = 99L
self.assertEquals(self.stats.bytes_in, 99L)
e = self.assertRaises(TypeError, setattr, self.stats, 'bytes_in', "NaN")
e = self.assertRaises(TypeError, setattr, self.stats,
'bytes_in', "NaN")
self.assertEqual("Must be a long integer: 'NaN'", e.message)
def testSetBytesOut(self):

View File

@@ -1,6 +1,6 @@
import logging
import testtools
import tests.mock_objects
import libra.tests.mock_objects
from libra.worker.controller import LBaaSController as c
from libra.worker.drivers.base import LoadBalancerDriver
from libra.worker.drivers.haproxy.driver import HAProxyDriver
@@ -10,10 +10,10 @@ class TestWorkerController(testtools.TestCase):
def setUp(self):
super(TestWorkerController, self).setUp()
self.logger = logging.getLogger('test_worker_controller')
self.lh = tests.mock_objects.MockLoggingHandler()
self.lh = libra.tests.mock_objects.MockLoggingHandler()
self.logger.setLevel(logging.DEBUG)
self.logger.addHandler(self.lh)
self.driver = HAProxyDriver('tests.mock_objects.FakeOSServices',
self.driver = HAProxyDriver('libra.tests.mock_objects.FakeOSServices',
None, None)
def testBadAction(self):
@@ -28,7 +28,7 @@ class TestWorkerController(testtools.TestCase):
def testCaseSensitive(self):
msg = {
c.ACTION_FIELD: 'UPDATE',
'LoAdBaLaNcErS': [ { 'protocol': 'http' } ]
'LoAdBaLaNcErS': [{'protocol': 'http'}]
}
controller = c(self.logger, self.driver, msg)
response = controller.run()
@@ -39,8 +39,8 @@ class TestWorkerController(testtools.TestCase):
c.ACTION_FIELD: 'UPDATE',
c.LBLIST_FIELD: [
{
'protocol': 'http',
'nodes': [
'protocol': 'http',
'nodes': [
{
'address': '10.0.0.1',
'port': 80
@@ -92,7 +92,7 @@ class TestWorkerController(testtools.TestCase):
def testCreateMissingNodes(self):
msg = {
c.ACTION_FIELD: 'UPDATE',
c.LBLIST_FIELD: [ { 'protocol': 'http' } ]
c.LBLIST_FIELD: [{'protocol': 'http'}]
}
controller = c(self.logger, self.driver, msg)
response = controller.run()
@@ -103,7 +103,7 @@ class TestWorkerController(testtools.TestCase):
c.ACTION_FIELD: 'UPDATE',
c.LBLIST_FIELD: [
{
'nodes': [
'nodes': [
{
'address': '10.0.0.1',
'port': 80
@@ -138,7 +138,9 @@ class TestWorkerController(testtools.TestCase):
self.assertEquals(response[c.RESPONSE_FIELD], c.RESPONSE_FAILURE)
def testDiscover(self):
msg = { c.ACTION_FIELD: 'DISCOVER' }
msg = {
c.ACTION_FIELD: 'DISCOVER'
}
controller = c(self.logger, self.driver, msg)
response = controller.run()
self.assertIn('version', response)