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
97 changes: 52 additions & 45 deletions unittests/testassets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .mock_response import MockResponse
from .testassetsconstants import (
TestAssetsBase,
TestAssetsBaseConfirm,
PRIMARY_IMAGE,
ASSET_NAME,
ATTRS,
Expand Down Expand Up @@ -139,87 +140,94 @@ def test_assets_create_with_fixtures(self):
msg="CREATE method called incorrectly",
)

def test_assets_create_with_confirmation(self):
def test_assets_create_with_confirmation_no_confirmed_status(self):
"""
Test asset creation
Test asset confirmation
"""
with mock.patch.object(
self.arch._session, "post"
) as mock_post, mock.patch.object(self.arch._session, "get") as mock_get:
mock_post.return_value = MockResponse(200, **RESPONSE)
mock_get.return_value = MockResponse(200, **RESPONSE)
asset = self.arch.assets.create(props=PROPS, attrs=ATTRS, confirm=True)
self.assertEqual(
asset,
RESPONSE,
msg="CREATE method called incorrectly",
)
mock_get.return_value = MockResponse(200, **RESPONSE_NO_CONFIRMATION)

def test_assets_create_with_explicit_confirmation(self):
with self.assertRaises(ArchivistUnconfirmedError):
asset = self.arch.assets.create(props=PROPS, attrs=ATTRS, confirm=True)

def test_assets_create_with_confirmation_failed_status(self):
"""
Test asset creation
Test asset confirmation
"""
with mock.patch.object(
self.arch._session, "post"
) as mock_post, mock.patch.object(self.arch._session, "get") as mock_get:
mock_post.return_value = MockResponse(200, **RESPONSE)
mock_get.return_value = MockResponse(200, **RESPONSE)
asset = self.arch.assets.create(props=PROPS, attrs=ATTRS, confirm=False)
self.arch.assets.wait_for_confirmation(asset["identity"])
self.assertEqual(
asset,
RESPONSE,
msg="CREATE method called incorrectly",
)
mock_get.side_effect = [
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE_FAILED),
]
with self.assertRaises(ArchivistUnconfirmedError):
asset = self.arch.assets.create(props=PROPS, attrs=ATTRS, confirm=True)

def test_assets_create_with_confirmation_no_confirmed_status(self):
def test_assets_create_with_confirmation_always_pending_status(self):
"""
Test asset confirmation
"""
with mock.patch.object(
self.arch._session, "post"
) as mock_post, mock.patch.object(self.arch._session, "get") as mock_get:
mock_post.return_value = MockResponse(200, **RESPONSE)
mock_get.return_value = MockResponse(200, **RESPONSE_NO_CONFIRMATION)

mock_get.side_effect = [
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE_PENDING),
]
with self.assertRaises(ArchivistUnconfirmedError):
asset = self.arch.assets.create(props=PROPS, attrs=ATTRS, confirm=True)

def test_assets_create_with_confirmation_pending_status(self):

class TestAssetsCreateConfirm(TestAssetsBaseConfirm):
"""
Test Archivist Assets methods with expected confirmation
"""

def test_assets_create_with_confirmation(self):
"""
Test asset confirmation
Test asset creation
"""
with mock.patch.object(
self.arch._session, "post"
) as mock_post, mock.patch.object(self.arch._session, "get") as mock_get:
mock_post.return_value = MockResponse(200, **RESPONSE)
mock_get.side_effect = [
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE),
]
mock_get.return_value = MockResponse(200, **RESPONSE)
asset = self.arch.assets.create(props=PROPS, attrs=ATTRS, confirm=True)
self.assertEqual(
asset,
RESPONSE,
msg="CREATE method called incorrectly",
)

def test_assets_create_with_confirmation_failed_status(self):
def test_assets_create_with_explicit_confirmation(self):
"""
Test asset confirmation
Test asset creation
"""
with mock.patch.object(
self.arch._session, "post"
) as mock_post, mock.patch.object(self.arch._session, "get") as mock_get:
mock_post.return_value = MockResponse(200, **RESPONSE)
mock_get.side_effect = [
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE_FAILED),
]
with self.assertRaises(ArchivistUnconfirmedError):
asset = self.arch.assets.create(props=PROPS, attrs=ATTRS, confirm=True)
mock_get.return_value = MockResponse(200, **RESPONSE)
asset = self.arch.assets.create(props=PROPS, attrs=ATTRS, confirm=False)
self.arch.assets.wait_for_confirmation(asset["identity"])
self.assertEqual(
asset,
RESPONSE,
msg="CREATE method called incorrectly",
)

