|
|
@@ -22,23 +22,6 @@ def _mock_annotation(**kwargs): |
|
|
'Annotation', 'search_lib')
|
|
|
|
|
|
|
|
|
@create_annotation_fixtures
|
|
|
def test_create_annotation_pops_protected_fields(Annotation):
|
|
|
"""It should remove any protected fields before calling Annotation."""
|
|
|
logic.create_annotation(
|
|
|
fields={
|
|
|
'foo': 'bar',
|
|
|
'created': 'foo',
|
|
|
'updated': 'foo',
|
|
|
'user': 'foo',
|
|
|
'id': 'foo'
|
|
|
},
|
|
|
userid='acct:annamaria@example.com')
|
|
|
|
|
|
for field in ('created', 'updated', 'user', 'id'):
|
|
|
assert field not in Annotation.call_args[0][0]
|
|
|
|
|
|
|
|
|
@create_annotation_fixtures
|
|
|
def test_create_annotation_calls_Annotation(Annotation):
|
|
|
fields = mock.MagicMock()
|
|
|
@@ -113,25 +96,6 @@ def test_create_annotation_does_not_crash_if_annotations_parent_has_no_group( |
|
|
update_annotation_fixtures = pytest.mark.usefixtures('search_lib')
|
|
|
|
|
|
|
|
|
@update_annotation_fixtures
|
|
|
def test_update_annotation_does_not_pass_protected_fields_to_update():
|
|
|
annotation = _mock_annotation()
|
|
|
|
|
|
logic.update_annotation(
|
|
|
annotation,
|
|
|
fields={
|
|
|
'foo': 'bar',
|
|
|
'created': 'foo',
|
|
|
'updated': 'foo',
|
|
|
'user': 'foo',
|
|
|
'id': 'foo'
|
|
|
},
|
|
|
userid='foo')
|
|
|
|
|
|
for field in ('created', 'updated', 'user', 'id'):
|
|
|
assert field not in annotation.update.call_args[0][0]
|
|
|
|
|
|
|
|
|
@update_annotation_fixtures
|
|
|
def test_update_annotation_raises_if_non_admin_changes_perms():
|
|
|
with pytest.raises(RuntimeError):
|
|
|
@@ -191,84 +155,6 @@ def test_update_annotation_user_cannot_change_group(): |
|
|
logic.update_annotation(annotation, fields, 'foo')
|
|
|
|
|
|
|
|
|
@update_annotation_fixtures
|
|
|
def test_update_annotation_removes_userid_from_permissions_if_deleted():
|
|
|
userid = 'acct:fred@hypothes.is'
|
|
|
annotation = _mock_annotation(
|
|
|
deleted=True,
|
|
|
user=userid,
|
|
|
permissions={
|
|
|
'admin': [userid, 'someone else'],
|
|
|
'read': [userid, 'someone else'],
|
|
|
'update': ['someone else'],
|
|
|
'delete': ['someone else']
|
|
|
}
|
|
|
)
|
|
|
fields = {
|
|
|
'permissions': {
|
|
|
'update': [userid],
|
|
|
'delete': [userid]
|
|
|
}
|
|
|
}
|
|
|
|
|
|
logic.update_annotation(annotation, fields, userid)
|
|
|
|
|
|
for action in annotation['permissions']:
|
|
|
assert userid not in annotation['permissions'][action]
|
|
|
|
|
|
|
|
|
@update_annotation_fixtures
|
|
|
def test_update_annotation_does_not_remove_userid_if_not_deleted():
|
|
|
userid = 'acct:fred@hypothes.is'
|
|
|
annotation = _mock_annotation(
|
|
|
deleted=False,
|
|
|
user=userid,
|
|
|
permissions={
|
|
|
'admin': [userid, 'someone else'],
|
|
|
'read': [userid, 'someone else'],
|
|
|
'update': ['someone else'],
|
|
|
'delete': ['someone else']
|
|
|
}
|
|
|
)
|
|
|
fields = {
|
|
|
'permissions': {
|
|
|
'update': [userid],
|
|
|
'delete': [userid]
|
|
|
}
|
|
|
}
|
|
|
|
|
|
logic.update_annotation(annotation, fields, userid)
|
|
|
|
|
|
for action in annotation['permissions']:
|
|
|
assert userid in annotation['permissions'][action]
|
|
|
|
|
|
|
|
|
@update_annotation_fixtures
|
|
|
def test_update_annotation_if_deleted_does_not_remove_other_principals():
|
|
|
userid = 'acct:fred@hypothes.is'
|
|
|
annotation = _mock_annotation(
|
|
|
deleted=True,
|
|
|
user=userid,
|
|
|
permissions={
|
|
|
'admin': [userid, 'someone else'],
|
|
|
'read': [userid, 'someone else'],
|
|
|
'update': [userid],
|
|
|
'delete': [userid]
|
|
|
}
|
|
|
)
|
|
|
fields = {
|
|
|
'permissions': {
|
|
|
'update': ['someone else'],
|
|
|
'delete': ['someone else']
|
|
|
}
|
|
|
}
|
|
|
|
|
|
logic.update_annotation(annotation, fields, userid)
|
|
|
|
|
|
for action in annotation['permissions']:
|
|
|
assert 'someone else' in annotation['permissions'][action]
|
|
|
|
|
|
|
|
|
@update_annotation_fixtures
|
|
|
def test_update_annotation_calls_prepare(search_lib):
|
|
|
annotation = _mock_annotation()
|
|
|
|