Fixing tests to work with python 2.6
This commit is contained in:
		@@ -19,7 +19,9 @@
 | 
			
		||||
# IN THE SOFTWARE.
 | 
			
		||||
 | 
			
		||||
import os
 | 
			
		||||
import re
 | 
			
		||||
import sys
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def setup_sys_path():
 | 
			
		||||
@@ -45,3 +47,57 @@ setup_environment()
 | 
			
		||||
from stacktach import stacklog
 | 
			
		||||
 | 
			
		||||
stacklog.set_default_logger_location("/tmp/%s.log")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class _AssertRaisesContext(object):
 | 
			
		||||
    """A context manager used to implement TestCase.assertRaises* methods."""
 | 
			
		||||
 | 
			
		||||
    def __init__(self, expected, test_case, expected_regexp=None):
 | 
			
		||||
        self.expected = expected
 | 
			
		||||
        self.failureException = test_case.failureException
 | 
			
		||||
        self.expected_regexp = expected_regexp
 | 
			
		||||
 | 
			
		||||
    def __enter__(self):
 | 
			
		||||
        return self
 | 
			
		||||
 | 
			
		||||
    def __exit__(self, exc_type, exc_value, tb):
 | 
			
		||||
        if exc_type is None:
 | 
			
		||||
            try:
 | 
			
		||||
                exc_name = self.expected.__name__
 | 
			
		||||
            except AttributeError:
 | 
			
		||||
                exc_name = str(self.expected)
 | 
			
		||||
            raise self.failureException(
 | 
			
		||||
                "{0} not raised".format(exc_name))
 | 
			
		||||
        if not issubclass(exc_type, self.expected):
 | 
			
		||||
            # let unexpected exceptions pass through
 | 
			
		||||
            return False
 | 
			
		||||
        self.exception = exc_value # store for later retrieval
 | 
			
		||||
        if self.expected_regexp is None:
 | 
			
		||||
            return True
 | 
			
		||||
 | 
			
		||||
        expected_regexp = self.expected_regexp
 | 
			
		||||
        if isinstance(expected_regexp, basestring):
 | 
			
		||||
            expected_regexp = re.compile(expected_regexp)
 | 
			
		||||
        if not expected_regexp.search(str(exc_value)):
 | 
			
		||||
            raise self.failureException('"%s" does not match "%s"' %
 | 
			
		||||
                     (expected_regexp.pattern, str(exc_value)))
 | 
			
		||||
        return True
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class StacktachBaseTestCase(unittest.TestCase):
 | 
			
		||||
 | 
			
		||||
    def assertIsNotNone(self, obj, msg=None):
 | 
			
		||||
        self.assertTrue(obj is not None, msg)
 | 
			
		||||
 | 
			
		||||
    def assertIsNone(self, obj, msg=None):
 | 
			
		||||
        self.assertTrue(obj is None, msg)
 | 
			
		||||
 | 
			
		||||
    def assertIsInstance(self, obj, cls, msg=None):
 | 
			
		||||
        self.assertTrue(isinstance(obj, cls), msg)
 | 
			
		||||
 | 
			
		||||
    def assertRaises(self, excClass, callableObj=None, *args, **kwargs):
 | 
			
		||||
        context = _AssertRaisesContext(excClass, self)
 | 
			
		||||
        if callableObj is None:
 | 
			
		||||
            return context
 | 
			
		||||
        with context:
 | 
			
		||||
            callableObj(*args, **kwargs)
 | 
			
		||||
@@ -20,11 +20,11 @@
 | 
			
		||||
 | 
			
		||||
import datetime
 | 
			
		||||
import decimal
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
from stacktach import datetime_to_decimal
 | 
			
		||||
from tests.unit import StacktachBaseTestCase
 | 
			
		||||
 | 
			
		||||
class DatetimeToDecimalTestCase(unittest.TestCase):
 | 
			
		||||
