Skip to content

Commit 7096761

Browse files
authored
Rename WarrantObject to Object (#17)
1 parent cb7d51c commit 7096761

File tree

9 files changed

+76
-76
lines changed

9 files changed

+76
-76
lines changed

test/test_live.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -221,46 +221,46 @@ def test_crud_features(self):
221221
self.assertEqual(len(features_list.results), 0)
222222

223223
def test_crud_objects(self):
224-
object1 = warrant.WarrantObject.create("document")
224+
object1 = warrant.Object.create("document")
225225
self.assertEqual(object1.object_type, "document")
226226
self.assertIsNotNone(object1.object_id)
227227
self.assertEqual(object1.meta, {})
228228

229-
object2 = warrant.WarrantObject.create("folder", "planning")
230-
refetched_object = warrant.WarrantObject.get(object2.object_type, object2.object_id, {"Warrant-Token": "latest"})
229+
object2 = warrant.Object.create("folder", "planning")
230+
refetched_object = warrant.Object.get(object2.object_type, object2.object_id, {"Warrant-Token": "latest"})
231231
self.assertEqual(object2.object_type, refetched_object.object_type)
232232
self.assertEqual(object2.object_id, refetched_object.object_id)
233233
self.assertEqual(object2.meta, refetched_object.meta)
234234

235235
object2.update({"description": "Second document"})
236-
refetched_object = warrant.WarrantObject.get(object2.object_type, object2.object_id, {"Warrant-Token": "latest"})
236+
refetched_object = warrant.Object.get(object2.object_type, object2.object_id, {"Warrant-Token": "latest"})
237237
self.assertEqual(refetched_object.object_type, "folder")
238238
self.assertEqual(refetched_object.object_id, "planning")
239239
self.assertEqual(refetched_object.meta, {"description": "Second document"})
240240

241-
objects_list = warrant.WarrantObject.list({"sortBy": "createdAt", "limit": 10}, {"Warrant-Token": "latest"})
241+
objects_list = warrant.Object.list({"sortBy": "createdAt", "limit": 10}, {"Warrant-Token": "latest"})
242242
self.assertEqual(len(objects_list.results), 2)
243243
self.assertEqual(objects_list.results[0].object_type, object1.object_type)
244244
self.assertEqual(objects_list.results[0].object_id, object1.object_id)
245245
self.assertEqual(objects_list.results[1].object_type, object2.object_type)
246246
self.assertEqual(objects_list.results[1].object_id, object2.object_id)
247247

248-
warrant_token = warrant.WarrantObject.delete(object1.object_type, object1.object_id)
248+
warrant_token = warrant.Object.delete(object1.object_type, object1.object_id)
249249
self.assertIsNotNone(warrant_token)
250-
warrant_token = warrant.WarrantObject.delete(object2.object_type, object2.object_id)
250+
warrant_token = warrant.Object.delete(object2.object_type, object2.object_id)
251251
self.assertIsNotNone(warrant_token)
252-
objects_list = warrant.WarrantObject.list({"sortBy": "createdAt", "limit": 10}, {"Warrant-Token": "latest"})
252+
objects_list = warrant.Object.list({"sortBy": "createdAt", "limit": 10}, {"Warrant-Token": "latest"})
253253
self.assertEqual(len(objects_list.results), 0)
254254

255255
def test_batch_create_delete_objects(self):
256-
objects = warrant.WarrantObject.batch_create([
256+
objects = warrant.Object.batch_create([
257257
{"objectType": "document", "objectId": "document-a"},
258258
{"objectType": "document", "objectId": "document-b"},
259259
{"objectType": "folder", "objectId": "resources", "meta": {"description": "Helpful documents"}}
260260
])
261261
self.assertEqual(len(objects), 3)
262262

263-
objects_list = warrant.WarrantObject.list({"limit": 10}, {"Warrant-Token": "latest"})
263+
objects_list = warrant.Object.list({"limit": 10}, {"Warrant-Token": "latest"})
264264
self.assertEqual(len(objects_list.results), 3)
265265
self.assertEqual(objects_list.results[0].object_type, "document")
266266
self.assertEqual(objects_list.results[0].object_id, "document-a")
@@ -270,12 +270,12 @@ def test_batch_create_delete_objects(self):
270270
self.assertEqual(objects_list.results[2].object_id, "resources")
271271
self.assertEqual(objects_list.results[2].meta, {"description": "Helpful documents"})
272272

273-
warrant.WarrantObject.batch_delete([
273+
warrant.Object.batch_delete([
274274
{"objectType": "document", "objectId": "document-a"},
275275
{"objectType": "document", "objectId": "document-b"},
276276
{"objectType": "folder", "objectId": "resources", "meta": {"description": "Helpful documents"}}
277277
])
278-
objects_list = warrant.WarrantObject.list({"limit": 10}, {"Warrant-Token": "latest"})
278+
objects_list = warrant.Object.list({"limit": 10}, {"Warrant-Token": "latest"})
279279
self.assertEqual(len(objects_list.results), 0)
280280

281281
def test_multitenancy_example(self):
@@ -732,7 +732,7 @@ def test_batch_create_delete_warrants(self):
732732
{"objectType": permission1.object_type, "objectId": permission1.id, "relation": "member", "subject": {"objectType": new_user.object_type, "objectId": new_user.id}},
733733
{"objectType": permission2.object_type, "objectId": permission2.id, "relation": "member", "subject": {"objectType": new_user.object_type, "objectId": new_user.id}}
734734
])
735-
warrant.WarrantObject.batch_delete([
735+
warrant.Object.batch_delete([
736736
{"objectType": permission1.object_type, "objectId": permission1.id},
737737
{"objectType": permission2.object_type, "objectId": permission2.id},
738738
{"objectType": new_user.object_type, "objectId": new_user.id},

warrant/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from warrant.api_resource import APIResource, WarrantException
22
from warrant.list_result import ListResult
3-
from warrant.warrant_object import WarrantObject
3+
from warrant.object import Object
44
from warrant.warrant import Warrant, Subject, QueryResult
55
from warrant.authz import Authz, CheckOp
66

warrant/feature.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
from warrant import APIResource, Subject, Warrant, WarrantObject, constants, ListResult
1+
from warrant import APIResource, Subject, Warrant, Object, constants, ListResult
22
from typing import Any, Dict, List, Optional
33

44

5-
class Feature(WarrantObject):
5+
class Feature(Object):
66
def __init__(self, id: str = "", meta: Dict[str, Any] = {}) -> None:
77
self.id = id
8-
WarrantObject.__init__(self, "feature", id, meta)
8+
Object.__init__(self, "feature", id, meta)
99

1010
@classmethod
1111
def list(cls, list_params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}):
1212
list_params['objectType'] = 'feature'
13-
list_result = WarrantObject.list(list_params, opts=opts)
13+
list_result = Object.list(list_params, opts=opts)
1414
features = map(lambda warrant_obj: Feature(warrant_obj.object_id, warrant_obj.meta), list_result.results)
1515
if list_result.prev_cursor != "" and list_result.next_cursor != "":
1616
return ListResult[Feature](list(features), list_result.prev_cursor, list_result.next_cursor)
@@ -23,17 +23,17 @@ def list(cls, list_params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}):
2323

2424
@classmethod
2525
def get(cls, id: str, opts: Dict[str, Any] = {}) -> "Feature":
26-
warrant_obj = WarrantObject.get("feature", id, opts=opts)
26+
warrant_obj = Object.get("feature", id, opts=opts)
2727
return Feature.from_warrant_obj(warrant_obj)
2828

2929
@classmethod
3030
def create(cls, id: str, meta: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> "Feature":
31-
warrant_obj = WarrantObject.create("feature", id, meta, opts=opts)
31+
warrant_obj = Object.create("feature", id, meta, opts=opts)
3232
return Feature.from_warrant_obj(warrant_obj)
3333

3434
@classmethod
3535
def delete(cls, id: str, opts: Dict[str, Any] = {}) -> Optional[str]:
36-
return WarrantObject.delete("feature", id, opts=opts)
36+
return Object.delete("feature", id, opts=opts)
3737

3838
"""
3939
Pricing tiers

warrant/warrant_object.py renamed to warrant/object.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,52 @@
22
from typing import Any, Dict, List, Optional
33

44

5-
class WarrantObject(APIResource):
5+
class Object(APIResource):
66
def __init__(self, object_type: str, object_id: str, meta: Dict[str, Any] = {}) -> None:
77
self.object_type = object_type
88
self.object_id = object_id
99
self.meta = meta
1010

1111
@classmethod
12-
def list(cls, params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> ListResult["WarrantObject"]:
12+
def list(cls, params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> ListResult["Object"]:
1313
if params is None:
1414
params = {}
1515
if opts is None:
1616
opts = {}
17-
list_result = cls._get(uri="/v2/objects", params=params, opts=opts, object_hook=WarrantObject.from_json)
17+
list_result = cls._get(uri="/v2/objects", params=params, opts=opts, object_hook=Object.from_json)
1818
if "prevCursor" in list_result and "nextCursor" in list_result:
19-
return ListResult[WarrantObject](list_result['results'], list_result['prevCursor'], list_result['nextCursor'])
19+
return ListResult[Object](list_result['results'], list_result['prevCursor'], list_result['nextCursor'])
2020
elif "prevCursor" in list_result:
21-
return ListResult[WarrantObject](list_result['results'], list_result['prevCursor'])
21+
return ListResult[Object](list_result['results'], list_result['prevCursor'])
2222
elif "nextCursor" in list_result:
23-
return ListResult[WarrantObject](list_result['results'], next_cursor=list_result['nextCursor'])
23+
return ListResult[Object](list_result['results'], next_cursor=list_result['nextCursor'])
2424
else:
25-
return ListResult[WarrantObject](list_result['results'])
25+
return ListResult[Object](list_result['results'])
2626

2727
@classmethod
28-
def create(cls, object_type: str, object_id: str = "", meta: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> "WarrantObject":
28+
def create(cls, object_type: str, object_id: str = "", meta: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> "Object":
2929
payload: Dict[str, Any] = {
3030
"objectType": object_type
3131
}
3232
if object_id is not None and object_id != "":
3333
payload["objectId"] = object_id
3434
if meta != {}:
3535
payload["meta"] = meta
36-
return cls._post(uri="/v2/objects", json_payload=payload, opts=opts, object_hook=WarrantObject.from_json)
36+
return cls._post(uri="/v2/objects", json_payload=payload, opts=opts, object_hook=Object.from_json)
3737

3838
@classmethod
39-
def batch_create(cls, objects: List[Dict[str, Any]], opts: Dict[str, Any] = {}) -> List["WarrantObject"]:
40-
return cls._post(uri="/v2/objects", json_payload=objects, opts=opts, object_hook=WarrantObject.from_json)
39+
def batch_create(cls, objects: List[Dict[str, Any]], opts: Dict[str, Any] = {}) -> List["Object"]:
40+
return cls._post(uri="/v2/objects", json_payload=objects, opts=opts, object_hook=Object.from_json)
4141

4242
@classmethod
43-
def get(cls, object_type: str, object_id: str, opts: Dict[str, Any] = {}) -> "WarrantObject":
44-
return cls._get("/v2/objects/"+object_type+"/"+object_id, params={}, opts=opts, object_hook=WarrantObject.from_json)
43+
def get(cls, object_type: str, object_id: str, opts: Dict[str, Any] = {}) -> "Object":
44+
return cls._get("/v2/objects/"+object_type+"/"+object_id, params={}, opts=opts, object_hook=Object.from_json)
4545

4646
def update(self, meta: Dict[str, Any], opts: Dict[str, Any] = {}) -> None:
4747
payload = {
4848
"meta": meta
4949
}
50-
updated_obj = self._put(uri="/v2/objects/"+self.object_type+"/"+self.object_id, json_payload=payload, opts=opts, object_hook=WarrantObject.from_json)
50+
updated_obj = self._put(uri="/v2/objects/"+self.object_type+"/"+self.object_id, json_payload=payload, opts=opts, object_hook=Object.from_json)
5151
self.meta = updated_obj.meta
5252

5353
@classmethod
@@ -65,8 +65,8 @@ def batch_delete(cls, objects: List[Dict[str, Any]], opts: Dict[str, Any] = {})
6565
def from_json(obj):
6666
if "objectType" in obj and "objectId" in obj:
6767
if "meta" in obj:
68-
return WarrantObject(obj["objectType"], obj["objectId"], obj["meta"])
68+
return Object(obj["objectType"], obj["objectId"], obj["meta"])
6969
else:
70-
return WarrantObject(obj["objectType"], obj["objectId"])
70+
return Object(obj["objectType"], obj["objectId"])
7171
else:
7272
return obj

warrant/permission.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
from warrant import APIResource, Subject, Warrant, WarrantObject, constants, ListResult
1+
from warrant import APIResource, Subject, Warrant, Object, constants, ListResult
22
from typing import Any, Dict, List, Optional
33

44

5-
class Permission(WarrantObject):
5+
class Permission(Object):
66
def __init__(self, id: str = "", meta: Dict[str, Any] = {}) -> None:
77
self.id = id
8-
WarrantObject.__init__(self, "permission", id, meta)
8+
Object.__init__(self, "permission", id, meta)
99

1010
@classmethod
1111
def list(cls, list_params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}):
1212
list_params['objectType'] = 'permission'
13-
list_result = WarrantObject.list(list_params, opts=opts)
13+
list_result = Object.list(list_params, opts=opts)
1414
permissions = map(lambda warrant_obj: Permission(warrant_obj.object_id, warrant_obj.meta), list_result.results)
1515
if list_result.prev_cursor != "" and list_result.next_cursor != "":
1616
return ListResult[Permission](list(permissions), list_result.prev_cursor, list_result.next_cursor)
@@ -23,17 +23,17 @@ def list(cls, list_params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}):
2323

2424
@classmethod
2525
def get(cls, id: str, opts: Dict[str, Any] = {}) -> "Permission":
26-
warrant_obj = WarrantObject.get("permission", id, opts=opts)
26+
warrant_obj = Object.get("permission", id, opts=opts)
2727
return Permission.from_warrant_obj(warrant_obj)
2828

2929
@classmethod
3030
def create(cls, id: str, meta={}, opts: Dict[str, Any] = {}) -> "Permission":
31-
warrant_obj = WarrantObject.create("permission", id, meta, opts=opts)
31+
warrant_obj = Object.create("permission", id, meta, opts=opts)
3232
return Permission.from_warrant_obj(warrant_obj)
3333

3434
@classmethod
3535
def delete(cls, id: str, opts: Dict[str, Any] = {}) -> Optional[str]:
36-
return WarrantObject.delete("permission", id, opts=opts)
36+
return Object.delete("permission", id, opts=opts)
3737

3838
"""
3939
Users

warrant/pricing_tier.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
from warrant import APIResource, Feature, Subject, Warrant, WarrantObject, constants, ListResult
1+
from warrant import APIResource, Feature, Subject, Warrant, Object, constants, ListResult
22
from typing import Any, Dict, List, Optional
33

44

5-
class PricingTier(WarrantObject):
5+
class PricingTier(Object):
66
def __init__(self, id: str = "", meta: Dict[str, Any] = {}) -> None:
77
self.id = id
8-
WarrantObject.__init__(self, "pricing-tier", id, meta)
8+
Object.__init__(self, "pricing-tier", id, meta)
99

1010
@classmethod
1111
def list(cls, list_params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}):
1212
list_params['objectType'] = 'pricing-tier'
13-
list_result = WarrantObject.list(list_params, opts=opts)
13+
list_result = Object.list(list_params, opts=opts)
1414
pricing_tiers = map(lambda warrant_obj: PricingTier(warrant_obj.object_id, warrant_obj.meta), list_result.results)
1515
if list_result.prev_cursor != "" and list_result.next_cursor != "":
1616
return ListResult[PricingTier](list(pricing_tiers), list_result.prev_cursor, list_result.next_cursor)
@@ -23,17 +23,17 @@ def list(cls, list_params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}):
2323

2424
@classmethod
2525
def get(cls, id: str, opts: Dict[str, Any] = {}) -> "PricingTier":
26-
warrant_obj = WarrantObject.get("pricing-tier", id, opts=opts)
26+
warrant_obj = Object.get("pricing-tier", id, opts=opts)
2727
return PricingTier.from_warrant_obj(warrant_obj)
2828

2929
@classmethod
3030
def create(cls, id: str, meta: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> "PricingTier":
31-
warrant_obj = WarrantObject.create("pricing-tier", id, meta, opts=opts)
31+
warrant_obj = Object.create("pricing-tier", id, meta, opts=opts)
3232
return PricingTier.from_warrant_obj(warrant_obj)
3333

3434
@classmethod
3535
def delete(cls, id: str, opts: Dict[str, Any] = {}):
36-
return WarrantObject.delete("pricing-tier", id, opts=opts)
36+
return Object.delete("pricing-tier", id, opts=opts)
3737

3838
"""
3939
Features

warrant/role.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
from warrant import APIResource, Permission, Subject, Warrant, WarrantObject, constants, ListResult
1+
from warrant import APIResource, Permission, Subject, Warrant, Object, constants, ListResult
22
from typing import Any, Dict, List, Optional
33

44

5-
class Role(WarrantObject):
5+
class Role(Object):
66
def __init__(self, id: str = "", meta: Dict[str, Any] = {}) -> None:
77
self.id = id
8-
WarrantObject.__init__(self, "role", id, meta)
8+
Object.__init__(self, "role", id, meta)
99

1010
@classmethod
1111
def list(cls, list_params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}):
1212
list_params['objectType'] = 'role'
13-
list_result = WarrantObject.list(list_params, opts=opts)
13+
list_result = Object.list(list_params, opts=opts)
1414
roles = map(lambda warrant_obj: Role(warrant_obj.object_id, warrant_obj.meta), list_result.results)
1515
if list_result.prev_cursor != "" and list_result.next_cursor != "":
1616
return ListResult[Role](list(roles), list_result.prev_cursor, list_result.next_cursor)
@@ -23,17 +23,17 @@ def list(cls, list_params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}):
2323

2424
@classmethod
2525
def get(cls, id: str, opts: Dict[str, Any] = {}) -> "Role":
26-
warrant_obj = WarrantObject.get("role", id, opts=opts)
26+
warrant_obj = Object.get("role", id, opts=opts)
2727
return Role.from_warrant_obj(warrant_obj)
2828

2929
@classmethod
3030
def create(cls, id: str = "", meta: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> "Role":
31-
warrant_obj = WarrantObject.create("role", id, meta, opts=opts)
31+
warrant_obj = Object.create("role", id, meta, opts=opts)
3232
return Role.from_warrant_obj(warrant_obj)
3333

3434
@classmethod
3535
def delete(cls, id: str, opts: Dict[str, Any] = {}) -> Optional[str]:
36-
return WarrantObject.delete("role", id, opts=opts)
36+
return Object.delete("role", id, opts=opts)
3737

3838
"""
3939
Users

0 commit comments

Comments
 (0)