@@ -25,6 +25,7 @@ class TestClient(base.IOTestCase):
2525 #def tearDown(self):
2626 # time.sleep(30.0)
2727
28+ # Helper Methods
2829 def get_client (self ):
2930 # Construct an Adafruit IO REST client and return it.
3031 return Client (self .get_test_username (), self .get_test_key (), proxies = PROXIES , base_url = BASE_URL , api_version = "v2" )
@@ -51,14 +52,15 @@ def empty_feed(self, client, feed):
5152 for d in data :
5253 client .delete (feed , d .id )
5354
54-
55+ # Test Adafruit IO Key Functionality
5556 def test_set_key_and_username (self ):
5657 username = "unique_username"
5758 key = "unique_key_id"
5859 io = Client (username , key )
5960 self .assertEqual (username , io .username )
6061 self .assertEqual (key , io .key )
6162
63+ # Test Data Functionality
6264 def test_send_and_receive (self ):
6365 io = self .get_client ()
6466 self .ensure_feed_deleted (io , 'testfeed' )
@@ -85,19 +87,18 @@ def test_receive_next(self):
8587 data = io .receive_next ('testfeed' )
8688 self .assertEqual (int (data .value ), 1 )
8789
88- # BUG: Previous jumps too far back: https://github.com/adafruit/io/issues/55
89- @unittest .expectedFailure
9090 def test_receive_previous (self ):
9191 io = self .get_client ()
92- self .ensure_feed_deleted (io , 'TestFeed' )
93- io .send_data ('TestFeed' , 1 )
94- io .send_data ('TestFeed' , 2 )
95- io .receive_next ('TestFeed' ) # Receive 1
96- io .receive_next ('TestFeed' ) # Receive 2
97- data = io .receive_previous ('TestFeed' )
98- self .assertEqual (int (data .value ), 2 )
99- data = io .receive_previous ('TestFeed' )
92+ self .ensure_feed_deleted (io , 'testfeed' )
93+ test_feed = io .create_feed (Feed (name = "testfeed" ))
94+ io .send_data (test_feed .key , 1 )
95+ io .receive_next (test_feed .key ) # Receive 1
96+ data = io .receive_previous (test_feed .key )
10097 self .assertEqual (int (data .value ), 1 )
98+ io .send_data (test_feed .key , 2 )
99+ io .receive_next (test_feed .key ) # Receive 2
100+ data = io .receive_previous (test_feed .key )
101+ self .assertEqual (int (data .value ), 2 )
101102
102103 def test_data_on_feed_returns_all_data (self ):
103104 io = self .get_client ()
@@ -127,7 +128,20 @@ def test_create_data(self):
127128 data = Data (value = 42 )
128129 result = aio .create_data ('testfeed' , data )
129130 self .assertEqual (int (result .value ), 42 )
131+
132+ def test_location_data (self ):
133+ aio = self .get_client ()
134+ self .ensure_feed_deleted (aio , 'testlocfeed' )
135+ test_feed = aio .create_feed (Feed (name = "testlocfeed" ))
136+ aio .send_location_data (test_feed .key , 0 , 40 , - 74 , 6 )
137+ data = aio .receive (test_feed .key )
138+ self .assertEqual (int (data .value ), 0 )
139+ self .assertEqual (float (data .lat ), 40.0 )
140+ self .assertEqual (float (data .lon ), - 74.0 )
141+ self .assertEqual (float (data .ele ), 6.0 )
130142
143+
144+ # Test Feed Functionality
131145 def test_append_by_feed_name (self ):
132146 io = self .get_client ()
133147 self .ensure_feed_deleted (io , 'testfeed' )
@@ -178,6 +192,8 @@ def test_delete_nonexistant_feed_fails(self):
178192 self .ensure_feed_deleted (io , 'testfeed' )
179193 self .assertRaises (RequestError , io .delete_feed , 'testfeed' )
180194
195+
196+ # Test Group Functionality
181197 def test_groups_returns_all_groups (self ):
182198 io = self .get_client ()
183199 groups = io .groups ()
@@ -192,31 +208,23 @@ def test_groups_retrieves_requested_group(self):
192208 self .assertEqual (response .name , 'grouptest' )
193209 self .assertEqual (response .key , 'grouptest' )
194210
195- # BUG: Group create doesn't work: https://github.com/adafruit/io/issues/58
196- @unittest .expectedFailure
197- def test_create_group (self ):
198- io = self .get_client ()
199- self .ensure_group_deleted (io , 'GroupTest2' )
200- self .ensure_feed_deleted (io , 'GroupTest3' )
201- self .ensure_feed_deleted (io , 'GroupTest4' )
202- feed1 = io .create_feed (Feed (name = 'GroupTest3' ))
203- feed2 = io .create_feed (Feed (name = 'GroupTest4' ))
204- io .send_data ('GroupTest3' , 10 )
205- io .send_data ('GroupTest4' , 20 )
206- group = Group (name = 'GroupTest2' , feeds = [feed1 , feed2 ])
207- response = io .create_group (group )
208- self .assertEqual (response .name , 'GroupTest2' )
209- self .assertEqual (len (response .feeds ), 2 )
210-
211- # BUG: Group create doesn't work: https://github.com/adafruit/io/issues/58
212- @unittest .expectedFailure
213211 def test_delete_group (self ):
214212 io = self .get_client ()
215- self .ensure_group_deleted (io , 'GroupDeleteTest ' )
216- group = io .create_group (Group (name = 'GroupDeleteTest ' ))
217- io .delete_group ('GroupDeleteTest ' )
218- self .assertRaises (RequestError , io .groups , 'GroupDeleteTest ' )
213+ self .ensure_group_deleted (io , 'groupdeletetest ' )
214+ group = io .create_group (Group (name = 'groupdeletetest ' ))
215+ io .delete_group ('groupdeletetest ' )
216+ self .assertRaises (RequestError , io .groups , 'groupdeletetest ' )
219217
220- # TODO: Get by group name, key, and ID
221- # TODO: Get data by name, key, ID
222- # TODO: Tests around Adafruit IO keys (make multiple, test they work, etc.)
218+ def test_receive_group_by_name (self ):
219+ io = self .get_client ()
220+ self .ensure_group_deleted (io , 'grouprx' )
221+ group = io .create_group (Group (name = 'grouprx' ))
222+ response = io .groups (group .name )
223+ self .assertEqual (response .name , 'grouprx' )
224+
225+ def test_receive_group_by_key (self ):
226+ io = self .get_client ()
227+ self .ensure_group_deleted (io , 'grouprx' )
228+ group = io .create_group (Group (name = 'grouprx' ))
229+ response = io .groups (group .key )
230+ self .assertEqual (response .key , 'grouprx' )
0 commit comments