def test_it_permits_all_other_changes(self, data): request = testing.DummyRequest() annotation = {'group': 'flibble'} schema = schemas.LegacyUpdateAnnotationSchema(request, annotation) result = schema.validate(data) for k in data: assert result[k] == data[k]
def test_it_raises_if_structure_validator_raises(self): request = testing.DummyRequest() schema = schemas.LegacyUpdateAnnotationSchema(request, {}) schema.structure = mock.Mock() schema.structure.validate.side_effect = ( schemas.ValidationError('asplode')) with pytest.raises(schemas.ValidationError): schema.validate({'foo': 'bar'})
def test_it_passes_input_to_structure_validator(self): request = testing.DummyRequest() schema = schemas.LegacyUpdateAnnotationSchema(request, {}) schema.structure = mock.Mock() schema.structure.validate.return_value = {} schema.validate({'foo': 'bar'}) schema.structure.validate.assert_called_once_with({'foo': 'bar'})
def test_it_removes_protected_fields(self, field): request = testing.DummyRequest() annotation = {} schema = schemas.LegacyUpdateAnnotationSchema(request, annotation) data = {} data[field] = 'something forbidden' result = schema.validate(data) assert field not in result
def test_it_denies_group_changes(self): """An annotation may not be moved between groups.""" request = testing.DummyRequest() annotation = {'group': 'flibble'} schema = schemas.LegacyUpdateAnnotationSchema(request, annotation) data = {'group': '__world__'} with pytest.raises(schemas.ValidationError) as exc: schema.validate(data) assert exc.value.message.startswith('group:')
def update(annotation, request): """Update the specified annotation with data from the PUT payload.""" schema = schemas.LegacyUpdateAnnotationSchema(request, annotation=annotation) appstruct = schema.validate(_json_payload(request)) annotation = storage.update_annotation(request, annotation.id, appstruct) _publish_annotation_event(request, annotation, 'update') presenter = AnnotationJSONPresenter(request, annotation) return presenter.asdict()
def test_it_allows_permissions_changes_if_admin(self, authn_policy): """If a user is an admin on an annotation, they can change perms.""" authn_policy.authenticated_userid.return_value = ( 'acct:[email protected]') request = testing.DummyRequest() annotation = {'permissions': {'admin': ['acct:[email protected]']}} schema = schemas.LegacyUpdateAnnotationSchema(request, annotation) data = {'permissions': {'admin': ['acct:[email protected]']}} result = schema.validate(data) assert result == data
def test_it_denies_permissions_changes_if_not_admin( self, annotation, authn_policy): """If a user isn't admin on an annotation they can't change perms.""" authn_policy.authenticated_userid.return_value = ( 'acct:[email protected]') request = testing.DummyRequest() schema = schemas.LegacyUpdateAnnotationSchema(request, annotation) data = {'permissions': {'admin': ['acct:[email protected]']}} with pytest.raises(schemas.ValidationError) as exc: schema.validate(data) assert exc.value.message.startswith('permissions:')