From b1c591e83c61e56266e14fa2dbbe810c437b0742 Mon Sep 17 00:00:00 2001 From: Kevin Chu Date: Thu, 15 Jun 2023 18:44:15 -0700 Subject: [PATCH 1/2] style: lint+fix ruff errors --- .pre-commit-config.yaml | 1 - exabyte_api_client/__init__.py | 1 + exabyte_api_client/endpoints/__init__.py | 12 +++---- exabyte_api_client/endpoints/bank_entity.py | 2 +- .../endpoints/bank_materials.py | 2 +- .../endpoints/bank_workflows.py | 2 +- exabyte_api_client/endpoints/charges.py | 2 +- exabyte_api_client/endpoints/entity.py | 12 +++---- exabyte_api_client/endpoints/jobs.py | 32 +++++++------------ exabyte_api_client/endpoints/login.py | 6 ++-- exabyte_api_client/endpoints/logout.py | 4 +-- exabyte_api_client/endpoints/materials.py | 4 +-- .../endpoints/mixins/default.py | 2 +- exabyte_api_client/endpoints/mixins/set.py | 6 ++-- exabyte_api_client/endpoints/projects.py | 2 +- .../endpoints/raw_properties.py | 2 +- .../endpoints/refined_properties.py | 2 +- exabyte_api_client/endpoints/workflows.py | 2 +- exabyte_api_client/utils/http.py | 4 +-- exabyte_api_client/utils/materials.py | 2 +- tests/__init__.py | 2 +- tests/integration/__init__.py | 12 +++---- tests/integration/entity.py | 18 +++++------ tests/integration/test_jobs.py | 31 +++++++----------- tests/integration/test_materials.py | 6 ++-- tests/unit/__init__.py | 8 ++--- tests/unit/entity.py | 16 +++++----- tests/unit/test_bank_materials.py | 4 +-- tests/unit/test_bank_workflows.py | 4 +-- tests/unit/test_httpBase.py | 20 ++++++------ tests/unit/test_jobs.py | 8 ++--- tests/unit/test_login.py | 16 +++++----- tests/unit/test_logout.py | 8 ++--- tests/unit/test_materials.py | 8 ++--- tests/unit/test_refined_properties.py | 4 +-- tests/unit/test_workflows.py | 8 ++--- 36 files changed, 130 insertions(+), 145 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6523be5..c198bd2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,4 +4,3 @@ repos: hooks: - id: ruff - id: black - - id: pydocstyle diff --git a/exabyte_api_client/__init__.py b/exabyte_api_client/__init__.py index e947a3f..bc91316 100644 --- a/exabyte_api_client/__init__.py +++ b/exabyte_api_client/__init__.py @@ -1,3 +1,4 @@ +# ruff: noqa: F401 try: from ._version import version as __version__ except ModuleNotFoundError: diff --git a/exabyte_api_client/endpoints/__init__.py b/exabyte_api_client/endpoints/__init__.py index 199b558..d88ea26 100644 --- a/exabyte_api_client/endpoints/__init__.py +++ b/exabyte_api_client/endpoints/__init__.py @@ -1,4 +1,4 @@ -import json +import json # noqa: F401 from ..utils.http import Connection @@ -17,7 +17,7 @@ class BaseEndpoint(object): conn (httplib.ExabyteConnection): ExabyteConnection instance. """ - def __init__(self, host, port, version='2018-10-1', secure=True, **kwargs): + def __init__(self, host, port, version="2018-10-1", secure=True, **kwargs): self.conn = Connection(host, port, version=version, secure=secure, **kwargs) def request(self, method, endpoint_path, params=None, data=None, headers=None): @@ -37,9 +37,9 @@ def request(self, method, endpoint_path, params=None, data=None, headers=None): with self.conn: self.conn.request(method, endpoint_path, params, data, headers) response = self.conn.json() - if response['status'] != 'success': - raise BaseException(response['data']['message']) - return response['data'] + if response["status"] != "success": + raise BaseException(response["data"]["message"]) + return response["data"] def get_headers(self, account_id, auth_token, content_type="application/json"): - return {'X-Account-Id': account_id, 'X-Auth-Token': auth_token, 'Content-Type': content_type} + return {"X-Account-Id": account_id, "X-Auth-Token": auth_token, "Content-Type": content_type} diff --git a/exabyte_api_client/endpoints/bank_entity.py b/exabyte_api_client/endpoints/bank_entity.py index cf7b4ad..79b7d3a 100644 --- a/exabyte_api_client/endpoints/bank_entity.py +++ b/exabyte_api_client/endpoints/bank_entity.py @@ -44,4 +44,4 @@ def copy(self, id_, account_id=None): dict: new entity. """ params = {"accountId": account_id} - return self.request('POST', '/'.join((self.name, id_, "copy")), params=params, headers=self.headers) + return self.request("POST", "/".join((self.name, id_, "copy")), params=params, headers=self.headers) diff --git a/exabyte_api_client/endpoints/bank_materials.py b/exabyte_api_client/endpoints/bank_materials.py index fe1c547..e77a3e7 100644 --- a/exabyte_api_client/endpoints/bank_materials.py +++ b/exabyte_api_client/endpoints/bank_materials.py @@ -22,4 +22,4 @@ class BankMaterialEndpoints(BankEntityEndpoints): def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs): super(BankMaterialEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs) - self.name = 'bank-materials' + self.name = "bank-materials" diff --git a/exabyte_api_client/endpoints/bank_workflows.py b/exabyte_api_client/endpoints/bank_workflows.py index c59f419..d999257 100644 --- a/exabyte_api_client/endpoints/bank_workflows.py +++ b/exabyte_api_client/endpoints/bank_workflows.py @@ -22,4 +22,4 @@ class BankWorkflowEndpoints(BankEntityEndpoints): def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs): super(BankWorkflowEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs) - self.name = 'bank-workflows' + self.name = "bank-workflows" diff --git a/exabyte_api_client/endpoints/charges.py b/exabyte_api_client/endpoints/charges.py index d52a7bb..3042417 100644 --- a/exabyte_api_client/endpoints/charges.py +++ b/exabyte_api_client/endpoints/charges.py @@ -25,7 +25,7 @@ class ChargeEndpoints(EntityEndpoint): def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs): super(ChargeEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs) - self.name = 'charges' + self.name = "charges" def delete(self, id_): raise NotImplementedError diff --git a/exabyte_api_client/endpoints/entity.py b/exabyte_api_client/endpoints/entity.py index 6187327..da56c10 100644 --- a/exabyte_api_client/endpoints/entity.py +++ b/exabyte_api_client/endpoints/entity.py @@ -40,7 +40,7 @@ def list(self, query=None, projection=None): list[dict] """ params = {"query": json.dumps(query or {}), "projection": json.dumps(projection or {})} - return self.request('GET', self.name, params=params, headers=self.headers) + return self.request("GET", self.name, params=params, headers=self.headers) def get(self, id_): """ @@ -52,7 +52,7 @@ def get(self, id_): Returns: dict: entity. """ - return self.request('GET', '/'.join((self.name, id_)), headers=self.headers) + return self.request("GET", "/".join((self.name, id_)), headers=self.headers) def delete(self, id_): """ @@ -61,7 +61,7 @@ def delete(self, id_): Args: id_ (str): entity ID. """ - return self.request('DELETE', '/'.join((self.name, id_)), headers=self.headers) + return self.request("DELETE", "/".join((self.name, id_)), headers=self.headers) def update(self, id_, modifier): """ @@ -74,7 +74,7 @@ def update(self, id_, modifier): Returns: dict: updated entity. """ - return self.request('PATCH', '/'.join((self.name, id_)), data=json.dumps(modifier), headers=self.headers) + return self.request("PATCH", "/".join((self.name, id_)), data=json.dumps(modifier), headers=self.headers) def create(self, config): """ @@ -86,7 +86,7 @@ def create(self, config): Returns: dict: new entity. """ - return self.request('PUT', '/'.join((self.name, "create")), data=json.dumps(config), headers=self.headers) + return self.request("PUT", "/".join((self.name, "create")), data=json.dumps(config), headers=self.headers) def copy(self, id_): """ @@ -98,4 +98,4 @@ def copy(self, id_): Returns: dict: new entity. """ - return self.request('POST', '/'.join((self.name, id_, "copy")), headers=self.headers) + return self.request("POST", "/".join((self.name, id_, "copy")), headers=self.headers) diff --git a/exabyte_api_client/endpoints/jobs.py b/exabyte_api_client/endpoints/jobs.py index 9f319fd..808a050 100644 --- a/exabyte_api_client/endpoints/jobs.py +++ b/exabyte_api_client/endpoints/jobs.py @@ -25,7 +25,7 @@ class JobEndpoints(EntitySetEndpointsMixin, EntityEndpoint): def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs): super(JobEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs) - self.name = 'jobs' + self.name = "jobs" def submit(self, id_): """ @@ -34,7 +34,7 @@ def submit(self, id_): Args: id_ (str): job ID. """ - self.request('POST', '/'.join((self.name, id_, "submit")), headers=self.headers) + self.request("POST", "/".join((self.name, id_, "submit")), headers=self.headers) def purge(self, id_): """ @@ -43,7 +43,7 @@ def purge(self, id_): Args: id_ (str): job ID. """ - self.request('POST', '/'.join((self.name, id_, "submit")), headers=self.headers) + self.request("POST", "/".join((self.name, id_, "submit")), headers=self.headers) def terminate(self, id_): """ @@ -52,7 +52,7 @@ def terminate(self, id_): Args: id_ (str): job ID. """ - self.request('POST', '/'.join((self.name, id_, "submit")), headers=self.headers) + self.request("POST", "/".join((self.name, id_, "submit")), headers=self.headers) def get_config(self, material_ids, workflow_id, project_id, owner_id, name, compute=None, is_multi_material=False): """ @@ -71,16 +71,10 @@ def get_config(self, material_ids, workflow_id, project_id, owner_id, name, comp dict """ config = { - "_project": { - "_id": project_id - }, - "workflow": { - "_id": workflow_id - }, - "owner": { - "_id": owner_id - }, - "name": name + "_project": {"_id": project_id}, + "workflow": {"_id": workflow_id}, + "owner": {"_id": owner_id}, + "name": name, } if compute: @@ -112,10 +106,8 @@ def get_compute(self, cluster, ppn=1, nodes=1, queue="D", time_limit="01:00:00", "queue": queue, "timeLimit": time_limit, "notify": notify, - "cluster": { - "fqdn": cluster - }, - "arguments": {} + "cluster": {"fqdn": cluster}, + "arguments": {}, } def create_by_ids(self, materials, workflow_id, project_id, owner_id, prefix, compute=None): @@ -152,7 +144,7 @@ def get_presigned_urls(self, id_, files): list: [{"file": "", "URL": ""}] """ data = json.dumps({"files": files}) - response = self.request('POST', '/'.join((self.name, id_, "presigned-urls")), data=data, headers=self.headers) + response = self.request("POST", "/".join((self.name, id_, "presigned-urls")), data=data, headers=self.headers) return response["presignedURLs"] def list_files(self, id_): @@ -166,7 +158,7 @@ def list_files(self, id_): list: [{ "key" : str, "size" : int, "bucket" : str, "region" : str, "provider" : str, "lastModified" : int, "name" : str, "signedURL" : str }] """ - response = self.request('GET', '/'.join(('jobs', id_, 'files')), headers=self.headers) + response = self.request("GET", "/".join(("jobs", id_, "files")), headers=self.headers) return response def insert_output_files(self, id_, data): diff --git a/exabyte_api_client/endpoints/login.py b/exabyte_api_client/endpoints/login.py index a9e429a..1e5050c 100644 --- a/exabyte_api_client/endpoints/login.py +++ b/exabyte_api_client/endpoints/login.py @@ -24,7 +24,7 @@ class LoginEndpoint(BaseEndpoint): def __init__(self, host, port, username, password, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs): super(LoginEndpoint, self).__init__(host, port, version, secure, **kwargs) - self.name = 'login' + self.name = "login" self.username = username self.password = password @@ -35,8 +35,8 @@ def login(self): Returns: dict """ - data = {'username': self.username, 'password': self.password} - return self.request('POST', self.name, data=data) + data = {"username": self.username, "password": self.password} + return self.request("POST", self.name, data=data) @staticmethod def get_endpoint_options(host, port, username, password, version=DEFAULT_API_VERSION, secure=SECURE): diff --git a/exabyte_api_client/endpoints/logout.py b/exabyte_api_client/endpoints/logout.py index d31c68b..8cc615d 100644 --- a/exabyte_api_client/endpoints/logout.py +++ b/exabyte_api_client/endpoints/logout.py @@ -23,11 +23,11 @@ class LogoutEndpoint(BaseEndpoint): def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs): super(LogoutEndpoint, self).__init__(host, port, version, secure, **kwargs) - self.name = 'logout' + self.name = "logout" self.headers = self.get_headers(account_id, auth_token) def logout(self): """ Deletes current API token. """ - return self.request('POST', self.name, headers=self.headers) + return self.request("POST", self.name, headers=self.headers) diff --git a/exabyte_api_client/endpoints/materials.py b/exabyte_api_client/endpoints/materials.py index 6f2f069..46acfb4 100644 --- a/exabyte_api_client/endpoints/materials.py +++ b/exabyte_api_client/endpoints/materials.py @@ -27,7 +27,7 @@ class MaterialEndpoints(EntitySetEndpointsMixin, DefaultableEntityEndpointsMixin def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs): super(MaterialEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs) - self.name = 'materials' + self.name = "materials" def import_from_file(self, name, content, owner_id=None, format="poscar", tags=()): """ @@ -44,7 +44,7 @@ def import_from_file(self, name, content, owner_id=None, format="poscar", tags=( dict """ data = {"name": name, "content": content, "format": format, "ownerId": owner_id, "tags": tags} - return self.request('POST', "/".join((self.name, "import")), headers=self.headers, data=json.dumps(data)) + return self.request("POST", "/".join((self.name, "import")), headers=self.headers, data=json.dumps(data)) def import_from_materialsproject(self, api_key, material_ids, owner_id=None, tags=[]): """ diff --git a/exabyte_api_client/endpoints/mixins/default.py b/exabyte_api_client/endpoints/mixins/default.py index 8377645..10989e0 100644 --- a/exabyte_api_client/endpoints/mixins/default.py +++ b/exabyte_api_client/endpoints/mixins/default.py @@ -13,4 +13,4 @@ def set_default(self, id_): Returns: dict: new entity. """ - self.request('POST', '/'.join((self.name, id_, "set-default")), headers=self.headers) + self.request("POST", "/".join((self.name, id_, "set-default")), headers=self.headers) diff --git a/exabyte_api_client/endpoints/mixins/set.py b/exabyte_api_client/endpoints/mixins/set.py index a2114bb..b55c30c 100644 --- a/exabyte_api_client/endpoints/mixins/set.py +++ b/exabyte_api_client/endpoints/mixins/set.py @@ -16,8 +16,8 @@ def create_set(self, config): Returns: dict: new entity set. """ - path_ = '/'.join((self.name, "create-set")) - return self.request('PUT', path_, data=json.dumps(config), headers=self.headers) + path_ = "/".join((self.name, "create-set")) + return self.request("PUT", path_, data=json.dumps(config), headers=self.headers) def move_to_set(self, _id, old_set_id, new_set_id): """ @@ -29,4 +29,4 @@ def move_to_set(self, _id, old_set_id, new_set_id): new_set_id (str): new entity set ID. """ params = {"oldSetId": old_set_id, "newSetId": new_set_id} - self.request('POST', '/'.join((self.name, _id, "move-to-set")), params=params, headers=self.headers) + self.request("POST", "/".join((self.name, _id, "move-to-set")), params=params, headers=self.headers) diff --git a/exabyte_api_client/endpoints/projects.py b/exabyte_api_client/endpoints/projects.py index 4b83b00..d11f94b 100644 --- a/exabyte_api_client/endpoints/projects.py +++ b/exabyte_api_client/endpoints/projects.py @@ -26,7 +26,7 @@ class ProjectEndpoints(DefaultableEntityEndpointsMixin, EntityEndpoint): def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs): super(ProjectEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs) - self.name = 'projects' + self.name = "projects" def delete(self, id_): raise NotImplementedError diff --git a/exabyte_api_client/endpoints/raw_properties.py b/exabyte_api_client/endpoints/raw_properties.py index 2d82a18..18eaf6e 100644 --- a/exabyte_api_client/endpoints/raw_properties.py +++ b/exabyte_api_client/endpoints/raw_properties.py @@ -44,7 +44,7 @@ class RawPropertiesEndpoints(BasePropertiesEndpoints): def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs): super(RawPropertiesEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs) - self.name = 'raw-properties' + self.name = "raw-properties" def delete(self, id_): raise NotImplementedError diff --git a/exabyte_api_client/endpoints/refined_properties.py b/exabyte_api_client/endpoints/refined_properties.py index 5fd5238..c88b415 100644 --- a/exabyte_api_client/endpoints/refined_properties.py +++ b/exabyte_api_client/endpoints/refined_properties.py @@ -25,7 +25,7 @@ class RefinedPropertiesEndpoints(BasePropertiesEndpoints): def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs): super(RefinedPropertiesEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs) - self.name = 'refined-properties' + self.name = "refined-properties" def delete(self, id_): raise NotImplementedError diff --git a/exabyte_api_client/endpoints/workflows.py b/exabyte_api_client/endpoints/workflows.py index 0672a11..13f460a 100644 --- a/exabyte_api_client/endpoints/workflows.py +++ b/exabyte_api_client/endpoints/workflows.py @@ -26,4 +26,4 @@ class WorkflowEndpoints(DefaultableEntityEndpointsMixin, EntityEndpoint): def __init__(self, host, port, account_id, auth_token, version=DEFAULT_API_VERSION, secure=SECURE, **kwargs): super(WorkflowEndpoints, self).__init__(host, port, account_id, auth_token, version, secure, **kwargs) - self.name = 'workflows' + self.name = "workflows" diff --git a/exabyte_api_client/utils/http.py b/exabyte_api_client/utils/http.py index 853f25d..bfc8096 100644 --- a/exabyte_api_client/utils/http.py +++ b/exabyte_api_client/utils/http.py @@ -18,7 +18,7 @@ class BaseConnection(object): def __init__(self, **kwargs): self.response = None self.session = requests.Session() - self.session.timeout = kwargs.get('timeout', 60) + self.session.timeout = kwargs.get("timeout", 60) def request(self, method, url, params=None, data=None, headers=None): """ @@ -129,7 +129,7 @@ class Connection(BaseConnection): """ def __init__(self, host, port, version, secure, **kwargs): - self.preamble = '{}://{}:{}/api/{}/'.format('https' if secure else 'http', host, port, version) + self.preamble = "{}://{}:{}/api/{}/".format("https" if secure else "http", host, port, version) super(Connection, self).__init__(**kwargs) def request(self, method, endpoint_path, params=None, data=None, headers=None): diff --git a/exabyte_api_client/utils/materials.py b/exabyte_api_client/utils/materials.py index a4728d1..d31044f 100644 --- a/exabyte_api_client/utils/materials.py +++ b/exabyte_api_client/utils/materials.py @@ -38,5 +38,5 @@ def flatten_material(material): lattice["c"], lattice["alpha"], lattice["beta"], - lattice["gamma"] + lattice["gamma"], ] diff --git a/tests/__init__.py b/tests/__init__.py index 0b039af..c756939 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -12,7 +12,7 @@ def __init__(self, *args, **kwargs): super(EndpointBaseTest, self).__init__(*args, **kwargs) def get_file_path(self, filename): - return os.path.join(os.path.dirname(__file__), 'data', filename) + return os.path.join(os.path.dirname(__file__), "data", filename) def get_content(self, filename): with open(self.get_file_path(filename)) as f: diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py index 53550e8..9a99cfa 100644 --- a/tests/integration/__init__.py +++ b/tests/integration/__init__.py @@ -11,10 +11,10 @@ class BaseIntegrationTest(EndpointBaseTest): def __init__(self, *args, **kwargs): super(BaseIntegrationTest, self).__init__(*args, **kwargs) self.endpoint_kwargs = { - 'host': os.environ['TEST_HOST'], - 'port': os.environ['TEST_PORT'], - 'account_id': os.environ['TEST_ACCOUNT_ID'], - 'auth_token': os.environ['TEST_AUTH_TOKEN'], - 'secure': os.environ.get('TEST_SECURE', 'False').lower() == 'true', - 'version': os.environ.get('TEST_VERSION', '2018-10-01') + "host": os.environ["TEST_HOST"], + "port": os.environ["TEST_PORT"], + "account_id": os.environ["TEST_ACCOUNT_ID"], + "auth_token": os.environ["TEST_AUTH_TOKEN"], + "secure": os.environ.get("TEST_SECURE", "False").lower() == "true", + "version": os.environ.get("TEST_VERSION", "2018-10-01"), } diff --git a/tests/integration/entity.py b/tests/integration/entity.py index 0ccb11c..cc33e71 100644 --- a/tests/integration/entity.py +++ b/tests/integration/entity.py @@ -21,7 +21,7 @@ def entities_selector(self): def tearDown(self): for entity in [e for e in self.endpoints.list(query=self.entities_selector())]: - self.endpoints.delete(entity['_id']) + self.endpoints.delete(entity["_id"]) def get_default_config(self): """ @@ -39,24 +39,24 @@ def create_entity(self, kwargs=None): def list_entities_test(self): entity = self.create_entity() - self.assertIn(entity['_id'], [e['_id'] for e in self.endpoints.list(query=self.entities_selector())]) + self.assertIn(entity["_id"], [e["_id"] for e in self.endpoints.list(query=self.entities_selector())]) def get_entity_by_id_test(self): entity = self.create_entity() - self.assertEqual(self.endpoints.get(entity['_id'])['_id'], entity['_id']) + self.assertEqual(self.endpoints.get(entity["_id"])["_id"], entity["_id"]) def create_entity_test(self): name = "test-{}".format(time.time()) job = self.create_entity({"name": name}) - self.assertEqual(job['name'], name) - self.assertIsNotNone(job['_id']) + self.assertEqual(job["name"], name) + self.assertIsNotNone(job["_id"]) def delete_entity_test(self): entity = self.create_entity() - self.endpoints.delete(entity['_id']) - self.assertNotIn(entity['_id'], [e['_id'] for e in self.endpoints.list(query=self.entities_selector())]) + self.endpoints.delete(entity["_id"]) + self.assertNotIn(entity["_id"], [e["_id"] for e in self.endpoints.list(query=self.entities_selector())]) def update_entity_test(self): entity = self.create_entity() - updated_entity = self.endpoints.update(entity['_id'], {'name': 'UPDATED'}) - self.assertEqual(updated_entity['name'], 'UPDATED') + updated_entity = self.endpoints.update(entity["_id"], {"name": "UPDATED"}) + self.assertEqual(updated_entity["name"], "UPDATED") diff --git a/tests/integration/test_jobs.py b/tests/integration/test_jobs.py index 591d6b8..c8ec4d5 100644 --- a/tests/integration/test_jobs.py +++ b/tests/integration/test_jobs.py @@ -9,6 +9,7 @@ class JobEndpointsIntegrationTest(EntityIntegrationTest): """ Job endpoints integration tests. """ + KNOWN_COMPLETED_JOB_ID = "9gyhfncWDhnSyzALv" def __init__(self, *args, **kwargs): @@ -20,17 +21,11 @@ def get_default_config(self): Returns the default entity config. Override upon inheritance. """ - now_time = datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S') + now_time = datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S") return {"name": "API-CLIENT TEST JOB {}".format(now_time)} - def get_compute_params(self, nodes=1, notify='n', ppn=1, queue='D', time_limit='00:05:00'): - return { - "nodes": nodes, - "notify": notify, - "ppn": ppn, - "queue": queue, - "timeLimit": time_limit - } + def get_compute_params(self, nodes=1, notify="n", ppn=1, queue="D", time_limit="00:05:00"): + return {"nodes": nodes, "notify": notify, "ppn": ppn, "queue": queue, "timeLimit": time_limit} def test_list_jobs(self): self.list_entities_test() @@ -58,25 +53,23 @@ def _wait_for_job_to_finish(self, id_, timeout=300): def test_submit_job_and_wait_to_finish(self): job = self.create_entity() - self.endpoints.submit(job['_id']) - self.assertEqual('submitted', self.endpoints.get(job['_id'])['status']) + self.endpoints.submit(job["_id"]) + self.assertEqual("submitted", self.endpoints.get(job["_id"])["status"]) self._wait_for_job_to_finish(job["_id"]) def test_create_job_timeLimit(self): time_limit = "00:10:00" job = self.create_entity({"compute": self.get_compute_params(time_limit=time_limit)}) - self.assertEqual(self.endpoints.get(job['_id'])['_id'], job['_id']) - self.assertEqual(self.endpoints.get(job['_id'])['compute']['timeLimit'], time_limit) + self.assertEqual(self.endpoints.get(job["_id"])["_id"], job["_id"]) + self.assertEqual(self.endpoints.get(job["_id"])["compute"]["timeLimit"], time_limit) def test_create_job_notify(self): - job = self.create_entity({"compute": self.get_compute_params(notify='abe')}) - self.assertEqual(self.endpoints.get(job['_id'])['_id'], job['_id']) - self.assertEqual(self.endpoints.get(job['_id'])['compute']['notify'], 'abe') + job = self.create_entity({"compute": self.get_compute_params(notify="abe")}) + self.assertEqual(self.endpoints.get(job["_id"])["_id"], job["_id"]) + self.assertEqual(self.endpoints.get(job["_id"])["compute"]["notify"], "abe") def test_list_files(self): - http_response_data = self.endpoints.list_files( - self.KNOWN_COMPLETED_JOB_ID - ) + http_response_data = self.endpoints.list_files(self.KNOWN_COMPLETED_JOB_ID) self.assertIsInstance(http_response_data, list) self.assertGreater(len(http_response_data), 0) self.assertIsInstance(http_response_data[0], dict) diff --git a/tests/integration/test_materials.py b/tests/integration/test_materials.py index a19d282..2ba28aa 100644 --- a/tests/integration/test_materials.py +++ b/tests/integration/test_materials.py @@ -12,7 +12,7 @@ def __init__(self, *args, **kwargs): self.endpoints = MaterialEndpoints(**self.endpoint_kwargs) def get_default_config(self): - return self.get_content_in_json('material.json') + return self.get_content_in_json("material.json") def test_list_materials(self): self.list_entities_test() @@ -31,5 +31,5 @@ def test_update_material(self): def test_get_material_by_formula(self): material = self.create_entity() - materials = self.endpoints.list(query={"_id": material["_id"], "formula": 'Si'}) - self.assertIn(material['_id'], [m['_id'] for m in materials]) + materials = self.endpoints.list(query={"_id": material["_id"], "formula": "Si"}) + self.assertIn(material["_id"], [m["_id"] for m in materials]) diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py index abfa47c..ae8737b 100644 --- a/tests/unit/__init__.py +++ b/tests/unit/__init__.py @@ -12,11 +12,11 @@ def __init__(self, *args, **kwargs): super(EndpointBaseUnitTest, self).__init__(*args, **kwargs) self.port = 4000 self.version = "2018-10-01" - self.host = 'platform.mat3ra.com' - self.account_id = 'ubxMkAyx37Rjn8qK9' - self.auth_token = 'XihOnUA8EqytSui1icz6fYhsJ2tUsJGGTlV03upYPSF' + self.host = "platform.mat3ra.com" + self.account_id = "ubxMkAyx37Rjn8qK9" + self.auth_token = "XihOnUA8EqytSui1icz6fYhsJ2tUsJGGTlV03upYPSF" - def mock_response(self, content, status_code=200, reason='OK'): + def mock_response(self, content, status_code=200, reason="OK"): response = Response() response._content = content.encode() response.status_code = status_code diff --git a/tests/unit/entity.py b/tests/unit/entity.py index 8f1295e..69faeda 100644 --- a/tests/unit/entity.py +++ b/tests/unit/entity.py @@ -13,25 +13,25 @@ def __init__(self, *args, **kwargs): @property def base_url(self): - return 'https://{}:{}/api/{}/{}'.format(self.host, self.port, self.version, self.endpoint_name) + return "https://{}:{}/api/{}/{}".format(self.host, self.port, self.version, self.endpoint_name) def list(self, mock_request): mock_request.return_value = self.mock_response('{"status": "success", "data": []}') self.assertEqual(self.endpoints.list(), []) - self.assertEqual(mock_request.call_args[1]['method'], 'get') + self.assertEqual(mock_request.call_args[1]["method"], "get") def get(self, mock_request): mock_request.return_value = self.mock_response('{"status": "success", "data": {}}') - self.assertEqual(self.endpoints.get('28FMvD5knJZZx452H'), {}) - expected_url = '{}/28FMvD5knJZZx452H'.format(self.base_url, self.port) - self.assertEqual(mock_request.call_args[1]['url'], expected_url) + self.assertEqual(self.endpoints.get("28FMvD5knJZZx452H"), {}) + expected_url = "{}/28FMvD5knJZZx452H".format(self.base_url) + self.assertEqual(mock_request.call_args[1]["url"], expected_url) def create(self, mock_request): mock_request.return_value = self.mock_response('{"status": "success", "data": {}}') self.endpoints.create({}) - self.assertEqual(mock_request.call_args[1]['headers']['Content-Type'], 'application/json') + self.assertEqual(mock_request.call_args[1]["headers"]["Content-Type"], "application/json") def delete(self, mock_request): mock_request.return_value = self.mock_response('{"status": "success", "data": {}}') - self.assertEqual(self.endpoints.delete('28FMvD5knJZZx452H'), {}) - self.assertEqual(mock_request.call_args[1]['method'], 'delete') + self.assertEqual(self.endpoints.delete("28FMvD5knJZZx452H"), {}) + self.assertEqual(mock_request.call_args[1]["method"], "delete") diff --git a/tests/unit/test_bank_materials.py b/tests/unit/test_bank_materials.py index c3ba731..839f772 100644 --- a/tests/unit/test_bank_materials.py +++ b/tests/unit/test_bank_materials.py @@ -13,10 +13,10 @@ def __init__(self, *args, **kwargs): self.endpoint_name = "bank-materials" self.endpoints = BankMaterialEndpoints(self.host, self.port, self.account_id, self.auth_token) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_list(self, mock_request): self.list(mock_request) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_get(self, mock_request): self.get(mock_request) diff --git a/tests/unit/test_bank_workflows.py b/tests/unit/test_bank_workflows.py index 241a08d..39e4cf8 100644 --- a/tests/unit/test_bank_workflows.py +++ b/tests/unit/test_bank_workflows.py @@ -13,10 +13,10 @@ def __init__(self, *args, **kwargs): self.endpoint_name = "bank-workflows" self.endpoints = BankWorkflowEndpoints(self.host, self.port, self.account_id, self.auth_token) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_list(self, mock_request): self.list(mock_request) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_get(self, mock_request): self.get(mock_request) diff --git a/tests/unit/test_httpBase.py b/tests/unit/test_httpBase.py index bba3326..9446f7e 100644 --- a/tests/unit/test_httpBase.py +++ b/tests/unit/test_httpBase.py @@ -13,20 +13,20 @@ def __init__(self, *args, **kwargs): super(HTTPBaseUnitTest, self).__init__(*args, **kwargs) def test_preamble_secure(self): - conn = Connection(self.host, self.port, version='2018-10-1', secure=True) - self.assertEqual(conn.preamble, 'https://{}:{}/api/2018-10-1/'.format(self.host, self.port)) + conn = Connection(self.host, self.port, version="2018-10-1", secure=True) + self.assertEqual(conn.preamble, "https://{}:{}/api/2018-10-1/".format(self.host, self.port)) def test_preamble_unsecure(self): - conn = Connection(self.host, self.port, version='2018-10-1', secure=False) - self.assertEqual(conn.preamble, 'http://{}:{}/api/2018-10-1/'.format(self.host, self.port)) + conn = Connection(self.host, self.port, version="2018-10-1", secure=False) + self.assertEqual(conn.preamble, "http://{}:{}/api/2018-10-1/".format(self.host, self.port)) def test_preamble_version(self): - conn = Connection(self.host, self.port, version='2018-10-2', secure=True) - self.assertEqual(conn.preamble, 'https://{}:{}/api/2018-10-2/'.format(self.host, self.port)) + conn = Connection(self.host, self.port, version="2018-10-2", secure=True) + self.assertEqual(conn.preamble, "https://{}:{}/api/2018-10-2/".format(self.host, self.port)) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_raise_http_error(self, mock_request): - mock_request.return_value = self.mock_response('', 401, reason='Unauthorized') + mock_request.return_value = self.mock_response("", 401, reason="Unauthorized") with self.assertRaises(HTTPError): - conn = Connection(self.host, self.port, version='2018-10-1', secure=True) - conn.request('POST', 'login', data={'username': '', 'password': ''}) + conn = Connection(self.host, self.port, version="2018-10-1", secure=True) + conn.request("POST", "login", data={"username": "", "password": ""}) diff --git a/tests/unit/test_jobs.py b/tests/unit/test_jobs.py index 2b3e534..cdc2c25 100644 --- a/tests/unit/test_jobs.py +++ b/tests/unit/test_jobs.py @@ -14,18 +14,18 @@ def __init__(self, *args, **kwargs): self.endpoint_name = "jobs" self.endpoints = JobEndpoints(self.host, self.port, self.account_id, self.auth_token) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_list(self, mock_request): self.list(mock_request) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_get(self, mock_request): self.get(mock_request) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_create(self, mock_request): self.create(mock_request) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_delete(self, mock_request): self.create(mock_request) diff --git a/tests/unit/test_login.py b/tests/unit/test_login.py index 0d1bccc..d33cbc9 100644 --- a/tests/unit/test_login.py +++ b/tests/unit/test_login.py @@ -11,17 +11,17 @@ class EndpointLoginUnitTest(EndpointBaseUnitTest): def __init__(self, *args, **kwargs): super(EndpointLoginUnitTest, self).__init__(*args, **kwargs) - self.username = 'test' - self.password = 'test' + self.username = "test" + self.password = "test" self.login_endpoint = LoginEndpoint(self.host, self.port, self.username, self.password) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_login(self, mock_request): - mock_request.return_value = self.mock_response(self.get_content('login.json')) + mock_request.return_value = self.mock_response(self.get_content("login.json")) expected_result = { - 'X-Account-Id': 'ubxMkAyx37Rjn8qK9', - 'X-Auth-Token': 'XihOnUA8EqytSui1icz6fYhsJ2tUsJGGTlV03upYPSF' + "X-Account-Id": "ubxMkAyx37Rjn8qK9", + "X-Auth-Token": "XihOnUA8EqytSui1icz6fYhsJ2tUsJGGTlV03upYPSF", } self.assertEqual(self.login_endpoint.login(), expected_result) - self.assertEqual(mock_request.call_args[1]['data']['username'], self.username) - self.assertEqual(mock_request.call_args[1]['data']['password'], self.password) + self.assertEqual(mock_request.call_args[1]["data"]["username"], self.username) + self.assertEqual(mock_request.call_args[1]["data"]["password"], self.password) diff --git a/tests/unit/test_logout.py b/tests/unit/test_logout.py index 45611d9..62e9144 100644 --- a/tests/unit/test_logout.py +++ b/tests/unit/test_logout.py @@ -13,9 +13,9 @@ def __init__(self, *args, **kwargs): super(EndpointLogoutUnitTest, self).__init__(*args, **kwargs) self.logout_endpoint = LogoutEndpoint(self.host, self.port, self.account_id, self.auth_token) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_logout(self, mock_request): - mock_request.return_value = self.mock_response(self.get_content('logout.json')) + mock_request.return_value = self.mock_response(self.get_content("logout.json")) self.assertEqual(self.logout_endpoint.logout(), {"message": "You are successfully logged out"}) - self.assertEqual(mock_request.call_args[1]['headers']['X-Account-Id'], self.account_id) - self.assertEqual(mock_request.call_args[1]['headers']['X-Auth-Token'], self.auth_token) + self.assertEqual(mock_request.call_args[1]["headers"]["X-Account-Id"], self.account_id) + self.assertEqual(mock_request.call_args[1]["headers"]["X-Auth-Token"], self.auth_token) diff --git a/tests/unit/test_materials.py b/tests/unit/test_materials.py index 3c4dcd9..504e7d9 100644 --- a/tests/unit/test_materials.py +++ b/tests/unit/test_materials.py @@ -14,18 +14,18 @@ def __init__(self, *args, **kwargs): self.endpoint_name = "materials" self.endpoints = MaterialEndpoints(self.host, self.port, self.account_id, self.auth_token) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_list(self, mock_request): self.list(mock_request) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_get(self, mock_request): self.get(mock_request) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_create(self, mock_request): self.create(mock_request) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_delete(self, mock_request): self.create(mock_request) diff --git a/tests/unit/test_refined_properties.py b/tests/unit/test_refined_properties.py index ca7f2fd..d65a543 100644 --- a/tests/unit/test_refined_properties.py +++ b/tests/unit/test_refined_properties.py @@ -13,10 +13,10 @@ def __init__(self, *args, **kwargs): self.endpoint_name = "refined-properties" self.endpoints = RefinedPropertiesEndpoints(self.host, self.port, self.account_id, self.auth_token) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_list(self, mock_request): self.list(mock_request) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_get(self, mock_request): self.get(mock_request) diff --git a/tests/unit/test_workflows.py b/tests/unit/test_workflows.py index ac23202..0a0d35d 100644 --- a/tests/unit/test_workflows.py +++ b/tests/unit/test_workflows.py @@ -14,18 +14,18 @@ def __init__(self, *args, **kwargs): self.endpoint_name = "workflows" self.endpoints = WorkflowEndpoints(self.host, self.port, self.account_id, self.auth_token) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_list(self, mock_request): self.list(mock_request) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_get(self, mock_request): self.get(mock_request) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_create(self, mock_request): self.create(mock_request) - @mock.patch('requests.sessions.Session.request') + @mock.patch("requests.sessions.Session.request") def test_delete(self, mock_request): self.delete(mock_request) From 26bec5de42b4e87a22f31bc64edbd5c6c23c6425 Mon Sep 17 00:00:00 2001 From: Kevin Chu Date: Thu, 15 Jun 2023 18:44:57 -0700 Subject: [PATCH 2/2] ci: add lint to actions --- .github/workflows/cicd.yml | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 21045d5..1fa7732 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -8,6 +8,31 @@ concurrency: jobs: + run-linter: + runs-on: ubuntu-20.04 + strategy: + matrix: + python-version: [3.8.6] + + steps: + - name: Checkout this repository + uses: actions/checkout@v3 + with: + lfs: true + + - name: Checkout actions repository + uses: actions/checkout@v3 + with: + repository: Exabyte-io/actions + token: ${{ secrets.BOT_GITHUB_TOKEN }} + path: actions + ref: feat/SOF-6640 + + - name: Run ruff linter + uses: ./actions/py/lint + with: + python-version: ${{ matrix.python-version }} + run-tests: runs-on: ubuntu-20.04 strategy: @@ -47,7 +72,7 @@ jobs: publish: - needs: run-tests + needs: [run-linter, run-tests] runs-on: ubuntu-latest if: github.ref_name == 'dev'