-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
91 lines (70 loc) · 2.21 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# -*- coding: utf-8 -*-
import os
import unittest
from unqlite import UnQLite
import tempfile
import bottle
from bottle.ext import unqlite
''' python3 moves unicode to str '''
try:
unicode
except NameError:
unicode = str
class UnQLiteTest(unittest.TestCase):
def setUp(self):
self.app = bottle.Bottle(catchall=False)
_, filename = tempfile.mkstemp(suffix='.unqlite')
self.plugin = self.app.install(unqlite.Plugin(filename=filename))
self.conn = UnQLite(filename)
self.conn.collection('todo').create()
self.conn.close()
def tearDown(self):
pass
# os.unlink(self.plugin.filename)
def test_with_keyword(self):
@self.app.get('/')
def test(db):
self.assertEqual(type(db), type(UnQLite(':mem:')))
self._request('/')
def test_without_keyword(self):
@self.app.get('/')
def test_1():
pass
self._request('/')
@self.app.get('/2')
def test_2(**kw):
self.assertFalse('db' in kw)
self._request('/2')
def test_install_conflicts(self):
self.app.install(unqlite.Plugin(keyword='db2'))
@self.app.get('/')
def test(db, db2):
pass
# I have two plugins working with different names
self._request('/')
def test_commit_on_redirect(self):
@self.app.get('/')
def test(db):
self._insert_into(db)
bottle.redirect('/')
self._request('/')
self.assert_records(1)
def test_commit_on_abort(self):
@self.app.get('/')
def test(db):
self._insert_into(db)
bottle.abort()
self._request('/')
self.assert_records(0)
def _request(self, path, method='GET'):
return self.app({'PATH_INFO': path, 'REQUEST_METHOD': method},
lambda x, y: None)
def _insert_into(self, db):
db.collection('todo').store({ 'task': 'PASS' })
def assert_records(self, count):
self.conn.open()
actual_count = len(self.conn.collection('todo').all())
self.conn.close()
self.assertEqual(count, actual_count)
if __name__ == '__main__':
unittest.main()