-
Notifications
You must be signed in to change notification settings - Fork 5
/
tests.py
55 lines (42 loc) · 1.49 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from contextlib import contextmanager
from StringIO import StringIO
import sys
from lymph.testing import (LymphServiceTestCase, EventMockTestCase,
WebServiceTestCase, RpcMockTestCase)
from mock import call
from greeting import Greeting
from web import Web
from listen import Listen
@contextmanager
def capture_stdout():
real_stdout = sys.stdout
sys.stdout = StringIO()
try:
yield sys.stdout
finally:
sys.stdout = real_stdout
class GreetingTest(LymphServiceTestCase, EventMockTestCase):
service_class = Greeting
service_name = u'Greeting'
def test_says_hi(self):
self.assertEqual(
self.client.proxy(u'Greeting').greet(name=u'John'),
u'Hi, John!'
)
self.assert_events_emitted(call(u'greeted', {u'name': u'John'}))
class ListenServiceTest(LymphServiceTestCase):
service_class = Listen
service_name = u'Listen'
def test_prints(self):
with capture_stdout() as stdout:
self.client.emit(u'greeted', {u'name': u'John'})
output = stdout.getvalue().strip()
self.assertEqual(output, u'Somebody greeted John')
class WebTest(WebServiceTestCase, RpcMockTestCase):
service_class = Web
service_name = 'Web'
def test_greets(self):
self.update_rpc_mock('Greeting.greet', 'Hi, John!')
response = self.client.post('/greet?name=John')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, 'Hi, John!')