-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
60 lines (46 loc) · 1.79 KB
/
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
#!/usr/bin/env python
#
# -*- mode: python; sh-basic-offset: 4; indent-tabs-mode: nil; coding: utf-8 -*-
# vim:set tabstop=4 softtabstop=4 expandtab shiftwidth=4 fileencoding=utf-8:
#
import unittest
import os
import bottle
from bottle.ext import memcache as mc_plugin
import memcache
from datetime import datetime
class MemcacheTest(unittest.TestCase):
test_key = 'bottle_memcache_test_value'
def setUp(self):
self.app = bottle.Bottle(catchall=False)
def test_with_keyword(self):
self.plugin = self.app.install(mc_plugin.Plugin())
@self.app.get('/')
def test(mc):
self.assertEqual(type(mc), type(memcache.Client(servers=['localhost:11211'])))
self.app({'PATH_INFO':'/', 'REQUEST_METHOD':'GET'}, lambda x, y: None)
def test_without_keyword(self):
self.plugin = self.app.install(mc_plugin.Plugin())
@self.app.get('/')
def test():
pass
self.app({'PATH_INFO':'/', 'REQUEST_METHOD':'GET'}, lambda x, y: None)
@self.app.get('/2')
def test(**kw):
self.assertFalse('mc' in kw)
self.app({'PATH_INFO':'/2', 'REQUEST_METHOD':'GET'}, lambda x, y: None)
def test_set_and_retrieve(self):
self.plugin = self.app.install(mc_plugin.Plugin())
@self.app.get('/3')
def test(mc):
in_val = str(datetime.now())
mc.set(self.test_key, in_val)
mc2 = memcache.Client(servers=['localhost:11211'])
out_val = mc2.get(self.test_key)
self.assertEqual(in_val, out_val)
self.app({'PATH_INFO':'/3', 'REQUEST_METHOD':'GET'}, lambda x, y: None)
def tearDown(self):
mc2 = memcache.Client(servers=['localhost:11211'])
mc2.delete(self.test_key)
if __name__ == '__main__':
unittest.main()