Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions archivist/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,19 @@ def __init__(self, archivist: "type_helper.Archivist"):
"keywords": ("display_name",),
}
self["SUBJECTS_CREATE"] = {
"action": archivist.subjects.create,
"action": archivist.subjects.create_from_data,
"delete": archivist.subjects.delete,
"keywords": ("display_name", "wallet_pub_keys", "tessera_pub_keys"),
"set_subject_label": True,
}
self["SUBJECTS_CREATE_FROM_B64"] = {
"action": archivist.subjects.create_from_b64,
"delete": archivist.subjects.delete,
"set_subject_label": True,
}
self["SUBJECTS_DELETE"] = {
"action": archivist.subjects.delete,
"use_subject_label": "add_arg_identity",
}
self["SUBJECTS_LIST"] = {
"action": archivist.subjects.list,
"keywords": ("display_name",),
Expand All @@ -175,8 +178,8 @@ def __init__(self, archivist: "type_helper.Archivist"):
"action": archivist.subjects.update,
"keywords": (
"display_name",
"wallet_pub_keys",
"tessera_pub_keys",
"wallet_pub_key",
"tessera_pub_key",
),
"use_subject_label": "add_arg_identity",
}
Expand Down
34 changes: 17 additions & 17 deletions archivist/subjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ def __str__(self) -> str:
return f"SubjectsClient({self._archivist.url})"

def create(
self, display_name: str, wallet_pub_keys: List, tessera_pub_keys: List
self, display_name: str, wallet_pub_key: List, tessera_pub_key: List
) -> Subject:
"""Create subject

Creates subject with defined attributes.

Args:
display_name (str): display name of subject.
wallet_pub_keys (list): wallet public keys
tessera_pub_keys (list): tessera public keys
wallet_pub_key (list): wallet public keys
tessera_pub_key (list): tessera public keys

Returns:
:class:`Subject` instance
Expand All @@ -85,8 +85,8 @@ def create(
return self.create_from_data(
self.__params(
display_name=display_name,
wallet_pub_keys=wallet_pub_keys,
tessera_pub_keys=tessera_pub_keys,
wallet_pub_key=wallet_pub_key,
tessera_pub_key=tessera_pub_key,
),
)

Expand Down Expand Up @@ -172,8 +172,8 @@ def update(
identity: str,
*,
display_name: str = None,
wallet_pub_keys: Optional[List[str]] = None,
tessera_pub_keys: Optional[List[str]] = None,
wallet_pub_key: Optional[List[str]] = None,
tessera_pub_key: Optional[List[str]] = None,
) -> Subject:
"""Update Subject

Expand All @@ -182,8 +182,8 @@ def update(
Args:
identity (str): subjects identity e.g. subjects/xxxxxxxxxxxxxxxxxxxxxxx
display_name (str): display name of subject.
wallet_pub_keys (list): wallet public keys
tessera_pub_keys (list): tessera public keys
wallet_pub_key (list): wallet public keys
tessera_pub_key (list): tessera public keys

Returns:
:class:`Subject` instance
Expand All @@ -194,8 +194,8 @@ def update(
f"{self._subpath}/{identity}",
self.__params(
display_name=display_name,
wallet_pub_keys=wallet_pub_keys,
tessera_pub_keys=tessera_pub_keys,
wallet_pub_key=wallet_pub_key,
tessera_pub_key=tessera_pub_key,
),
)
)
Expand All @@ -218,20 +218,20 @@ def __params(
self,
*,
display_name: Optional[str] = None,
wallet_pub_keys: Optional[List[str]] = None,
tessera_pub_keys: Optional[List[str]] = None,
wallet_pub_key: Optional[List[str]] = None,
tessera_pub_key: Optional[List[str]] = None,
) -> Dict:

params = {}

if display_name is not None:
params["display_name"] = display_name

if wallet_pub_keys is not None:
params["wallet_pub_key"] = wallet_pub_keys
if wallet_pub_key is not None:
params["wallet_pub_key"] = wallet_pub_key

if tessera_pub_keys is not None:
params["tessera_pub_key"] = tessera_pub_keys
if tessera_pub_key is not None:
params["tessera_pub_key"] = tessera_pub_key

return _deepmerge(self._archivist.fixtures.get(SUBJECTS_LABEL), params)

