@@ -136,6 +136,46 @@ def test_sort_items_with_invalid_direction(self):
136136 utils .sort_items ,
137137 items , sort_str )
138138
139+ @mock .patch .object (time , 'sleep' )
140+ def test_wait_for_status_ok (self , mock_sleep ):
141+ # Tests the normal flow that the resource is status=active
142+ resource = mock .MagicMock (status = 'ACTIVE' )
143+ status_f = mock .Mock (return_value = resource )
144+ res_id = str (uuid .uuid4 ())
145+ self .assertTrue (utils .wait_for_status (status_f , res_id ,))
146+ self .assertFalse (mock_sleep .called )
147+
148+ @mock .patch .object (time , 'sleep' )
149+ def test_wait_for_status_ok__with_overrides (self , mock_sleep ):
150+ # Tests the normal flow that the resource is status=complete
151+ resource = mock .MagicMock (my_status = 'COMPLETE' )
152+ status_f = mock .Mock (return_value = resource )
153+ res_id = str (uuid .uuid4 ())
154+ self .assertTrue (utils .wait_for_status (status_f , res_id ,
155+ status_field = 'my_status' ,
156+ success_status = ['complete' ]))
157+ self .assertFalse (mock_sleep .called )
158+
159+ @mock .patch .object (time , 'sleep' )
160+ def test_wait_for_status_error (self , mock_sleep ):
161+ # Tests that we fail if the resource is status=error
162+ resource = mock .MagicMock (status = 'ERROR' )
163+ status_f = mock .Mock (return_value = resource )
164+ res_id = str (uuid .uuid4 ())
165+ self .assertFalse (utils .wait_for_status (status_f , res_id ))
166+ self .assertFalse (mock_sleep .called )
167+
168+ @mock .patch .object (time , 'sleep' )
169+ def test_wait_for_status_error_with_overrides (self , mock_sleep ):
170+ # Tests that we fail if the resource is my_status=failed
171+ resource = mock .MagicMock (my_status = 'FAILED' )
172+ status_f = mock .Mock (return_value = resource )
173+ res_id = str (uuid .uuid4 ())
174+ self .assertFalse (utils .wait_for_status (status_f , res_id ,
175+ status_field = 'my_status' ,
176+ error_status = ['failed' ]))
177+ self .assertFalse (mock_sleep .called )
178+
139179 @mock .patch .object (time , 'sleep' )
140180 def test_wait_for_delete_ok (self , mock_sleep ):
141181 # Tests the normal flow that the resource is deleted with a 404 coming
0 commit comments