def test_assets_create_with_confirmation_always_pending_status(self):
def test_assets_create_with_confirmation_pending_status(self):
"""
Test asset confirmation
"""
Expand All @@ -229,15 +237,14 @@ def test_assets_create_with_confirmation_always_pending_status(self):
mock_post.return_value = MockResponse(200, **RESPONSE)
mock_get.side_effect = [
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE),
]
with self.assertRaises(ArchivistUnconfirmedError):
asset = self.arch.assets.create(props=PROPS, attrs=ATTRS, confirm=True)
asset = self.arch.assets.create(props=PROPS, attrs=ATTRS, confirm=True)
self.assertEqual(
asset,
RESPONSE,
msg="CREATE method called incorrectly",
)


class TestAssetsCreateIfNotExists(TestAssetsBase):
Expand Down
14 changes: 14 additions & 0 deletions unittests/testassetsconstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,17 @@ def setUp(self):

def tearDown(self):
self.arch = None


class TestAssetsBaseConfirm(TestCase):
"""
Test Archivist Assets Base with expected confirmation
"""

maxDiff = None

def setUp(self):
self.arch = Archivist("url", "authauthauth", max_time=100)

def tearDown(self):
self.arch = None
88 changes: 51 additions & 37 deletions unittests/testevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,24 +788,6 @@ def test_events_create_with_asset_attrs(self):
msg="CREATE method called incorrectly",
)

def test_events_create_with_confirmation(self):
"""
Test event creation
"""
with mock.patch.object(
self.arch._session, "post"
) as mock_post, mock.patch.object(self.arch._session, "get") as mock_get:

mock_post.return_value = MockResponse(200, **RESPONSE)
mock_get.return_value = MockResponse(200, **RESPONSE)

event = self.arch.events.create(ASSET_ID, PROPS, EVENT_ATTRS, confirm=True)
self.assertEqual(
event,
RESPONSE,
msg="CREATE method called incorrectly",
)

def test_events_create_with_explicit_confirmation(self):
"""
Test event creation
Expand Down Expand Up @@ -840,25 +822,6 @@ def test_events_create_with_confirmation_no_confirmed_status(self):
ASSET_ID, PROPS, EVENT_ATTRS, confirm=True
)

def test_events_create_with_confirmation_pending_status(self):
"""
Test asset confirmation
"""
with mock.patch.object(
self.arch._session, "post"
) as mock_post, mock.patch.object(self.arch._session, "get") as mock_get:
mock_post.return_value = MockResponse(200, **RESPONSE)
mock_get.side_effect = [
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE),
]
event = self.arch.events.create(ASSET_ID, PROPS, EVENT_ATTRS, confirm=True)
self.assertEqual(
event,
RESPONSE,
msg="CREATE method called incorrectly",
)

def test_events_create_with_confirmation_failed_status(self):
"""
Test asset confirmation
Expand Down Expand Up @@ -1386,3 +1349,54 @@ def test_events_read_by_signature(self):
),
msg="GET method called incorrectly",
)


class TestEventsConfirm(TestCase):
"""
Test Archivist Events Create method with expected confirm
"""

maxDiff = None

def setUp(self):
self.arch = Archivist("url", "authauthauth", max_time=100)

def tearDown(self):
self.arch = None

def test_events_create_with_confirmation(self):
"""
Test event creation
"""
with mock.patch.object(
self.arch._session, "post"
) as mock_post, mock.patch.object(self.arch._session, "get") as mock_get:

mock_post.return_value = MockResponse(200, **RESPONSE)
mock_get.return_value = MockResponse(200, **RESPONSE)

event = self.arch.events.create(ASSET_ID, PROPS, EVENT_ATTRS, confirm=True)
self.assertEqual(
event,
RESPONSE,
msg="CREATE method called incorrectly",
)

def test_events_create_with_confirmation_pending_status(self):
"""
Test asset confirmation
"""
with mock.patch.object(
self.arch._session, "post"
) as mock_post, mock.patch.object(self.arch._session, "get") as mock_get:
mock_post.return_value = MockResponse(200, **RESPONSE)
mock_get.side_effect = [
MockResponse(200, **RESPONSE_PENDING),
MockResponse(200, **RESPONSE),
]
event = self.arch.events.create(ASSET_ID, PROPS, EVENT_ATTRS, confirm=True)
self.assertEqual(
event,
RESPONSE,
msg="CREATE method called incorrectly",
)
Loading