Expand Down
1 change: 1 addition & 0 deletions docs/runner/components/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Story Runner Components
subjects_count
subjects_create
subjects_create_b64
subjects_delete
subjects_list
subjects_read
subjects_update
Expand Down
4 changes: 2 additions & 2 deletions docs/runner/components/subjects_create.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ not be accessible to later actions in the story.
print_response: true
subject_label: A subject
display_name: A subject
wallet_pub_keys:
wallet_pub_key:
- wallet_pub_key1
tessera_pub_keys:
tessera_pub_key:
- tessera_pub_key2
20 changes: 20 additions & 0 deletions docs/runner/components/subjects_delete.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. _subjects_delete_yamlref:

Subjects Delete Story Runner YAML
.........................................

Delete the specified subject.

:code:`subject_label` is required.

The :code:`print_response` setting should be specified as :code:`True` in order to see the results.

.. code-block:: yaml

---
steps:
- step:
action: SUBJECTS_DELETE
description: Dele subject
print_response: true
subject_label: A subject
8 changes: 4 additions & 4 deletions docs/runner/components/subjects_update.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Subjects Update Story Runner YAML
.........................................

'subject_label' is required.
:code:`subject_label` is required.

'display_name', wallet_pub_keys' and 'tessera_pub_keys' are
:code:`display_name`, :code:`wallet_pub_key` and :code:`tessera_pub_key` are
optional but at least one must be specified.

.. code-block:: yaml
Expand All @@ -18,9 +18,9 @@ optional but at least one must be specified.
print_response: true
subject_label: A subject
display_name: A subject
wallet_pub_keys:
wallet_pub_key:
- wallet_pub_key1
- wallet_pub_key2
tessera_pub_keys:
tessera_pub_key:
- tessera_pub_key1
- tessera_pub_key2
18 changes: 9 additions & 9 deletions functests/execsubjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
LOGGER = logger.LOGGER

