-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
159 lines (128 loc) · 5.26 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
"""
fleetdb.py - Python interface to FleetDB (http://fleetdb.org/)
Library Maintainer:
Matt Culbreth
http://github.com/mattc58/fleetdb-python
#####################################################################
This work is distributed under an MIT License:
http://www.opensource.org/licenses/mit-license.php
The MIT License
Copyright (c) 2010 Matt Culbreth (http://mattculbreth.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
#####################################################################
Unit tests for fleetdb-python
"""
import unittest
import uuid
import fleetdb
class TestClient(unittest.TestCase):
'''
Unit tests for the python-fleetdb library
'''
def setUp(self):
'''
set up the client
'''
self.client = fleetdb.FleetDBClient("localhost", 3400)
def test_ping(self):
'''
test the ping method
'''
response = self.client.ping()
self.assert_(response)
def test_single_insert(self):
'''
test a single record insert
'''
response = self.client.insert("test", {'id' : uuid.uuid4().hex})
self.assert_(response, 1)
def test_multi_insert(self):
'''
test a multiple record insert
'''
response = self.client.insert("test", [{'id' : uuid.uuid4().hex}, {'id' : uuid.uuid4().hex}, {'id' : uuid.uuid4().hex}])
self.assert_(response, 3)
def test_insert_duplicate(self):
'''
test that an insert of a duplicate key throws an exception
'''
def test_insert_duplicates_inner():
# first insert something
id1 = uuid.uuid4().hex
self.client.insert("test", {'id' : id1, 'name' : 'name1'})
# now try the same key
self.client.insert("test", {'id' : id1, 'name' : 'name2'})
self.assertRaises(AssertionError, test_insert_duplicates_inner)
def test_select(self):
'''
test a normal select
'''
# first insert something
test_collection = uuid.uuid4().hex
id1 = uuid.uuid4().hex
self.client.insert(test_collection, {'id' : id1, 'name' : 'name1'})
# now get it
response = self.client.select(test_collection)
self.assert_(response)
self.assertEqual(1, len(response))
def test_select_where(self):
'''
test a select with a where clause
'''
# first insert something
test_collection = uuid.uuid4().hex
id2 = uuid.uuid4().hex
response = self.client.insert(test_collection, [{'id' : uuid.uuid4().hex}, {'id' : id2}, {'id' : uuid.uuid4().hex}])
# get all 3
response = self.client.select(test_collection)
self.assert_(response)
self.assertEqual(3, len(response))
# now get 1
response = self.client.select(test_collection, {'where' : ['=', 'id', id2]})
self.assert_(response)
self.assertEqual(1, len(response))
def test_count(self):
'''
test a count
'''
# first insert something
test_collection = uuid.uuid4().hex
response = self.client.insert(test_collection, [{'id' : uuid.uuid4().hex}, {'id' : uuid.uuid4().hex}, {'id' : uuid.uuid4().hex}])
# get all 3
response = self.client.count(test_collection)
self.assert_(response)
self.assertEqual(3, response)
def test_count_where(self):
'''
test a count with a where clause
'''
# first insert something
test_collection = uuid.uuid4().hex
id2 = uuid.uuid4().hex
response = self.client.insert(test_collection, [{'id' : uuid.uuid4().hex}, {'id' : id2}, {'id' : uuid.uuid4().hex}])
# get all 3
response = self.client.count(test_collection)
self.assert_(response)
self.assertEqual(3, response)
# now get 1
response = self.client.count(test_collection, {'where' : ['=', 'id', id2]})
self.assert_(response)
self.assertEqual(1, response)
# now try to get 0
response = self.client.count(test_collection, {'where' : ['=', 'id', 'should not exist']})
self.assertEqual(0, response)