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
5 changes: 2 additions & 3 deletions lib/SampleService/core/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,14 @@ def _resolve_timestamp(self, timestamp: datetime.datetime = None) -> datetime.da

def get_links_from_data(
self,
user: UserID,
user: Optional[UserID],
upa: UPA,
timestamp: datetime.datetime = None,
as_admin: bool = False) -> Tuple[List[DataLink], datetime.datetime]:
'''
Get a set of data links originating from a workspace object at a particular time.

:param user: the user requesting the links.
:param user: the user requesting the links, or None for an anonymous user.
:param upa: the data from which the links originate.
:param timestamp: the timestamp during which the links should be active, defaulting to
the current time.
Expand All @@ -413,7 +413,6 @@ def get_links_from_data(
'''
# may need to make this independent of the workspace. YAGNI.
# handle ref path?
_not_falsy(user, 'user')
_not_falsy(upa, 'upa')
timestamp = self._resolve_timestamp(timestamp)
# NONE still checks that WS/obj exists. If it's deleted this method should fail
Expand Down
17 changes: 10 additions & 7 deletions test/core/samples_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ def test_get_links_from_data():
storage.get_links_from_data.assert_called_once_with(UPA('2/4/6'), dt(6))


def test_get_links_from_data_with_timestamp():
def test_get_links_from_data_with_timestamp_and_anon_user():
storage = create_autospec(ArangoSampleStorage, spec_set=True, instance=True)
lu = create_autospec(KBaseUserLookup, spec_set=True, instance=True)
meta = create_autospec(MetadataValidatorSet, spec_set=True, instance=True)
Expand All @@ -1364,10 +1364,10 @@ def test_get_links_from_data_with_timestamp():

storage.get_links_from_data.return_value = [dl1]

assert s.get_links_from_data(UserID('u1'), UPA('2/4/6'), timestamp=dt(700)) == ([dl1], dt(700))
assert s.get_links_from_data(None, UPA('2/4/6'), timestamp=dt(700)) == ([dl1], dt(700))

ws.has_permission.assert_called_once_with(
UserID('u1'), WorkspaceAccessType.READ, upa=UPA('2/4/6'))
None, WorkspaceAccessType.READ, upa=UPA('2/4/6'))

storage.get_links_from_data.assert_called_once_with(UPA('2/4/6'), dt(700))

Expand Down Expand Up @@ -1416,15 +1416,18 @@ def test_get_links_from_data_fail_bad_args():
up = UPA('1/1/1')
bt = datetime.datetime.fromtimestamp(1)

_get_links_from_from_data_fail(s, None, up, None, ValueError(
'user cannot be a value that evaluates to false'))
_get_links_from_from_data_fail(s, u, None, None, ValueError(
'upa cannot be a value that evaluates to false'))
_get_links_from_from_data_fail(s, u, up, bt, ValueError(
'timestamp cannot be a naive datetime'))


def test_get_links_from_data_fail_no_ws_access():
_get_links_from_data_fail_no_ws_access(UserID('u'))
_get_links_from_data_fail_no_ws_access(None)


def _get_links_from_data_fail_no_ws_access(user):
storage = create_autospec(ArangoSampleStorage, spec_set=True, instance=True)
lu = create_autospec(KBaseUserLookup, spec_set=True, instance=True)
meta = create_autospec(MetadataValidatorSet, spec_set=True, instance=True)
Expand All @@ -1433,11 +1436,11 @@ def test_get_links_from_data_fail_no_ws_access():

ws.has_permission.side_effect = UnauthorizedError('oh honey')

_get_links_from_from_data_fail(s, UserID('u'), UPA('1/1/1'), None,
_get_links_from_from_data_fail(s, user, UPA('1/1/1'), None,
UnauthorizedError('oh honey'))

ws.has_permission.assert_called_once_with(
UserID('u'), WorkspaceAccessType.READ, upa=UPA('1/1/1'))
user, WorkspaceAccessType.READ, upa=UPA('1/1/1'))


def _get_links_from_from_data_fail(samples, user, upa, ts, expected):
Expand Down