-
Notifications
You must be signed in to change notification settings - Fork 3
/
tests.py
57 lines (41 loc) · 1.76 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
56
57
"""
Tests for the sprockets.clients.memcached package
"""
import mock
import os
try:
import unittest2 as unittest
except ImportError:
import unittest
from sprockets.clients import memcached
class TestGetServers(unittest.TestCase):
def tearDown(self):
for key in ['MEMCACHED_SERVERS', 'TEST1_MEMCACHED_SERVERS']:
if key in os.environ:
del os.environ[key]
def test_get_servers_for_prefixed_key(self):
os.environ['TEST1_MEMCACHED_SERVERS'] = '1.1.1.1:11211,1.1.1.2:11211'
self.assertListEqual(memcached._get_servers('TEST1'),
['1.1.1.1:11211', '1.1.1.2:11211'])
def test_get_servers_for_non_prefixed_key(self):
os.environ['MEMCACHED_SERVERS'] = '2.1.1.1:11211'
self.assertListEqual(memcached._get_servers(None), ['2.1.1.1:11211'])
def test_get_servers_returns_default_value(self):
self.assertListEqual(memcached._get_servers(None), ['127.0.0.1:11211'])
class TestClientWrapsMemcacheClient(unittest.TestCase):
@mock.patch('memcache.Client.__init__')
def test_client_super_init(self, mock_init):
memcached.Client()
mock_init.assert_called_once_with(['127.0.0.1:11211'])
class ClientIntegrationTests(unittest.TestCase):
def setUp(self):
self.client = memcached.Client()
self.client.incr('test')
if any([s.deaduntil for s in self.client.servers]):
raise unittest.SkipTest('No memcached daemon present')
def test_that_incr_returns_a_value_for_a_set_key(self):
self.client.set('test-incr', 2)
self.assertEqual(self.client.incr('test-incr'), 3)
def test_that_set_key_is_gettable(self):
self.client.set('foo', 'bar', 60)
self.assertEqual(self.client.get('foo'), 'bar')