DISPLAY_NAME = "Subject display name"
WALLET_PUB_KEYS = [
WALLET_PUB_KEY = [
(
"04c1173bf7844bf1c607b79c18db091b9558ffe581bf132b8cf3b37657230fa321a088"
"0b54a79a88b28bc710ede6dcf3d8272c5210bfd41ea83188e385d12c189c"
)
]
WALLET_ADDRESSES = ["0xAab979509B595084F5C113c5622Ca9A7844C58B5"]

TESSERA_PUB_KEYS = ["efdg9J0QhSB2g4IxKcaXgJmNKbzpxs03FFYIiYYuekk="]
TESSERA_PUB_KEY = ["efdg9J0QhSB2g4IxKcaXgJmNKbzpxs03FFYIiYYuekk="]

SUBJECT_STRING = (
"eyJpZGVudGl0eSI6ICJzdWJqZWN0cy8wMDAwMDAwMC0wMDAwLTAwMDAtMDA"
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_subjects_create(self):
Test subject creation
"""
subject = self.arch.subjects.create(
self.display_name, WALLET_PUB_KEYS, TESSERA_PUB_KEYS
self.display_name, WALLET_PUB_KEY, TESSERA_PUB_KEY
)
self.assertEqual(
subject["display_name"],
Expand All @@ -96,12 +96,12 @@ def test_subjects_create_b64(self):
)
self.assertEqual(
subject["wallet_pub_key"],
WALLET_PUB_KEYS,
WALLET_PUB_KEY,
msg="Incorrect wallet_pub_key",
)
self.assertEqual(
subject["tessera_pub_key"],
TESSERA_PUB_KEYS,
TESSERA_PUB_KEY,
msg="Incorrect tessera_pub_key",
)

Expand All @@ -110,7 +110,7 @@ def test_subjects_update(self):
Test subject update
"""
subject = self.arch.subjects.create(
self.display_name, WALLET_PUB_KEYS, TESSERA_PUB_KEYS
self.display_name, WALLET_PUB_KEY, TESSERA_PUB_KEY
)
self.assertEqual(
subject["display_name"],
Expand All @@ -120,16 +120,16 @@ def test_subjects_update(self):
subject = self.arch.subjects.update(
subject["identity"],
display_name=self.display_name,
wallet_pub_keys=WALLET_PUB_KEYS,
tessera_pub_keys=TESSERA_PUB_KEYS,
wallet_pub_key=WALLET_PUB_KEY,
tessera_pub_key=TESSERA_PUB_KEY,
)

def test_subjects_delete(self):
"""
Test subject delete
"""
subject = self.arch.subjects.create(
self.display_name, WALLET_PUB_KEYS, TESSERA_PUB_KEYS
self.display_name, WALLET_PUB_KEY, TESSERA_PUB_KEY
)
self.assertEqual(
subject["display_name"],
Expand Down
18 changes: 15 additions & 3 deletions functests/test_resources/subjects_story.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ steps:
print_response: true
subject_label: A subject
display_name: A subject
wallet_pub_keys:
wallet_pub_key:
- 04c1173bf7844bf1c607b79c18db091b9558ffe581bf132b8cf3b37657230fa321a0880b54a79a88b28bc710ede6dcf3d8272c5210bfd41ea83188e385d12c189c
tessera_pub_keys:
tessera_pub_key:
- efdg9J0QhSB2g4IxKcaXgJmNKbzpxs03FFYIiYYuekk=

- step:
Expand Down Expand Up @@ -51,5 +51,17 @@ steps:
description: Update a subjects entity.
print_response: true
subject_label: A subject
wallet_pub_keys:
wallet_pub_key:
- 04c1173bf7844bf1c607b79c18db091b9558ffe581bf132b8cf3b37657230fa321a0880b54a79a88b28bc710ede6dcf3d8272c5210bfd41ea83188e385d12c189c

- step:
action: SUBJECTS_DELETE
description: Delete subject
print_response: true
subject_label: A subject

- step:
action: SUBJECTS_DELETE
description: Delete subject
print_response: true
subject_label: An imported subject
18 changes: 9 additions & 9 deletions unittests/testsubjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
# pylint: disable=unused-variable

DISPLAY_NAME = "Subject display name"
WALLET_PUB_KEYS = [
WALLET_PUB_KEY = [
(
"04c1173bf7844bf1c607b79c18db091b9558ffe581bf132b8cf3b37657230fa321a088"
"0b54a79a88b28bc710ede6dcf3d8272c5210bfd41ea83188e385d12c189c"
)
]
WALLET_ADDRESSES = ["0xAab979509B595084F5C113c5622Ca9A7844C58B5"]

TESSERA_PUB_KEYS = ["efdg9J0QhSB2g4IxKcaXgJmNKbzpxs03FFYIiYYuekk="]
TESSERA_PUB_KEY = ["efdg9J0QhSB2g4IxKcaXgJmNKbzpxs03FFYIiYYuekk="]

SUBJECT_STRING = (
"eyJpZGVudGl0eSI6ICJzdWJqZWN0cy8wMDAwMDAwMC0wMDAwLTAwMDAtMDA"
Expand All @@ -52,9 +52,9 @@
RESPONSE = {
"identity": IDENTITY,
"display_name": DISPLAY_NAME,
"wallet_pub_key": WALLET_PUB_KEYS,
"wallet_pub_key": WALLET_PUB_KEY,
"wallet_address": WALLET_ADDRESSES,
"tessera_pub_key": TESSERA_PUB_KEYS,
"tessera_pub_key": TESSERA_PUB_KEY,
}
RESPONSE_WITH_PENDING = {
**RESPONSE,
Expand All @@ -66,8 +66,8 @@
}
REQUEST = {
"display_name": DISPLAY_NAME,
"wallet_pub_key": WALLET_PUB_KEYS,
"tessera_pub_key": TESSERA_PUB_KEYS,
"wallet_pub_key": WALLET_PUB_KEY,
"tessera_pub_key": TESSERA_PUB_KEY,
}
UPDATE = {"display_name": DISPLAY_NAME}

Expand Down Expand Up @@ -100,7 +100,7 @@ def test_subjects_create(self):
mock_post.return_value = MockResponse(200, **RESPONSE)

subject = self.arch.subjects.create(
DISPLAY_NAME, WALLET_PUB_KEYS, TESSERA_PUB_KEYS
DISPLAY_NAME, WALLET_PUB_KEY, TESSERA_PUB_KEY
)
args, kwargs = mock_post.call_args
self.assertEqual(
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_subjects_create_with_confirmation_unconfirmed(self):
with mock.patch.object(self.arch.session, "post") as mock_post:
mock_post.return_value = MockResponse(200, **RESPONSE)
subject = self.arch.subjects.create(
DISPLAY_NAME, WALLET_PUB_KEYS, TESSERA_PUB_KEYS
DISPLAY_NAME, WALLET_PUB_KEY, TESSERA_PUB_KEY
)
self.assertEqual(
subject,
Expand Down Expand Up @@ -444,7 +444,7 @@ def test_subjects_create_with_confirmation(self):
with mock.patch.object(self.arch.session, "post") as mock_post:
mock_post.return_value = MockResponse(200, **RESPONSE)
subject = self.arch.subjects.create(
DISPLAY_NAME, WALLET_PUB_KEYS, TESSERA_PUB_KEYS
DISPLAY_NAME, WALLET_PUB_KEY, TESSERA_PUB_KEY
)
self.assertEqual(
subject,
Expand Down