def test_it_renames_group_to_groupid(self, pyramid_request): schema = schemas.CreateAnnotationSchema(pyramid_request) appstruct = schema.validate(self.valid_data(group='foo')) assert appstruct['groupid'] == 'foo' assert 'group' not in appstruct
def create_annotation_schema_validate(request, data): # 'uri' is required when creating new annotations. if 'uri' not in data: data['uri'] = 'http://example.com/example' schema = schemas.CreateAnnotationSchema(request) return schema.validate(data)
def test_it_sets_userid(self, pyramid_config, pyramid_request): pyramid_config.testing_securitypolicy('acct:[email protected]') schema = schemas.CreateAnnotationSchema(pyramid_request) appstruct = schema.validate(self.valid_data()) assert appstruct['userid'] == 'acct:[email protected]'
def test_it_deletes_groupid_for_replies(self, pyramid_request): schema = schemas.CreateAnnotationSchema(pyramid_request) appstruct = schema.validate( self.valid_data(group='foo', references=['parent annotation id'])) assert 'groupid' not in appstruct
def test_it_keeps_references(self, pyramid_request): schema = schemas.CreateAnnotationSchema(pyramid_request) appstruct = schema.validate( self.valid_data(references=['parent id', 'parent id 2'])) assert appstruct['references'] == ['parent id', 'parent id 2']
def test_it_defaults_to_private_if_no_permissions_object_sent( self, pyramid_request): schema = schemas.CreateAnnotationSchema(pyramid_request) appstruct = schema.validate(self.valid_data()) assert appstruct['shared'] is False
def test_it_raises_if_uri_is_empty_string(self, pyramid_request): schema = schemas.CreateAnnotationSchema(pyramid_request) with pytest.raises(schemas.ValidationError) as exc: schema.validate(self.valid_data(uri='')) assert exc.value.message == "uri: 'uri' is a required property"
def test_it_replaces_private_permissions_with_shared_False(self, pyramid_request): schema = schemas.CreateAnnotationSchema(pyramid_request) appstruct = schema.validate(self.valid_data( permissions={'read': ['acct:[email protected]']} )) assert appstruct['shared'] is False assert 'permissions' not in appstruct
def test_it_raises_if_data_has_no_uri(self, pyramid_request): data = self.valid_data() del data['uri'] schema = schemas.CreateAnnotationSchema(pyramid_request) with pytest.raises(schemas.ValidationError) as exc: schema.validate(data) assert exc.value.message == "uri: 'uri' is a required property"
def test_it_replaces_shared_permissions_with_shared_True(self, pyramid_request): schema = schemas.CreateAnnotationSchema(pyramid_request) appstruct = schema.validate(self.valid_data( permissions={'read': ['group:__world__']}, group='__world__' )) assert appstruct['shared'] is True assert 'permissions' not in appstruct
def create(request): """Create an annotation from the POST payload.""" schema = schemas.CreateAnnotationSchema(request) appstruct = schema.validate(_json_payload(request)) annotation = storage.create_annotation(request, appstruct) _publish_annotation_event(request, annotation, 'create') links_service = request.find_service(name='links') presenter = AnnotationJSONPresenter(annotation, links_service) return presenter.asdict()
def test_it_inserts_empty_list_if_no_references(self, pyramid_request): schema = schemas.CreateAnnotationSchema(pyramid_request) appstruct = schema.validate(self.valid_data()) assert appstruct['references'] == []
def test_it_inserts_default_groupid_if_no_group(self, pyramid_request): schema = schemas.CreateAnnotationSchema(pyramid_request) appstruct = schema.validate(self.valid_data()) assert appstruct['groupid'] == '__world__'
def test_it_inserts_empty_list_if_data_contains_no_tags(self, pyramid_request): schema = schemas.CreateAnnotationSchema(pyramid_request) assert schema.validate(self.valid_data())['tags'] == []
def test_it_inserts_empty_string_if_data_contains_no_text(self, pyramid_request): schema = schemas.CreateAnnotationSchema(pyramid_request) assert schema.validate(self.valid_data())['text'] == ''