Skip to content

Commit

Permalink
Merge branch 'feature/adhoc-new-test-base' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jerith committed Nov 4, 2013
2 parents baad6f4 + da24500 commit 4e32c27
Show file tree
Hide file tree
Showing 75 changed files with 315 additions and 449 deletions.
2 changes: 1 addition & 1 deletion vumi/application/tests/test_http_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
@inlineCallbacks
def setup_resource_with_callback(self, callback):
self.mock_server = MockHttpServer(callback)
self.addCleanup(self.mock_server.stop)
self.add_cleanup(self.mock_server.stop)
yield self.mock_server.start()
self.app = yield self.get_application({
'url': '%s%s' % (self.mock_server.url, self.path),
Expand Down
2 changes: 1 addition & 1 deletion vumi/application/tests/test_rapidsms_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setup_resource(self, callback=None, auth=None):
if callback is None:
callback = lambda r: self.fail("No RapidSMS requests expected.")
self.mock_server = MockHttpServer(callback)
self.addCleanup(self.mock_server.stop)
self.add_cleanup(self.mock_server.stop)
yield self.mock_server.start()
url = '%s%s' % (self.mock_server.url, self.path)
self.app = yield self.setup_app(url, auth=auth)
Expand Down
13 changes: 5 additions & 8 deletions vumi/application/tests/test_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from twisted.internet.defer import (
inlineCallbacks, fail, succeed, DeferredQueue)
from twisted.internet.error import ProcessTerminated
from twisted.trial.unittest import TestCase, SkipTest
from twisted.trial.unittest import SkipTest

from vumi.message import TransportUserMessage, TransportEvent
from vumi.application.tests.utils import ApplicationTestCase
Expand All @@ -21,6 +21,7 @@
LoggingResource, HttpClientResource, JsSandbox, JsFileSandbox,
HttpClientContextFactory)
from vumi.tests.utils import LogCatcher, PersistenceMixin
from vumi.tests.helpers import VumiTestCase

from OpenSSL.SSL import (
VERIFY_PEER, VERIFY_FAIL_IF_NO_PEER_CERT, VERIFY_NONE)
Expand Down Expand Up @@ -516,7 +517,7 @@ def mock_method(*args, **kw):
return mock_method


class SandboxApiTestCase(TestCase):
class SandboxApiTestCase(VumiTestCase):
def setUp(self):
self.sent_messages = DeferredQueue()
self.patch(SandboxApi, 'sandbox_send',
Expand Down Expand Up @@ -548,7 +549,7 @@ def handle_use(api, command):
self.assertEqual(logged_error.type, Exception)


class ResourceTestCaseBase(TestCase):
class ResourceTestCaseBase(VumiTestCase):

app_worker_cls = DummyAppWorker
resource_cls = None
Expand All @@ -562,11 +563,6 @@ def setUp(self):
self.sandbox = self.app_worker.create_sandbox_protocol(self.sandbox_id,
self.api)

@inlineCallbacks
def tearDown(self):
if self.resource is not None:
yield self.resource.teardown()

@inlineCallbacks
def create_resource(self, config):
if self.resource is not None:
Expand All @@ -576,6 +572,7 @@ def create_resource(self, config):
resource = self.resource_cls(self.resource_name,
self.app_worker,
config)
self.add_cleanup(resource.teardown)
yield resource.setup()
self.resource = resource

Expand Down
5 changes: 2 additions & 3 deletions vumi/application/tests/test_sandbox_rlimiter.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Tests for vumi.application.sandbox_rlimiter."""

from twisted.trial.unittest import TestCase

from vumi.application import sandbox_rlimiter
from vumi.application.sandbox_rlimiter import SandboxRlimiter
from vumi.tests.helpers import VumiTestCase


class SandboxRlimiterTestCase(TestCase):
class SandboxRlimiterTestCase(VumiTestCase):
def test_script_name_dot_py(self):
self.patch(sandbox_rlimiter, '__file__', 'foo.py')
self.assertEqual(SandboxRlimiter.script_name(), 'foo.py')
Expand Down
10 changes: 4 additions & 6 deletions vumi/application/tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

import time

from twisted.trial.unittest import TestCase
from vumi.persist.fake_redis import FakeRedis
from vumi.application import SessionManager
from vumi.tests.helpers import VumiTestCase


class SessionManagerTestCase(TestCase):
class SessionManagerTestCase(VumiTestCase):
def setUp(self):
self.fake_redis = FakeRedis()
self.add_cleanup(self.fake_redis.teardown)
self.sm = SessionManager(self.fake_redis, prefix="test")

def tearDown(self):
self.sm.stop()
self.fake_redis.teardown()
self.add_cleanup(self.sm.stop)

def test_active_sessions(self):
def get_sessions():
Expand Down
13 changes: 7 additions & 6 deletions vumi/blinkenlights/heartbeat/tests/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import time
import json

from twisted.trial.unittest import TestCase
from twisted.internet.defer import inlineCallbacks

from vumi.tests.utils import get_stubbed_worker
from vumi.blinkenlights.heartbeat import publisher
from vumi.blinkenlights.heartbeat import monitor
from vumi.blinkenlights.heartbeat.storage import issue_key
from vumi.utils import generate_worker_id
from vumi.tests.helpers import VumiTestCase


def expected_wkr_dict():
Expand All @@ -36,7 +36,7 @@ def expected_sys_dict():
return sys


class TestWorkerInstance(TestCase):
class TestWorkerInstance(VumiTestCase):

def test_create(self):
worker = monitor.WorkerInstance('foo', 34)
Expand All @@ -61,7 +61,7 @@ def test_hash(self):
self.assertNotEqual(hash(worker1), hash(worker4))


class TestWorker(TestCase):
class TestWorker(VumiTestCase):

def test_to_dict(self):
wkr = monitor.Worker('system-1', 'foo', 1)
Expand Down Expand Up @@ -97,7 +97,7 @@ def test_snapshot(self):
self.assertEqual(len(wkr._instances), 2)


class TestSystem(TestCase):
class TestSystem(VumiTestCase):

def test_to_dict(self):
wkr = monitor.Worker('system-1', 'foo', 1)
Expand All @@ -119,7 +119,7 @@ def test_dumps(self):
self.assertEqual(obj, expected_sys_dict())


class TestHeartBeatMonitor(TestCase):
class TestHeartBeatMonitor(VumiTestCase):

def setUp(self):
config = {
Expand All @@ -143,9 +143,10 @@ def setUp(self):
}
}
self.worker = get_stubbed_worker(monitor.HeartBeatMonitor, config)
self.add_cleanup(self.cleanup_worker)

@inlineCallbacks
def tearDown(self):
def cleanup_worker(self):
redis = self.worker._redis
yield redis._purge_all()
yield redis.close_manager()
Expand Down
10 changes: 2 additions & 8 deletions vumi/blinkenlights/heartbeat/tests/test_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

import json

from twisted.trial.unittest import TestCase
from twisted.internet.defer import inlineCallbacks

from vumi.tests.utils import get_stubbed_channel
from vumi.tests.fake_amqp import FakeAMQPBroker
from vumi.blinkenlights.heartbeat import publisher
from vumi.errors import MissingMessageField
from vumi.tests.helpers import VumiTestCase


class MockHeartBeatPublisher(publisher.HeartBeatPublisher):
Expand All @@ -20,13 +20,7 @@ def _start_looping_task(self):
self._task = None


class TestHeartBeatPublisher(TestCase):

def setUp(self):
pass

def tearDown(self):
pass
class TestHeartBeatPublisher(VumiTestCase):

def gen_fake_attrs(self):
attrs = {
Expand Down
7 changes: 4 additions & 3 deletions vumi/blinkenlights/heartbeat/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import json

from twisted.trial.unittest import TestCase
from twisted.internet.defer import inlineCallbacks

from vumi.persist.txredis_manager import TxRedisManager
from vumi.blinkenlights.heartbeat import storage
from vumi.blinkenlights.heartbeat import monitor
from vumi.tests.helpers import VumiTestCase


class DummySystem:
Expand All @@ -20,7 +20,7 @@ def dumps(self):
return "Ha!"


class TestStorage(TestCase):
class TestStorage(VumiTestCase):

@inlineCallbacks
def setUp(self):
Expand All @@ -30,10 +30,11 @@ def setUp(self):
'FAKE_REDIS': True,
}
self.redis = yield TxRedisManager.from_config(config)
self.add_cleanup(self.cleanup_redis)
self.stg = storage.Storage(self.redis)

@inlineCallbacks
def tearDown(self):
def cleanup_redis(self):
yield self.redis._purge_all()
yield self.redis.close_manager()

Expand Down
12 changes: 3 additions & 9 deletions vumi/blinkenlights/tests/test_message20110707.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime

from twisted.trial.unittest import TestCase
from vumi.blinkenlights import message20110707 as message
from vumi.tests.helpers import VumiTestCase


TIMEOBJ = datetime(2011, 07, 07, 12, 00, 00)
Expand All @@ -25,13 +25,7 @@ def mkmsgobj(message_type, source_name, source_id, payload, timestamp):
timestamp)


class MessageTestCase(TestCase):

def setUp(self):
pass

def tearDown(self):
pass
class MessageTestCase(VumiTestCase):

def test_decode_valid_message(self):
"""A valid message dict should decode into an appropriate Message
Expand Down Expand Up @@ -115,7 +109,7 @@ def mkmetricsmsg(metrics):
TIMELIST)


class MetricsMessageTestCase(TestCase):
class MetricsMessageTestCase(VumiTestCase):
def test_parse_empty_metrics(self):
msg_data = mkmetricsmsg([])
msg = message.MetricsMessage.from_dict(msg_data)
Expand Down
7 changes: 4 additions & 3 deletions vumi/blinkenlights/tests/test_message20110818.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from twisted.trial.unittest import TestCase
import vumi.blinkenlights.message20110818 as message
import time

import vumi.blinkenlights.message20110818 as message
from vumi.tests.helpers import VumiTestCase


class TestMessage(TestCase):
class TestMessage(VumiTestCase):

def test_to_dict(self):
now = time.time()
Expand Down
29 changes: 14 additions & 15 deletions vumi/blinkenlights/tests/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
from twisted.trial.unittest import TestCase
import time

from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks, returnValue, Deferred

from vumi.blinkenlights import metrics
from vumi.tests.utils import get_stubbed_worker, get_stubbed_channel
from vumi.message import Message
from vumi.service import Worker

import time
from vumi.tests.helpers import VumiTestCase


class TestMetricManager(TestCase):
class TestMetricManager(VumiTestCase):

def setUp(self):
self._next_publish = Deferred()

def tearDown(self):
self._next_publish.callback(None)
self.add_cleanup(lambda: self._next_publish.callback(None))

def on_publish(self, mm):
d, self._next_publish = self._next_publish, Deferred()
Expand All @@ -28,9 +27,9 @@ def wait_publish(self):
def start_manager(self, manager):
channel = yield get_stubbed_channel()
broker = channel.broker
self.addCleanup(broker.wait_delivery)
self.add_cleanup(broker.wait_delivery)
manager.start(channel)
self.addCleanup(manager.stop)
self.add_cleanup(manager.stop)
returnValue(broker)

def _sleep(self, delay):
Expand Down Expand Up @@ -135,7 +134,7 @@ def test_stop_unstarted(self):
def test_in_worker(self):
worker = get_stubbed_worker(Worker)
broker = worker._amqp_client.broker
self.addCleanup(broker.wait_delivery)
self.add_cleanup(broker.wait_delivery)
mm = yield worker.start_publisher(metrics.MetricManager,
"vumi.test.", 0.1, self.on_publish)
acc = mm.register(metrics.Metric("my.acc"))
Expand Down Expand Up @@ -172,7 +171,7 @@ def poll(self):
self.assertTrue(error.type is BadMetricError)


class TestAggregators(TestCase):
class TestAggregators(VumiTestCase):
def test_sum(self):
self.assertEqual(metrics.SUM([]), 0.0)
self.assertEqual(metrics.SUM([1.0, 2.0]), 3.0)
Expand Down Expand Up @@ -239,7 +238,7 @@ def check_poll(self, metric, expected_values):
self.assertEqual(actual_values, expected_values)


class TestMetric(TestCase, CheckValuesMixin):
class TestMetric(VumiTestCase, CheckValuesMixin):
def test_manage(self):
mm = metrics.MetricManager("vumi.test.")
metric = metrics.Metric("foo")
Expand All @@ -264,7 +263,7 @@ def test_poll(self):
self.check_poll(metric, [1.0, 2.0])


class TestCount(TestCase, CheckValuesMixin):
class TestCount(VumiTestCase, CheckValuesMixin):
def test_inc_and_poll(self):
metric = metrics.Count("foo")
self.check_poll(metric, [])
Expand All @@ -276,7 +275,7 @@ def test_inc_and_poll(self):
self.check_poll(metric, [1.0, 1.0])


class TestTimer(TestCase, CheckValuesMixin):
class TestTimer(VumiTestCase, CheckValuesMixin):

def patch_time(self, starting_value):
def fake_time():
Expand Down Expand Up @@ -321,7 +320,7 @@ def test_accumulate_times(self):
self.check_poll(timer, [])


class TestMetricsConsumer(TestCase):
class TestMetricsConsumer(VumiTestCase):
def test_consume_message(self):
expected_datapoints = [
("vumi.test.v1", 1234, 1.0),
Expand Down
Loading

0 comments on commit 4e32c27

Please sign in to comment.