-
Notifications
You must be signed in to change notification settings - Fork 0
/
clients_test.py
72 lines (60 loc) · 2.49 KB
/
clients_test.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import unittest
import mox
import clients
import client_model
from datetime import datetime
from google.appengine.ext import db
from google.appengine.api import channel
# Import the 'testbed' module.
from google.appengine.ext import testbed
class ClientsUnitTest(unittest.TestCase):
def setUp(self):
self.mox = mox.Mox()
# At first, create an instance of the Testbed class.
self.testbed = testbed.Testbed()
# Then activate the testbed which will prepare the usage of service stubs.
self.testbed.activate()
# Next, declare which service stubs you want to use.
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
def test_add_client(self):
self.mox.StubOutWithMock(clients, 'channel')
clients.channel.create_channel(mox.IsA(str))
self.mox.ReplayAll()
(id, token) = clients.add_client('http://example.com/feed')
self.mox.UnsetStubs()
self.mox.VerifyAll()
self.assertEqual(1, len(client_model.Client.all().fetch(2)))
def test_add_client_no_feed(self):
try:
clients.add_client()
self.fail('add_client with no feed should fail.')
except:
"""Expected behavior."""
def test_send_filtered_messages(self):
self.mox.StubOutWithMock(clients, 'channel')
self.mox.StubOutWithMock(clients, 'datetime')
clients.channel.create_channel(mox.IsA(str))
clients.channel.send_message(mox.IsA(str), '[{"id": "foo"}, {"id": "bar"}]')
self.mox.ReplayAll()
(id, token) = clients.add_client('http://example.com/feed')
clients.send_filtered_messages(id, 'http://example.com/feed',
[{'id': 'foo'}, {'id': 'bar'}])
self.mox.UnsetStubs()
self.mox.VerifyAll()
def test_send_filtered_messages_with_dup(self):
self.mox.StubOutWithMock(clients, 'channel')
self.mox.StubOutWithMock(clients, 'datetime')
clients.channel.create_channel(mox.IsA(str))
clients.channel.send_message(mox.IsA(str), '[{"id": "foo"}, {"id": "bar"}]')
clients.channel.send_message(mox.IsA(str), '[{"id": "baz"}]')
self.mox.ReplayAll()
(id, token) = clients.add_client('http://example.com/feed')
clients.send_filtered_messages(id, 'http://example.com/feed',
[{'id': 'foo'}, {'id': 'bar'}])
clients.send_filtered_messages(id, 'http://example.com/feed',
[{'id': 'foo'}, {'id': 'baz'}])
self.mox.UnsetStubs()
self.mox.VerifyAll()
if __name__ == '__main__':
unittest.main()