From 938ba751f90a3103ff264de3d6c02a7762f2c0ee Mon Sep 17 00:00:00 2001 From: stanleyphu Date: Tue, 7 Nov 2023 12:26:36 -0800 Subject: [PATCH] Fix lint errors --- test/test_live.py | 17 +++++++++-------- warrant/authz.py | 3 ++- warrant/feature.py | 1 + warrant/list_result.py | 1 + warrant/pricing_tier.py | 1 - warrant/query_result.py | 1 + warrant/role.py | 1 + warrant/tenant.py | 5 ++++- warrant/warrant.py | 2 +- warrant/warrant_object.py | 5 +++-- 10 files changed, 23 insertions(+), 14 deletions(-) diff --git a/test/test_live.py b/test/test_live.py index 7a4d3c3..ef0f7ad 100644 --- a/test/test_live.py +++ b/test/test_live.py @@ -1,6 +1,7 @@ import warrant import unittest + class LiveTest(unittest.TestCase): @classmethod def setUpClass(cls): @@ -686,16 +687,16 @@ def test_batch_create_delete_warrants(self): user_has_permissions = warrant.Authz.check_many( warrant.CheckOp.ALL_OF, [ - {"objectType": permission1.object_type, "objectId": permission1.id, "relation": "member", "subject":{"objectType": new_user.object_type, "objectId": new_user.id}}, - {"objectType": permission2.object_type, "objectId": permission2.id, "relation": "member", "subject":{"objectType": new_user.object_type, "objectId": new_user.id}} + {"objectType": permission1.object_type, "objectId": permission1.id, "relation": "member", "subject": {"objectType": new_user.object_type, "objectId": new_user.id}}, + {"objectType": permission2.object_type, "objectId": permission2.id, "relation": "member", "subject": {"objectType": new_user.object_type, "objectId": new_user.id}} ], opts={"Warrant-Token": "latest"} ) self.assertEqual(user_has_permissions, False) warrants = warrant.Warrant.batch_create([ - {"objectType": permission1.object_type, "objectId": permission1.id, "relation": "member", "subject":{"objectType": new_user.object_type, "objectId": new_user.id}}, - {"objectType": permission2.object_type, "objectId": permission2.id, "relation": "member", "subject":{"objectType": new_user.object_type, "objectId": new_user.id}} + {"objectType": permission1.object_type, "objectId": permission1.id, "relation": "member", "subject": {"objectType": new_user.object_type, "objectId": new_user.id}}, + {"objectType": permission2.object_type, "objectId": permission2.id, "relation": "member", "subject": {"objectType": new_user.object_type, "objectId": new_user.id}} ]) self.assertEqual(len(warrants), 2) @@ -720,16 +721,16 @@ def test_batch_create_delete_warrants(self): user_has_permissions = warrant.Authz.check_many( warrant.CheckOp.ALL_OF, [ - {"objectType": permission1.object_type, "objectId": permission1.id, "relation": "member", "subject":{"objectType": new_user.object_type, "objectId": new_user.id}}, - {"objectType": permission2.object_type, "objectId": permission2.id, "relation": "member", "subject":{"objectType": new_user.object_type, "objectId": new_user.id}} + {"objectType": permission1.object_type, "objectId": permission1.id, "relation": "member", "subject": {"objectType": new_user.object_type, "objectId": new_user.id}}, + {"objectType": permission2.object_type, "objectId": permission2.id, "relation": "member", "subject": {"objectType": new_user.object_type, "objectId": new_user.id}} ], opts={"Warrant-Token": "latest"} ) self.assertEqual(user_has_permissions, True) warrant.Warrant.batch_delete([ - {"objectType": permission1.object_type, "objectId": permission1.id, "relation": "member", "subject":{"objectType": new_user.object_type, "objectId": new_user.id}}, - {"objectType": permission2.object_type, "objectId": permission2.id, "relation": "member", "subject":{"objectType": new_user.object_type, "objectId": new_user.id}} + {"objectType": permission1.object_type, "objectId": permission1.id, "relation": "member", "subject": {"objectType": new_user.object_type, "objectId": new_user.id}}, + {"objectType": permission2.object_type, "objectId": permission2.id, "relation": "member", "subject": {"objectType": new_user.object_type, "objectId": new_user.id}} ]) warrant.WarrantObject.batch_delete([ {"objectType": permission1.object_type, "objectId": permission1.id}, diff --git a/warrant/authz.py b/warrant/authz.py index 6918da0..2b93581 100644 --- a/warrant/authz.py +++ b/warrant/authz.py @@ -3,12 +3,13 @@ from enum import Enum from typing import Any, Dict, List, Optional, Union + class CheckOp(str, Enum): ANY_OF = "anyOf" ALL_OF = "allOf" -class Authz(APIResource): +class Authz(APIResource): @classmethod def check(cls, object_type: str, object_id: str, relation: str, subject, context: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> bool: warrantToCheck = { diff --git a/warrant/feature.py b/warrant/feature.py index 2d8bfa8..6b4ad78 100644 --- a/warrant/feature.py +++ b/warrant/feature.py @@ -1,6 +1,7 @@ from warrant import APIResource, Subject, Warrant, WarrantObject, constants, ListResult from typing import Any, Dict, List, Optional + class Feature(WarrantObject): def __init__(self, id: str = "", meta: Dict[str, Any] = {}) -> None: self.id = id diff --git a/warrant/list_result.py b/warrant/list_result.py index d9cfb54..9058c19 100644 --- a/warrant/list_result.py +++ b/warrant/list_result.py @@ -2,6 +2,7 @@ T = TypeVar('T') + class ListResult(Generic[T]): def __init__(self, results: List[T], prev_cursor: str = "", next_cursor: str = "") -> None: self.results = results diff --git a/warrant/pricing_tier.py b/warrant/pricing_tier.py index 5dca852..fb7d248 100644 --- a/warrant/pricing_tier.py +++ b/warrant/pricing_tier.py @@ -35,7 +35,6 @@ def create(cls, id: str, meta: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) - def delete(cls, id: str, opts: Dict[str, Any] = {}): return WarrantObject.delete("pricing-tier", id, opts=opts) - """ Features """ diff --git a/warrant/query_result.py b/warrant/query_result.py index 1ba981f..3bc282e 100644 --- a/warrant/query_result.py +++ b/warrant/query_result.py @@ -1,6 +1,7 @@ from warrant import Warrant from typing import Any, Dict + class QueryResult: def __init__(self, object_type: str, object_id: str, warrant: Warrant, is_implicit: bool, meta: Dict[str, Any] = {}): self.object_type = object_type diff --git a/warrant/role.py b/warrant/role.py index 1234558..c26e477 100644 --- a/warrant/role.py +++ b/warrant/role.py @@ -1,6 +1,7 @@ from warrant import APIResource, Permission, Subject, Warrant, WarrantObject, constants, ListResult from typing import Any, Dict, List, Optional + class Role(WarrantObject): def __init__(self, id: str = "", meta: Dict[str, Any] = {}) -> None: self.id = id diff --git a/warrant/tenant.py b/warrant/tenant.py index d477196..e566b96 100644 --- a/warrant/tenant.py +++ b/warrant/tenant.py @@ -33,7 +33,10 @@ def create(cls, id: str = "", meta: Dict[str, Any] = {}, opts: Dict[str, Any] = @classmethod def batch_create(cls, tenants: List[Dict[str, Any]], opts: Dict[str, Any] = {}) -> List["Tenant"]: - objects = map(lambda tenant: {"objectType": "tenant", "objectId": tenant['tenantId'], "meta": tenant['meta']} if "meta" in tenant.keys() else {"objectType": "tenant", "objectId": tenant['tenantId']}, tenants) + objects = map( + lambda tenant: {"objectType": "tenant", "objectId": tenant['tenantId'], "meta": tenant['meta']} if "meta" in tenant.keys() else {"objectType": "tenant", "objectId": tenant['tenantId']}, + tenants + ) created_objects = WarrantObject.batch_create(list(objects), opts) created_tenants = map(lambda warrant_obj: Tenant(warrant_obj.object_id, warrant_obj.meta), created_objects) return list(created_tenants) diff --git a/warrant/warrant.py b/warrant/warrant.py index 2bf5a03..43bbaaa 100644 --- a/warrant/warrant.py +++ b/warrant/warrant.py @@ -1,6 +1,7 @@ from warrant import APIResource, WarrantException, ListResult from typing import Any, Dict, List, Optional + class Subject(object): def __init__(self, object_type, object_id, relation=""): self.object_type = object_type @@ -38,7 +39,6 @@ def from_json(obj): return obj - class Warrant(APIResource): object_type: str object_id: str diff --git a/warrant/warrant_object.py b/warrant/warrant_object.py index 8beda87..200a27d 100644 --- a/warrant/warrant_object.py +++ b/warrant/warrant_object.py @@ -1,6 +1,7 @@ from warrant import APIResource, ListResult from typing import Any, Dict, List, Optional + class WarrantObject(APIResource): def __init__(self, object_type: str, object_id: str, meta: Dict[str, Any] = {}) -> None: self.object_type = object_type @@ -14,9 +15,9 @@ def __init__(self, object_type: str, object_id: str, meta: Dict[str, Any] = {}) @classmethod def list(cls, params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> ListResult["WarrantObject"]: if params is None: - params={} + params = {} if opts is None: - opts={} + opts = {} list_result = cls._get(uri="/v2/objects", params=params, opts=opts, object_hook=WarrantObject.from_json) if "prevCursor" in list_result and "nextCursor" in list_result: return ListResult[WarrantObject](list_result['results'], list_result['prevCursor'], list_result['nextCursor'])