diff --git a/Algorithmia/algorithm.py b/Algorithmia/algorithm.py index b4f75a1..7d2adcd 100644 --- a/Algorithmia/algorithm.py +++ b/Algorithmia/algorithm.py @@ -39,10 +39,15 @@ def set_options(self, timeout=300, stdout=False, output=OutputType.default, **qu return self # Create a new algorithm - def create(self, details={}, settings={}, version_info={}, source={}, scmsCredentials={}): + def create(self, details, settings, version_info=None, source=None, scmsCredentials=None): url = "/v1/algorithms/" + self.username - create_parameters = {"name": self.algoname, "details": details, "settings": settings, - "version_info": version_info, "source": source, "scmsCredentials": scmsCredentials} + create_parameters = {"name": self.algoname, "details": details, "settings": settings} + if version_info: + create_parameters['version_info'] = version_info + if source: + create_parameters['source'] = source + if scmsCredentials: + create_parameters['scmsCredentials'] = scmsCredentials api_response = self.client.postJsonHelper(url, create_parameters, parse_response_as_json=True) return api_response diff --git a/Algorithmia/client.py b/Algorithmia/client.py index 74d88fa..ffc3f03 100644 --- a/Algorithmia/client.py +++ b/Algorithmia/client.py @@ -71,6 +71,11 @@ def username(self): username = next(self.dir("").list()).path return username + def scms(self): + url = "/v1/scms" + response = self.getJsonHelper(url) + return response + def file(self, dataUrl, cleanup=False): if dataUrl.startswith('file://'): return LocalDataFile(self, dataUrl) diff --git a/Test/api/app.py b/Test/api/app.py index 8871d91..825af29 100644 --- a/Test/api/app.py +++ b/Test/api/app.py @@ -80,7 +80,8 @@ async def process_get_algo(request: Request, username, algoname): "resource_type": "algorithm"} elif algoname == "echo": return JSONResponse(content={"error": {"id": "1cfb98c5-532e-4cbf-9192-fdd45b86969c", "code": 2001, - "message": "Caller is not authorized to perform the operation"}}, status_code=403) + "message": "Caller is not authorized to perform the operation"}}, + status_code=403) else: return JSONResponse(content={"error": "No such algorithm"}, status_code=404) @@ -102,6 +103,34 @@ async def get_scm_status(username, algoname): return {"scm_connection_status": "active"} +@regular_app.get("/v1/scms") +async def get_scms(): + return {'results': [{'default': True, 'enabled': True, 'id': 'internal', 'name': '', 'provider': 'internal'}, + {'default': False, 'enabled': True, 'id': 'github', 'name': 'https://github.com', + 'provider': 'github', 'scm': {'client_id': '0ff25ba21ec67dbed6e2'}, + 'oauth': {'client_id': '0ff25ba21ec67dbed6e2'}, + 'urls': {'web': 'https://github.com', 'api': 'https://api.github.com', + 'ssh': 'ssh://git@github.com'}}, + {'default': False, 'enabled': True, 'id': 'aadebe70-007f-48ff-ba38-49007c6e0377', + 'name': 'https://gitlab.com', 'provider': 'gitlab', + 'scm': {'client_id': 'ca459576279bd99ed480236a267cc969f8322caad292fa5147cc7fdf7b530a7e'}, + 'oauth': {'client_id': 'ca459576279bd99ed480236a267cc969f8322caad292fa5147cc7fdf7b530a7e'}, + 'urls': {'web': 'https://gitlab.com', 'api': 'https://gitlab.com', + 'ssh': 'ssh://git@gitlab.com'}}, + {'default': False, 'enabled': True, 'id': '24ad1496-5a1d-43e2-9d96-42fce8e5484f', + 'name': 'IQIVA Public GitLab', 'provider': 'gitlab', + 'scm': {'client_id': '3341c989f9d28043d2597388aa4f43ce60a74830b981c4b7d79becf641959376'}, + 'oauth': {'client_id': '3341c989f9d28043d2597388aa4f43ce60a74830b981c4b7d79becf641959376'}, + 'urls': {'web': 'https://gitlab.com', 'api': 'https://gitlab.com', + 'ssh': 'ssh://git@gitlab.com'}}, + {'default': False, 'enabled': False, 'id': '83cd96ae-b1f4-4bd9-b9ca-6f7f25c37708', + 'name': 'GitlabTest', 'provider': 'gitlab', + 'scm': {'client_id': '5e257d6e168d579d439b7d38cdfa647e16573ae1dace6d93a30c5c60b4e5dd32'}, + 'oauth': {'client_id': '5e257d6e168d579d439b7d38cdfa647e16573ae1dace6d93a30c5c60b4e5dd32'}, + 'urls': {'web': 'https://gitlab.com', 'api': 'https://gitlab.com', + 'ssh': 'ssh://git@gitlab.com'}}]} + + @regular_app.get("/v1/algorithms/{algo_id}/errors") async def get_algo_errors(algo_id): return JSONResponse(content={"error": {"message": "not found"}}, status_code=404) diff --git a/Test/regular/client_test.py b/Test/regular/client_test.py index c7ed9f2..9cfc39b 100644 --- a/Test/regular/client_test.py +++ b/Test/regular/client_test.py @@ -20,6 +20,7 @@ class ClientDummyTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.client = Algorithmia.client(api_address="http://localhost:8080", api_key="simabcd123") + admin_username = "a_Mrtest" admin_org_name = "a_myOrg" environment_name = "Python 3.9" @@ -28,7 +29,6 @@ def setUp(self): self.admin_username = self.admin_username + str(int(random() * 10000)) self.admin_org_name = self.admin_org_name + str(int(random() * 10000)) - def test_create_user(self): response = self.client.create_user( {"username": self.admin_username, "email": self.admin_username + "@algo.com", "passwordHash": "", @@ -60,6 +60,12 @@ def test_get_environment(self): if u'error' not in response: self.assertTrue(response is not None and u'environments' in response) + def test_get_scms(self): + response = self.client.scms() + results = response['results'] + internal = [result for result in results if result['id'] == 'internal'] + self.assertTrue(len(internal) == 1) + def test_edit_org(self): org_name = "a_myOrg84" @@ -120,7 +126,6 @@ def test_get_algorithm_errors(self): except AlgorithmException as e: self.assertTrue(e.message == "No such algorithm") - def test_no_auth_client(self): key = os.environ.get('ALGORITHMIA_API_KEY', "") @@ -135,6 +140,7 @@ def test_no_auth_client(self): error = e finally: os.environ['ALGORITHMIA_API_KEY'] = key - self.assertEqual(str(error), str(AlgorithmException(message="authorization required", stack_trace=None, error_type=None))) + self.assertEqual(str(error), str(AlgorithmException(message="authorization required", stack_trace=None, + error_type=None))) if __name__ == '__main__': unittest.main()