def test_it_raises_if_data_has_no_uri(self, pyramid_request): data = self.valid_data() del data['uri'] schema = CreateAnnotationSchema(pyramid_request) with pytest.raises(ValidationError) as exc: schema.validate(data) assert str(exc.value) == "uri: 'uri' is a required property"
def test_it_raises_if_data_has_no_uri(self, pyramid_request): data = self.valid_data() del data["uri"] schema = CreateAnnotationSchema(pyramid_request) with pytest.raises(ValidationError) as exc: schema.validate(data) assert str(exc.value) == "uri: 'uri' is a required property"
def test_it_renames_group_to_groupid(self, pyramid_request): schema = CreateAnnotationSchema(pyramid_request) appstruct = schema.validate(self.valid_data(group="foo")) assert appstruct["groupid"] == "foo" assert "group" not in appstruct
def test_it_sets_userid(self, pyramid_config, pyramid_request): pyramid_config.testing_securitypolicy('acct:[email protected]') schema = CreateAnnotationSchema(pyramid_request) appstruct = schema.validate(self.valid_data()) assert appstruct['userid'] == 'acct:[email protected]'
def test_it_sets_userid(self, pyramid_config, pyramid_request): pyramid_config.testing_securitypolicy("acct:[email protected]") schema = CreateAnnotationSchema(pyramid_request) appstruct = schema.validate(self.valid_data()) assert appstruct["userid"] == "acct:[email protected]"
def test_it_defaults_to_private_if_no_permissions_object_sent( self, pyramid_request): schema = CreateAnnotationSchema(pyramid_request) appstruct = schema.validate(self.valid_data()) assert appstruct["shared"] is False
def test_it_keeps_references(self, pyramid_request): schema = 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_renames_group_to_groupid(self, pyramid_request): schema = CreateAnnotationSchema(pyramid_request) appstruct = schema.validate(self.valid_data(group='foo')) assert appstruct['groupid'] == 'foo' assert 'group' not in appstruct
def test_it_keeps_references(self, pyramid_request): schema = 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_deletes_groupid_for_replies(self, pyramid_request): schema = CreateAnnotationSchema(pyramid_request) appstruct = schema.validate( self.valid_data(group="foo", references=["parent annotation id"])) assert "groupid" 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 = CreateAnnotationSchema(request) return schema.validate(data)
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 = CreateAnnotationSchema(request) return schema.validate(data)
def test_it_keeps_references(self, pyramid_request): schema = 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 = CreateAnnotationSchema(pyramid_request) appstruct = schema.validate(self.valid_data()) assert appstruct["shared"] is False
def test_it_deletes_groupid_for_replies(self, pyramid_request): schema = 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 = 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_replaces_private_permissions_with_shared_False(self, pyramid_request): schema = 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_replaces_private_permissions_with_shared_False(self, pyramid_request): schema = 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_replaces_private_permissions_with_shared_False(self, pyramid_request): schema = CreateAnnotationSchema(pyramid_request) appstruct = schema.validate( self.valid_data(permissions={"read": ["acct:[email protected]"]}) ) assert not appstruct["shared"] assert "permissions" not in appstruct
def test_it_replaces_shared_permissions_with_shared_True( self, pyramid_request): schema = 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 test_it_replaces_shared_permissions_with_shared_True(self, pyramid_request): schema = 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 test_it_replaces_shared_permissions_with_shared_True( self, pyramid_request): schema = 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 test_it_replaces_shared_permissions_with_shared_True(self, pyramid_request): schema = 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 = CreateAnnotationSchema(request) appstruct = schema.validate(_json_payload(request)) group_service = request.find_service(IGroupService) annotation = storage.create_annotation(request, appstruct, group_service) _publish_annotation_event(request, annotation, "create") svc = request.find_service(name="annotation_json_presentation") annotation_resource = _annotation_resource(request, annotation) return svc.present(annotation_resource)
def create(request): """Create an annotation from the POST payload.""" schema = CreateAnnotationSchema(request) appstruct = schema.validate(_json_payload(request)) annotation = storage.create_annotation(request, appstruct) _publish_annotation_event(request, annotation, "create") return request.find_service(name="annotation_json").present_for_user( annotation=annotation, user=request.user )
def create(request): """Create an annotation from the POST payload.""" schema = CreateAnnotationSchema(request) appstruct = schema.validate(_json_payload(request)) group_service = request.find_service(IGroupService) annotation = storage.create_annotation(request, appstruct, group_service) _publish_annotation_event(request, annotation, 'create') links_service = request.find_service(name='links') group_service = request.find_service(IGroupService) resource = AnnotationResource(annotation, group_service, links_service) presenter = AnnotationJSONPresenter(resource) return presenter.asdict()
def test_it_inserts_empty_string_if_data_contains_no_text(self, pyramid_request): schema = CreateAnnotationSchema(pyramid_request) assert schema.validate(self.valid_data())['text'] == ''
def test_it_inserts_empty_list_if_data_contains_no_tags(self, pyramid_request): schema = CreateAnnotationSchema(pyramid_request) assert schema.validate(self.valid_data())['tags'] == []
def test_it_inserts_empty_list_if_no_references(self, pyramid_request): schema = 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 = CreateAnnotationSchema(pyramid_request) appstruct = schema.validate(self.valid_data()) assert appstruct["groupid"] == "__world__"
def test_it_inserts_default_groupid_if_no_group(self, pyramid_request): schema = CreateAnnotationSchema(pyramid_request) appstruct = schema.validate(self.valid_data()) assert appstruct['groupid'] == '__world__'
def test_it_inserts_empty_list_if_no_references(self, pyramid_request): schema = CreateAnnotationSchema(pyramid_request) appstruct = schema.validate(self.valid_data()) assert appstruct['references'] == []
def test_it_inserts_empty_string_if_data_contains_no_text( self, pyramid_request): schema = CreateAnnotationSchema(pyramid_request) assert schema.validate(self.valid_data())["text"] == ""
def test_it_inserts_empty_list_if_data_contains_no_tags( self, pyramid_request): schema = CreateAnnotationSchema(pyramid_request) assert schema.validate(self.valid_data())["tags"] == []