class DatetimeToDecimalTestCase(StacktachBaseTestCase):
 | 
			
		||||
 | 
			
		||||
    def test_datetime_to_decimal(self):
 | 
			
		||||
        expected_decimal = decimal.Decimal('1356093296.123')
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,6 @@
 | 
			
		||||
 | 
			
		||||
import datetime
 | 
			
		||||
import json
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
from django.db.models import FieldDoesNotExist
 | 
			
		||||
from django.db import transaction
 | 
			
		||||
@@ -29,13 +28,14 @@ import mox
 | 
			
		||||
from stacktach import dbapi
 | 
			
		||||
from stacktach import models
 | 
			
		||||
from stacktach import utils as stacktach_utils
 | 
			
		||||
from tests.unit import StacktachBaseTestCase
 | 
			
		||||
import utils
 | 
			
		||||
from utils import INSTANCE_ID_1
 | 
			
		||||
from utils import MESSAGE_ID_1
 | 
			
		||||
from utils import MESSAGE_ID_2
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class DBAPITestCase(unittest.TestCase):
 | 
			
		||||
class DBAPITestCase(StacktachBaseTestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.mox = mox.Mox()
 | 
			
		||||
        dne_exception = models.InstanceExists.DoesNotExist
 | 
			
		||||
 
 | 
			
		||||
@@ -18,12 +18,11 @@
 | 
			
		||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 | 
			
		||||
# IN THE SOFTWARE.
 | 
			
		||||
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
from stacktach import image_type
 | 
			
		||||
from tests.unit import StacktachBaseTestCase
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ImageTypeTestCase(unittest.TestCase):
 | 
			
		||||
class ImageTypeTestCase(StacktachBaseTestCase):
 | 
			
		||||
 | 
			
		||||
    # Abstractions
 | 
			
		||||
    def _test_get_numeric_code(self, image, os_type, os_distro, expected,
 | 
			
		||||
 
 | 
			
		||||
@@ -18,11 +18,11 @@
 | 
			
		||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 | 
			
		||||
# IN THE SOFTWARE.
 | 
			
		||||
 | 
			
		||||
import unittest
 | 
			
		||||
from stacktach.models import RawData, GlanceRawData, GenericRawData
 | 
			
		||||
from tests.unit import StacktachBaseTestCase
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ModelsTestCase(unittest.TestCase):
 | 
			
		||||
class ModelsTestCase(StacktachBaseTestCase):
 | 
			
		||||
    def test_get_name_for_rawdata(self):
 | 
			
		||||
        self.assertEquals(RawData.get_name(), 'RawData')
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -18,8 +18,6 @@
 | 
			
		||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 | 
			
		||||
# IN THE SOFTWARE.
 | 
			
		||||
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
import mox
 | 
			
		||||
 | 
			
		||||
from stacktach import notification
 | 
			
		||||
@@ -29,6 +27,7 @@ from stacktach.notification import Notification
 | 
			
		||||
from stacktach.notification import NovaNotification
 | 
			
		||||
from stacktach.notification import GlanceNotification
 | 
			
		||||
from stacktach import db
 | 
			
		||||
from tests.unit import StacktachBaseTestCase
 | 
			
		||||
from tests.unit.utils import REQUEST_ID_1
 | 
			
		||||
from tests.unit.utils import DECIMAL_DUMMY_TIME
 | 
			
		||||
from tests.unit.utils import DUMMY_TIME
 | 
			
		||||
@@ -38,7 +37,7 @@ from tests.unit.utils import INSTANCE_ID_1
 | 
			
		||||
from tests.unit.utils import MESSAGE_ID_1
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class NovaNotificationTestCase(unittest.TestCase):
 | 
			
		||||
class NovaNotificationTestCase(StacktachBaseTestCase):
 | 
			
		||||
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.mox = mox.Mox()
 | 
			
		||||
@@ -150,7 +149,7 @@ class NovaNotificationTestCase(unittest.TestCase):
 | 
			
		||||
        self.mox.VerifyAll()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class GlanceNotificationTestCase(unittest.TestCase):
 | 
			
		||||
class GlanceNotificationTestCase(StacktachBaseTestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.mox = mox.Mox()
 | 
			
		||||
 | 
			
		||||
@@ -423,7 +422,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
 | 
			
		||||
        self.mox.VerifyAll()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class NotificationTestCase(unittest.TestCase):
 | 
			
		||||
class NotificationTestCase(StacktachBaseTestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.mox = mox.Mox()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,6 @@
 | 
			
		||||
# IN THE SOFTWARE.
 | 
			
		||||
 | 
			
		||||
import datetime
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
import mox
 | 
			
		||||
import requests
 | 
			
		||||
@@ -30,6 +29,7 @@ from stacktach import utils as stackutils
 | 
			
		||||
from stacktach.reconciler import exceptions
 | 
			
		||||
from stacktach.reconciler import nova
 | 
			
		||||
from stacktach.reconciler import utils as rec_utils
 | 
			
		||||
from tests.unit import StacktachBaseTestCase
 | 
			
		||||
from tests.unit import utils
 | 
			
		||||
from tests.unit.utils import INSTANCE_ID_1
 | 
			
		||||
from tests.unit.utils import TENANT_ID_1
 | 
			
		||||
@@ -45,7 +45,7 @@ DEFAULT_OS_VERSION = "1.1"
 | 
			
		||||
DEFAULT_RAX_OPTIONS = "rax_ops"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ReconcilerTestCase(unittest.TestCase):
 | 
			
		||||
class ReconcilerTestCase(StacktachBaseTestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.mox = mox.Mox()
 | 
			
		||||
        self.client = self.mox.CreateMockAnything()
 | 
			
		||||
@@ -415,7 +415,7 @@ json_bridge_config = {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class NovaJSONBridgeClientTestCase(unittest.TestCase):
 | 
			
		||||
class NovaJSONBridgeClientTestCase(StacktachBaseTestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.mox = mox.Mox()
 | 
			
		||||
        self.client = nova.JSONBridgeClient(json_bridge_config)
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,6 @@
 | 
			
		||||
 | 
			
		||||
import datetime
 | 
			
		||||
import json
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
import mox
 | 
			
		||||
 | 
			
		||||
@@ -40,9 +39,10 @@ from utils import IMAGE_UUID_1
 | 
			
		||||
from stacktach import stacklog
 | 
			
		||||
from stacktach import notification
 | 
			
		||||
from stacktach import views
 | 
			
		||||
from tests.unit import StacktachBaseTestCase
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class StacktachRawParsingTestCase(unittest.TestCase):
 | 
			
		||||
class StacktachRawParsingTestCase(StacktachBaseTestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.mox = mox.Mox()
 | 
			
		||||
        views.STACKDB = self.mox.CreateMockAnything()
 | 
			
		||||
@@ -101,7 +101,7 @@ class StacktachRawParsingTestCase(unittest.TestCase):
 | 
			
		||||
        self.mox.VerifyAll()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class StacktachLifecycleTestCase(unittest.TestCase):
 | 
			
		||||
class StacktachLifecycleTestCase(StacktachBaseTestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.mox = mox.Mox()
 | 
			
		||||
        views.STACKDB = self.mox.CreateMockAnything()
 | 
			
		||||
@@ -287,7 +287,7 @@ class StacktachLifecycleTestCase(unittest.TestCase):
 | 
			
		||||
        self.mox.VerifyAll()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class StacktachUsageParsingTestCase(unittest.TestCase):
 | 
			
		||||
class StacktachUsageParsingTestCase(StacktachBaseTestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.mox = mox.Mox()
 | 
			
		||||
        views.STACKDB = self.mox.CreateMockAnything()
 | 
			
		||||
@@ -830,7 +830,7 @@ class StacktachUsageParsingTestCase(unittest.TestCase):
 | 
			
		||||
        self.mox.VerifyAll()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class StacktachImageUsageParsingTestCase(unittest.TestCase):
 | 
			
		||||
class StacktachImageUsageParsingTestCase(StacktachBaseTestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.mox = mox.Mox()
 | 
			
		||||
        views.STACKDB = self.mox.CreateMockAnything()
 | 
			
		||||
 
 | 
			
		||||
@@ -18,17 +18,15 @@
 | 
			
		||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 | 
			
		||||
# IN THE SOFTWARE.
 | 
			
		||||
 | 
			
		||||
import datetime
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
import mox
 | 
			
		||||
 | 
			
		||||
from stacktach import db
 | 
			
		||||
from stacktach import stacklog
 | 
			
		||||
from stacktach import models
 | 
			
		||||
from tests.unit import StacktachBaseTestCase
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class StacktachDBTestCase(unittest.TestCase):
 | 
			
		||||
class StacktachDBTestCase(StacktachBaseTestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.mox = mox.Mox()
 | 
			
		||||
        self.log = self.mox.CreateMockAnything()
 | 
			
		||||
 
 | 
			
		||||
@@ -18,17 +18,16 @@
 | 
			
		||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 | 
			
		||||
# IN THE SOFTWARE.
 | 
			
		||||
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
import mox
 | 
			
		||||
 | 
			
		||||
from stacktach import utils as stacktach_utils
 | 
			
		||||
from utils import INSTANCE_ID_1
 | 
			
		||||
from utils import MESSAGE_ID_1
 | 
			
		||||
from utils import REQUEST_ID_1
 | 
			
		||||
from tests.unit import StacktachBaseTestCase
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class StacktachUtilsTestCase(unittest.TestCase):
 | 
			
		||||
class StacktachUtilsTestCase(StacktachBaseTestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.mox = mox.Mox()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,6 @@
 | 
			
		||||
import datetime
 | 
			
		||||
import decimal
 | 
			
		||||
import json
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
import mox
 | 
			
		||||
 | 
			
		||||
@@ -33,8 +32,10 @@ from utils import INSTANCE_ID_1
 | 
			
		||||
from utils import INSTANCE_ID_2
 | 
			
		||||
from utils import REQUEST_ID_1
 | 
			
		||||
 | 
			
		||||
from tests.unit import StacktachBaseTestCase
 | 
			
		||||
 | 
			
		||||
class StackyServerTestCase(unittest.TestCase):
 | 
			
		||||
 | 
			
		||||
class StackyServerTestCase(StacktachBaseTestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.mox = mox.Mox()
 | 
			
		||||
        self.mox.StubOutWithMock(models, 'RawData', use_mock_anything=True)
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,6 @@ import datetime
 | 
			
		||||
import decimal
 | 
			
		||||
import json
 | 
			
		||||
import time
 | 
			
		||||
import unittest
 | 
			
		||||
import uuid
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -51,9 +50,10 @@ from verifier import AmbiguousResults
 | 
			
		||||
from verifier import FieldMismatch
 | 
			
		||||
from verifier import NotFound
 | 
			
		||||
from verifier import VerificationException
 | 
			
		||||
from tests.unit import StacktachBaseTestCase
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class VerifierTestCase(unittest.TestCase):
 | 
			
		||||
class VerifierTestCase(StacktachBaseTestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.mox = mox.Mox()
 | 
			
		||||
        self.mox.StubOutWithMock(models, 'RawData', use_mock_anything=True)
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,6 @@
 | 
			
		||||
# IN THE SOFTWARE.
 | 
			
		||||
 | 
			
		||||
import json
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
import kombu
 | 
			
		||||
import mox
 | 
			
		||||
@@ -27,9 +26,10 @@ import mox
 | 
			
		||||
from stacktach import db
 | 
			
		||||
from stacktach import views
 | 
			
		||||
import worker.worker as worker
 | 
			
		||||
from tests.unit import StacktachBaseTestCase
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ConsumerTestCase(unittest.TestCase):
 | 
			
		||||
class ConsumerTestCase(StacktachBaseTestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        self.mox = mox.Mox()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user