33import sys
44import unittest
55import httmock
6+ import itertools
67
78sys .path .insert (0 , os .path .join (os .path .dirname (__file__ ), '..' ))
89import clever
@@ -36,9 +37,23 @@ def test_list_accessors(self):
3637 district = clever .District .all ()[0 ]
3738 self .assertEqual (district ['name' ], district .name )
3839
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+
3954 def test_unicode (self ):
4055 # 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'☃' )
4257
4358 def test_none_values (self ):
4459 district = clever .District .all (sort = None )[0 ]
@@ -76,6 +91,20 @@ def test_iter(self):
7691 for district in clever .District .iter ():
7792 self .assertTrue (district .id )
7893
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+
79108 def test_iter_count (self ):
80109 r = requests .get ('https://api.clever.com/v1.1/students?count=true' ,
81110 headers = {'Authorization' : 'Bearer DEMO_TOKEN' })
@@ -89,10 +118,6 @@ def test_iter_count(self):
89118 def test_unsupported_params (self ):
90119 self .assertRaises (clever .CleverError , lambda : clever .District .all (page = 2 ))
91120 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' ))
96121 self .assertRaises (clever .CleverError , lambda : clever .District .all (page = 2 , limit = 10 ))
97122
98123 def test_unicode (self ):
@@ -160,7 +185,7 @@ def test_rate_limiter(self):
160185 suite = unittest .TestSuite ()
161186 for TestClass in [
162187 functional_test ({"api_key" : "DEMO_KEY" }),
163- functional_test ({"token" : "7f76343d50b9e956138169e8cbb4630bb887b18 " }),
188+ functional_test ({"token" : "DEMO_TOKEN " }),
164189 AuthenticationErrorTest ,
165190 InvalidRequestErrorTest ,
166191 TooManyRequestsErrorTest ]:
0 commit comments