3
3
import sys
4
4
import unittest
5
5
import httmock
6
+ import itertools
6
7
7
8
sys .path .insert (0 , os .path .join (os .path .dirname (__file__ ), '..' ))
8
9
import clever
@@ -36,9 +37,23 @@ def test_list_accessors(self):
36
37
district = clever .District .all ()[0 ]
37
38
self .assertEqual (district ['name' ], district .name )
38
39
40
+ def test_starting_after (self ):
41
+ allevents = clever .Event .all ()
42
+ second_to_last_id = allevents [len (allevents )- 2 ]['id' ]
43
+ events = clever .Event .iter (starting_after = second_to_last_id )
44
+ count = len (list (events ))
45
+ self .assertTrue (count == 1 )
46
+
47
+ def test_ending_before (self ):
48
+ allevents = clever .Event .all ()
49
+ second_id = allevents [1 ]['id' ]
50
+ events = clever .Event .iter (ending_before = second_id )
51
+ count = len (list (events ))
52
+ self .assertTrue (count == 1 )
53
+
39
54
def test_unicode (self ):
40
55
# Make sure unicode requests can be sent
41
- self .assertRaises (clever .InvalidRequestError , clever .District .retrieve , id = u'☃' )
56
+ self .assertRaises (clever .APIError , clever .District .retrieve , id = u'☃' )
42
57
43
58
def test_none_values (self ):
44
59
district = clever .District .all (sort = None )[0 ]
@@ -76,6 +91,20 @@ def test_iter(self):
76
91
for district in clever .District .iter ():
77
92
self .assertTrue (district .id )
78
93
94
+ def test_starting_after (self ):
95
+ allevents = clever .Event .all ()
96
+ second_to_last_id = allevents [len (allevents )- 2 ]['id' ]
97
+ events = clever .Event .iter (starting_after = second_to_last_id )
98
+ count = len (list (events ))
99
+ self .assertTrue (count == 1 )
100
+
101
+ def test_ending_before (self ):
102
+ allevents = clever .Event .all ()
103
+ second_id = allevents [1 ]['id' ]
104
+ events = clever .Event .iter (ending_before = second_id )
105
+ count = len (list (events ))
106
+ self .assertTrue (count == 1 )
107
+
79
108
def test_iter_count (self ):
80
109
r = requests .get ('https://api.clever.com/v1.1/students?count=true' ,
81
110
headers = {'Authorization' : 'Bearer DEMO_TOKEN' })
@@ -89,10 +118,6 @@ def test_iter_count(self):
89
118
def test_unsupported_params (self ):
90
119
self .assertRaises (clever .CleverError , lambda : clever .District .all (page = 2 ))
91
120
self .assertRaises (clever .CleverError , lambda : clever .District .all (limit = 10 ))
92
- self .assertRaises (clever .CleverError , lambda : clever .District .all (
93
- starting_after = '4fd43cc56d11340000000005' ))
94
- self .assertRaises (clever .CleverError , lambda : clever .District .all (
95
- ending_before = '4fd43cc56d11340000000005' ))
96
121
self .assertRaises (clever .CleverError , lambda : clever .District .all (page = 2 , limit = 10 ))
97
122
98
123
def test_unicode (self ):
@@ -160,7 +185,7 @@ def test_rate_limiter(self):
160
185
suite = unittest .TestSuite ()
161
186
for TestClass in [
162
187
functional_test ({"api_key" : "DEMO_KEY" }),
163
- functional_test ({"token" : "7f76343d50b9e956138169e8cbb4630bb887b18 " }),
188
+ functional_test ({"token" : "DEMO_TOKEN " }),
164
189
AuthenticationErrorTest ,
165
190
InvalidRequestErrorTest ,
166
191
TooManyRequestsErrorTest ]:
0 commit comments