Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed tests, moved Transport Provider tests into their own TestCase

  • Loading branch information...
commit 42fb4153961e553b8e50c4d055848e6d9d0ef413 1 parent 6e2c099
@davbo davbo authored
Showing with 56 additions and 44 deletions.
  1. +1 −44 moxie/tests/test_services.py
  2. +55 −0 moxie/tests/test_transport_service.py
View
45 moxie/tests/test_services.py
@@ -1,32 +1,11 @@
import unittest
from moxie import create_app
-from moxie.core.provider import Provider
from moxie.core.service import Service, NoConfiguredService
-class ProvidesAll(Provider):
- def handles(self, doc):
- return True
-
- def invoke(self, doc):
- return doc
-
-
-class ProvidesNone(Provider):
- def handles(self, doc):
- return False
-
- def invoke(self, doc):
- return doc
-
-
class TestProvider(Service):
- def annotate_provider(self, doc):
- if self.get_provider(doc):
- doc['provider_exists'] = True
- return doc
- return doc
+ pass
class ArgService(Service):
@@ -38,9 +17,6 @@ def __init__(self, *args, **kwargs):
class ServiceTest(unittest.TestCase):
def setUp(self):
- self.any_service = TestProvider(providers=[ProvidesAll()])
- self.no_service = TestProvider(providers=[ProvidesNone()])
- self.doc = {'foo': 'bar'}
self.app = create_app()
services = {'foobar': {'TestProvider': ([], {})},
'barfoo': {'TestProvider': ([], {})},
@@ -48,25 +24,6 @@ def setUp(self):
}
self.app.config['SERVICES'] = services
- def test_get_provider(self):
- self.assertTrue(self.any_service.get_provider(self.doc))
-
- def test_none_get_provider(self):
- self.assertEqual(None, self.no_service.get_provider(self.doc))
-
- def test_annotated_doc(self):
- doc = self.any_service.annotate_provider(self.doc)
- self.assertTrue(doc['provider_exists'])
-
- def test_unannotated_doc(self):
- doc = self.no_service.annotate_provider(self.doc)
- with self.assertRaises(KeyError):
- doc['provider_exists']
-
- def test_invoked_provider_success(self):
- provider = self.any_service.get_provider(self.doc)
- self.assertEqual(provider(self.doc), self.doc)
-
def test_service_config_missing(self):
with self.app.app_context():
with self.assertRaises(NoConfiguredService):
View
55 moxie/tests/test_transport_service.py
@@ -0,0 +1,55 @@
+import unittest
+
+from moxie.transport.providers import TransportRTIProvider
+from moxie.transport.services import TransportService
+
+
+class ProvidesAll(TransportRTIProvider):
+ def handles(self, doc):
+ return True
+
+ def invoke(self, doc):
+ return doc
+
+
+class ProvidesNone(TransportRTIProvider):
+ def handles(self, doc):
+ return False
+
+ def invoke(self, doc):
+ return doc
+
+
+class TestProvider(TransportService):
+ def annotate_provider(self, doc):
+ if self.get_provider(doc):
+ doc['provider_exists'] = True
+ return doc
+ return doc
+
+
+class TransportServiceTest(unittest.TestCase):
+
+ def setUp(self):
+ self.any_service = TestProvider(providers=[ProvidesAll()])
+ self.no_service = TestProvider(providers=[ProvidesNone()])
+ self.doc = {'foo': 'bar'}
+
+ def test_get_provider(self):
+ self.assertTrue(self.any_service.get_provider(self.doc))
+
+ def test_none_get_provider(self):
+ self.assertEqual(None, self.no_service.get_provider(self.doc))
+
+ def test_annotated_doc(self):
+ doc = self.any_service.annotate_provider(self.doc)
+ self.assertTrue(doc['provider_exists'])
+
+ def test_unannotated_doc(self):
+ doc = self.no_service.annotate_provider(self.doc)
+ with self.assertRaises(KeyError):
+ doc['provider_exists']
+
+ def test_invoked_provider_success(self):
+ provider = self.any_service.get_provider(self.doc)
+ self.assertEqual(provider(self.doc), self.doc)
Please sign in to comment.
Something went wrong with that request. Please try again.