Repository: levlaz/circleci.py

Issue:
Update retry method to include retry with SSH
We have retry, and we also have retry without cache via the Experimental API. We should also include an option to retry with SSH as [described here](https://circleci.com/docs/api/v1-reference/#retry-build)

Discussion:

Patch:
diff --git a/circleci/api.py b/circleci/api.py
index cf8a7ab..84ea9c6 100644
--- a/circleci/api.py
+++ b/circleci/api.py
@@ -259,7 +259,7 @@ class Api():
         resp = self._request('GET', endpoint)
         return resp
 
-    def retry_build(self, username, project, build_num, vcs_type='github'):
+    def retry_build(self, username, project, build_num, ssh=False, vcs_type='github'):
         """Retries the build.
 
         Args:
@@ -269,6 +269,8 @@ class Api():
                 case sensitive repo name
             build_num (str):
                 build number
+            ssh: retry a build with SSH enabled
+                defaults to False
             vcs_type (str):
                 defaults to github
                 on circleci.com you can also pass in bitbucket
@@ -276,12 +278,20 @@ class Api():
         Endpoint:
             POST: /project/:vcs-type/:username/:project/:build_num/retry
         """
-        endpoint = 'project/{0}/{1}/{2}/{3}/retry'.format(
-            vcs_type,
-            username,
-            project,
-            build_num
-        )
+        if ssh:
+            endpoint = 'project/{0}/{1}/{2}/{3}/ssh'.format(
+                vcs_type,
+                username,
+                project,
+                build_num
+            )
+        else:
+            endpoint = 'project/{0}/{1}/{2}/{3}/retry'.format(
+                vcs_type,
+                username,
+                project,
+                build_num
+            )
         resp = self._request('POST', endpoint)
         return resp
 


Test patch:
diff --git a/tests/circle/test_api.py b/tests/circle/test_api.py
index 347223b..33c0ee0 100644
--- a/tests/circle/test_api.py
+++ b/tests/circle/test_api.py
@@ -92,6 +92,11 @@ class TestCircleCIApi(unittest.TestCase):
 
         self.assertEqual(resp['reponame'], 'MOCK+testing')
 
+        # with SSH
+        resp = json.loads(self.c.retry_build('ccie-tester', 'testing', '1', ssh=True))
+
+        self.assertEqual(resp['reponame'], 'MOCK+testing')
+
     def test_cancel_build(self):
         self.loadMock('mock_cancel_build_response')
         resp = json.loads(self.c.cancel_build('ccie-tester', 'testing', '11'))
@@ -194,6 +199,12 @@ class TestCircleCIApi(unittest.TestCase):
 
         self.assertEqual(resp[0]['path'],'circleci-docs/index.html')
 
+        resp = json.loads(self.c.get_latest_artifact('levlaz', 'circleci-sandbox', 'master'))
+        self.assertEqual(resp[0]['path'],'circleci-docs/index.html')
+
+        with self.assertRaises(InvalidFilterError):
+            self.c.get_latest_artifact('levlaz', 'circleci-sandbox', 'master', 'invalid')
+
     # def test_helper(self):
     #     resp = self.c.get_latest_artifact('circleci', 'circleci-docs')
     #     print(resp)
diff --git a/tests/circle/test_error.py b/tests/circle/test_error.py
index bab58d1..c907ad2 100644
--- a/tests/circle/test_error.py
+++ b/tests/circle/test_error.py
@@ -11,7 +11,7 @@ class TestCircleCIError(unittest.TestCase):
         self.key = BadKeyError('fake')
         self.verb = BadVerbError('fake')
         self.filter = InvalidFilterError('fake', 'status')
-
+        self.afilter = InvalidFilterError('fake', 'artifacts')
     def test_error_implements_str(self):
         self.assertTrue(self.base.__str__ is not object.__str__)
 
@@ -26,5 +26,6 @@ class TestCircleCIError(unittest.TestCase):
         self.assertIn('deploy-key', self.key.message)
 
     def test_filter_message(self):
-        print(self.filter)
-        self.assertIn('running', self.filter.message)
\ No newline at end of file
+        self.assertIn('running', self.filter.message)
+
+        self.assertIn('completed', self.afilter.message)
\ No newline at end of file