def test_update_change_permissions_disallowed(): annotation = api.Annotation(_old_annotation) with raises(RuntimeError): api._update_annotation(annotation, _new_annotation, False) assert annotation['text'] == 'old_text' assert annotation.save.call_count == 0
def test_update_anonymize_deletes(mock_anonymize_deletes): annotation = api.Annotation(_old_annotation) annotation['deleted'] = True request = DummyRequest(json_body=_new_annotation) api.update(annotation, request) api._anonymize_deletes.assert_called_once_with(annotation)
def test_delete(): annotation = api.Annotation(_old_annotation) result = api.delete(annotation, DummyRequest()) assert annotation.delete.assert_called_once() _assert_event_triggered('delete') assert result == { 'id': '1234', 'deleted': True }, "Deletion confirmation should have been returned"
def test_update_annotation(user): annotation = api.Annotation(_old_annotation) api._update_annotation(annotation, _new_annotation, True) assert annotation['text'] == 'blabla' assert annotation['quote'] == 'original_quote' assert annotation['user'] == 'alice' assert annotation['consumer'] == 'consumer_key' assert annotation['permissions'] == _new_annotation['permissions'] annotation.save.assert_called_once()
def test_update(mock_update_annotation): annotation = api.Annotation(_old_annotation) request = DummyRequest(json_body=_new_annotation) request.has_permission = MagicMock(return_value=True) result = api.update(annotation, request) api._update_annotation.assert_called_once_with(annotation, _new_annotation, True) _assert_event_triggered('update') assert result is annotation, "Annotation should have been returned"
def test_anonymize_deletes(): annotation = api.Annotation(_old_annotation) annotation['deleted'] = True api._anonymize_deletes(annotation) assert 'user' not in annotation assert annotation['permissions'] == { 'admin': [], 'update': ['bob'], 'read': ['group:__world__'], 'delete': [], }