From 2518dd18a083e412fb493e98608d9bdb1e564c86 Mon Sep 17 00:00:00 2001 From: Alzbeta Pokorna Date: Tue, 22 Oct 2024 15:14:14 +0200 Subject: [PATCH] tests --- tests/test_builder_from_entrypoints.py | 4 +- tests/test_datatype_prepare.py | 14 +- tests/test_extend.py | 16 +- tests/test_marshmallow_builder.py | 24 +- tests/test_model_saver.py | 858 +++++++++++++++---------- tests/test_raw.py | 4 +- tests/test_schema_props.py | 2 +- tests/test_shortcuts.py | 2 +- tests/test_simple_builders.py | 25 +- 9 files changed, 563 insertions(+), 386 deletions(-) diff --git a/tests/test_builder_from_entrypoints.py b/tests/test_builder_from_entrypoints.py index 0dd4c17..a5b9943 100644 --- a/tests/test_builder_from_entrypoints.py +++ b/tests/test_builder_from_entrypoints.py @@ -47,10 +47,10 @@ def test_include_invenio(): import marshmallow as ma from marshmallow import fields as ma_fields from oarepo_runtime.services.schema.marshmallow import BaseRecordSchema +from oarepo_runtime.services.schema.rdm import RDMRecordMixin - -class TestSchema(BaseRecordSchema): +class TestSchema(BaseRecordSchema, RDMRecordMixin): class Meta: unknown = ma.RAISE diff --git a/tests/test_datatype_prepare.py b/tests/test_datatype_prepare.py index 721c0a0..533229e 100644 --- a/tests/test_datatype_prepare.py +++ b/tests/test_datatype_prepare.py @@ -120,9 +120,7 @@ def test_prepare_datatype(): "generate": True, "module": "my.test.records.api", "class": "my.test.records.api.TestRecord", - "base-classes": [ - "invenio_records_resources.records.api.Record{InvenioRecord}" - ], + "base-classes": ['invenio_rdm_records.records.api.RDMRecord'], "imports": [], "extra-code": "", "fields": {}, @@ -200,7 +198,8 @@ def test_prepare_datatype(): "invenio_records.models.RecordMetadataBase", ], "extra-code": "", - "imports": [], + "imports": [{'import': 'invenio_rdm_records.records.systemfields.deletion_status.RecordDeletionStatusEnum'}, + {'import': 'sqlalchemy_utils.types.ChoiceType'}], "table": "test_metadata", "alias": "my_test_record", "use-versioning": True, @@ -227,9 +226,7 @@ def test_prepare_datatype(): "module": "my.test.services.records.service", "class": "my.test.services.records.service.TestService", "extra-code": "", - "base-classes": [ - "invenio_records_resources.services.RecordService{InvenioRecordService}" - ], + "base-classes": ['invenio_rdm_records.services.services.RDMRecordService'], "additional-args": [], "imports": [], }, @@ -270,7 +267,8 @@ def test_prepare_datatype(): "module": "my.test.services.records.schema", "class": "my.test.services.records.schema.TestSchema", "extra-code": "", - "base-classes": ["marshmallow.Schema"], + "base-classes": ['marshmallow.Schema', + 'oarepo_runtime.services.schema.rdm.RDMRecordMixin'], }, "permissions": { "generate": True, diff --git a/tests/test_extend.py b/tests/test_extend.py index 4e011cb..470e2cd 100644 --- a/tests/test_extend.py +++ b/tests/test_extend.py @@ -37,7 +37,8 @@ def test_extend_marshmallow(): loaded_model = json5.loads(fs.read("test/models/records.json")) assert loaded_model["model"]["marshmallow"] == { - "base-classes": ["marshmallow.Schema"], + "base-classes": ['marshmallow.Schema', + 'oarepo_runtime.services.schema.rdm.RDMRecordMixin'], "class": "aaa.BlahSchema", "extra-code": "", "generate": False, @@ -91,7 +92,7 @@ def test_extend_with_extra_props(): loaded_model = json5.loads(fs.read("test/models/records.json")) assert loaded_model["model"]["marshmallow"] == { - "base-classes": ["aaa.BlahSchema"], + "base-classes": ["aaa.BlahSchema", 'oarepo_runtime.services.schema.rdm.RDMRecordMixin'], "class": "test.services.records.schema.TestSchema", "extra-code": "", "generate": True, @@ -116,13 +117,13 @@ def test_extend_with_extra_props(): print(service_config) assert "from test.services.records.schema import TestSchema" in service_config assert "schema = TestSchema" in service_config - + # schema = fs.read("test/services/records/schema.py") print(schema) - + # assert "from aaa import BlahSchema" in schema assert "from aaa import BlahMetadataSchema" in schema - assert "class TestSchema(BlahSchema)" in schema + assert "class TestSchema(BlahSchema, RDMRecordMixin)" in schema assert "metadata = ma_fields.Nested(lambda: TestMetadataSchema())" in schema assert "class TestMetadataSchema(BlahMetadataSchema)" in schema assert "b = ma_fields.String()" in schema @@ -158,7 +159,8 @@ def test_extend_with_extra_props_inside_use(): loaded_model = json5.loads(fs.read("test/models/records.json")) assert loaded_model["model"]["marshmallow"] == { - "base-classes": ["aaa.BlahSchema"], + "base-classes": ['aaa.BlahSchema', + 'oarepo_runtime.services.schema.rdm.RDMRecordMixin'], "class": "test.services.records.schema.TestSchema", "extra-code": "", "generate": True, @@ -189,7 +191,7 @@ def test_extend_with_extra_props_inside_use(): assert "from aaa import BlahSchema" in schema assert "from aaa import BlahMetadataSchema" in schema - assert "class TestSchema(BlahSchema)" in schema + assert "class TestSchema(BlahSchema, RDMRecordMixin)" in schema assert "metadata = ma_fields.Nested(lambda: TestMetadataSchema())" in schema assert "class TestMetadataSchema(BlahMetadataSchema)" in schema assert "b = ma_fields.String()" in schema diff --git a/tests/test_marshmallow_builder.py b/tests/test_marshmallow_builder.py index ff54037..9076bdf 100644 --- a/tests/test_marshmallow_builder.py +++ b/tests/test_marshmallow_builder.py @@ -214,7 +214,7 @@ def test_array_of_objects(fulltext_builder): assert ( strip_whitespaces( """ -class TestSchema(Schema): +class TestSchema(Schema, RDMRecordMixin): class Meta: unknown = ma.RAISE a = ma_fields.List(ma_fields.Nested(lambda: AItemSchema())) @@ -342,7 +342,7 @@ def test_generate_nested_schema_same_file(fulltext_builder): assert ( strip_whitespaces( """ -class TestSchema(Schema): +class TestSchema(Schema, RDMRecordMixin): class Meta: unknown = ma.RAISE @@ -396,8 +396,9 @@ def test_generate_nested_schema_different_file(fulltext_builder): from marshmallow import fields as ma_fields from test.services.schema2 import BSchema from marshmallow import Schema +from oarepo_runtime.services.schema.rdm import RDMRecordMixin -class TestSchema(Schema): +class TestSchema(Schema, RDMRecordMixin): class Meta: unknown = ma.RAISE a = ma_fields.Nested(lambda: BSchema()) @@ -450,7 +451,7 @@ def test_use_nested_schema_same_file(fulltext_builder): assert ( strip_whitespaces( """ -class TestSchema(Schema): +class TestSchema(Schema, RDMRecordMixin): class Meta: unknown = ma.RAISE @@ -488,7 +489,7 @@ def test_use_nested_schema_different_file(fulltext_builder): assert ( strip_whitespaces( """ -class TestSchema(Schema): +class TestSchema(Schema, RDMRecordMixin): class Meta: unknown = ma.RAISE @@ -527,7 +528,7 @@ def test_generate_nested_schema_array(fulltext_builder): assert ( strip_whitespaces( """ -class TestSchema(Schema): +class TestSchema(Schema, RDMRecordMixin): class Meta: unknown = ma.RAISE @@ -562,7 +563,7 @@ def test_extend_existing(fulltext_builder): from invenio_records_resources.services.records.schema import BaseRecordSchema as InvenioBaseRecordSchema import marshmallow as ma import marshmallow.validate as ma_valid -class TestSchema(Schema): +class TestSchema(Schema, RDMRecordMixin): """TestSchema schema.""" a = ma_fields.String()''' ) @@ -608,8 +609,9 @@ def test_generate_nested_schema_relative_same_package(fulltext_builder): from marshmallow import fields as ma_fields from test.services.records.schema2 import BSchema from marshmallow import Schema +from oarepo_runtime.services.schema.rdm import RDMRecordMixin -class TestSchema(Schema): +class TestSchema(Schema, RDMRecordMixin): class Meta: unknown = ma.RAISE @@ -669,7 +671,7 @@ def test_generate_nested_schema_relative_same_file(fulltext_builder): assert ( strip_whitespaces( """ -class TestSchema(Schema): +class TestSchema(Schema, RDMRecordMixin): class Meta: unknown = ma.RAISE @@ -723,7 +725,9 @@ def test_generate_nested_schema_relative_upper(fulltext_builder): from marshmallow import fields as ma_fields from test.services.schema2 import BSchema from marshmallow import Schema -class TestSchema(Schema): +from oarepo_runtime.services.schema.rdm import RDMRecordMixin + +class TestSchema(Schema, RDMRecordMixin): class Meta: unknown = ma.RAISE diff --git a/tests/test_model_saver.py b/tests/test_model_saver.py index 0542131..aa3292f 100644 --- a/tests/test_model_saver.py +++ b/tests/test_model_saver.py @@ -114,9 +114,7 @@ def test_model_saver(): "generate": True, "module": "test.records.api", "class": "test.records.api.TestRecord", - "base-classes": [ - "invenio_records_resources.records.api.Record{InvenioRecord}" - ], + "base-classes": ['invenio_rdm_records.records.api.RDMRecord'], "imports": [], "extra-code": "", "fields": {}, @@ -192,7 +190,8 @@ def test_model_saver(): "invenio_records.models.RecordMetadataBase", ], "extra-code": "", - "imports": [], + "imports": [{'import': 'invenio_rdm_records.records.systemfields.deletion_status.RecordDeletionStatusEnum'}, + {'import': 'sqlalchemy_utils.types.ChoiceType'}], "table": "test_metadata", "alias": "test", "use-versioning": True, @@ -219,9 +218,7 @@ def test_model_saver(): "module": "test.services.records.service", "class": "test.services.records.service.TestService", "extra-code": "", - "base-classes": [ - "invenio_records_resources.services.RecordService{InvenioRecordService}" - ], + "base-classes": ['invenio_rdm_records.services.services.RDMRecordService'], "additional-args": [], "imports": [], }, @@ -262,7 +259,8 @@ def test_model_saver(): "module": "test.services.records.schema", "class": "test.services.records.schema.TestSchema", "extra-code": "", - "base-classes": ["marshmallow.Schema"], + "base-classes": ['marshmallow.Schema', + 'oarepo_runtime.services.schema.rdm.RDMRecordMixin'], }, "permissions": { "generate": True, @@ -343,8 +341,8 @@ def test_model_saver(): assert data[1].strip() == "" assert ( - data[2].strip() - == """[options.entry_points] + data[2].strip() + == """[options.entry_points] oarepo.models = test = test.models:records.json""" ) @@ -392,339 +390,507 @@ def test_model_saver_invenio(): {"use": "invenio", "properties": {}}, ) print(repr(data[0])) - assert data[0]["model"] == { - "type": "model", - "marshmallow": { - "imports": [], - "base-classes": [ - "oarepo_runtime.services.schema.marshmallow.BaseRecordSchema" - ], - "generate": True, - "module": "test.services.records.schema", - "class": "test.services.records.schema.TestSchema", - "extra-code": "", - }, - "searchable": True, - "ui": { - "marshmallow": { - "imports": [], - "base-classes": ["oarepo_runtime.services.schema.ui.InvenioUISchema"], - "generate": True, - "module": "test.services.records.ui_schema", - "class": "test.services.records.ui_schema.TestUISchema", - "extra-code": "", - } - }, - "module": { - "qualified": "test", - "alias": "test", - "path": "test", - "base": "test", - "base-upper": "TEST", - "base-title": "Test", - "kebab-module": "test", - "prefix": "Test", - "prefix-upper": "TEST", - "prefix-snake": "test", - "suffix": "test", - "suffix-upper": "TEST", - "suffix-snake": "test", - }, - "sample": {"file": "data/sample_data.yaml"}, - "model-name": "Test", - "ext-resource": {"generate": True, "skip": False}, - "search-options": { - "generate": True, - "module": "test.services.records.search", - "extra-code": "", - "class": "test.services.records.search.TestSearchOptions", - "base-classes": [ - "invenio_records_resources.services.SearchOptions{InvenioSearchOptions}" - ], - "imports": [], - "fields": {}, - "sort-options-field": "sort_options", - }, - "config": { - "generate": True, - "module": "test.config", - "extra_code": "", - "imports": [], - }, - "ext": { - "generate": True, - "module": "test.ext", - "class": "test.ext.TestExt", - "base-classes": [], - "extra_code": "", - "alias": "test", - "imports": [], - }, - "api-blueprint": { - "generate": True, - "alias": "test", - "extra_code": "", - "module": "test.views.records.api", - "function": "test.views.records.api.create_api_blueprint", - "imports": [], - }, - "app-blueprint": { - "generate": True, - "alias": "test", - "extra_code": "", - "module": "test.views.records.app", - "function": "test.views.records.app.create_app_blueprint", - "imports": [], - }, - "facets": { - "generate": True, - "module": "test.services.records.facets", - "groups": True, - "extra-code": "", - }, - "record": { - "generate": True, - "module": "test.records.api", - "class": "test.records.api.TestRecord", - "base-classes": [ - "invenio_records_resources.records.api.Record{InvenioRecord}" - ], - "imports": [], - "extra-code": "", - "fields": {}, - }, - "resource": { - "generate": True, - "config-key": "TEST_RECORD_RESOURCE_CLASS", - "module": "test.resources.records.resource", - "class": "test.resources.records.resource.TestResource", - "proxy": "current_resource", - "extra-code": "", - "base-classes": ["invenio_records_resources.resources.RecordResource"], - "additional-args": [], - "imports": [], - }, - "resource-config": { - "generate": True, - "base-url": "/test/", - "base-html-url": "/test/", - "config-key": "TEST_RECORD_RESOURCE_CONFIG", - "module": "test.resources.records.config", - "class": "test.resources.records.config.TestResourceConfig", - "extra-code": "", - "base-classes": [ - "invenio_records_resources.resources.RecordResourceConfig" - ], - "additional-args": [], - "imports": [], - }, - "saved-model": { - "file": "test/models/records.json", - "module": "test.models", - "alias": "test", - }, - "proxy": {"module": "test.proxies", "generate": True}, - "json-schema-settings": { - "generate": True, - "alias": "test", - "version": "1.0.0", - "module": "test.records.jsonschemas", - "name": "test-1.0.0.json", - "file": "test/records/jsonschemas/test-1.0.0.json", - }, - "pid": { - "generate": True, - "type": "test", - "module": "test.records.api", - "provider-class": "test.records.api.TestIdProvider", - "provider-base-classes": [ - "invenio_pidstore.providers.recordid_v2.RecordIdProviderV2" - ], - "field-class": "invenio_records_resources.records.systemfields.pid.PIDField", - "context-class": "invenio_records_resources.records.systemfields.pid.PIDFieldContext", - "field-args": ["create=True"], - "imports": [], - "extra-code": "", - }, - "record-dumper": { - "generate": True, - "module": "test.records.dumpers.dumper", - "class": "test.records.dumpers.dumper.TestDumper", - "base-classes": ["oarepo_runtime.records.dumpers.SearchDumper"], - "extra-code": "", - "extensions": ["{{test.records.dumpers.edtf.TestEDTFIntervalDumperExt}}()"], - "imports": [], - }, - "record-metadata": { - "generate": True, - "module": "test.records.models", - "class": "test.records.models.TestMetadata", - "base-classes": [ - "invenio_db.db{db.Model}", - "invenio_records.models.RecordMetadataBase", - ], - "extra-code": "", - "imports": [], - "table": "test_metadata", - "alias": "test", - "use-versioning": True, - "alembic": "test.alembic", - }, - "service-config": { - "generate": True, - "config-key": "TEST_RECORD_SERVICE_CONFIG", - "module": "test.services.records.config", - "class": "test.services.records.config.TestServiceConfig", - "extra-code": "", - "service-id": "test", - "base-classes": [ - "oarepo_runtime.services.config.service.PermissionsPresetsConfigMixin", - "invenio_records_resources.services.RecordServiceConfig{InvenioRecordServiceConfig}", - ], - "additional-args": [], - "components": [], - }, - "service": { - "generate": True, - "config-key": "TEST_RECORD_SERVICE_CLASS", - "proxy": "current_service", - "module": "test.services.records.service", - "class": "test.services.records.service.TestService", - "extra-code": "", - "base-classes": [ - "invenio_records_resources.services.RecordService{InvenioRecordService}" - ], - "additional-args": [], - "imports": [], - }, - "json-serializer": { - "module": "test.resources.records.ui", - "class": "test.resources.records.ui.TestUIJSONSerializer", - "base-classes": ["oarepo_runtime.resources.LocalizedUIJSONSerializer"], - "imports": [], - "extra-code": "", - "generate": True, - "list_schema_cls": "flask_resources.BaseListSchema", - "format_serializer_cls": "flask_resources.serializers.JSONSerializer", - "schema-context-args": { - '"object_key"': '"ui"', - '"identity"': "{{ flask.g{g.identity} }}", - }, - }, - "mapping": { - "generate": True, - "alias": "test", - "module": "test.records.mappings", - "index": "test-test-1.0.0", - "file": "test/records/mappings/os-v2/test/test-1.0.0.json", - "index-field-args": [], - }, - "permissions": { - "generate": True, - "presets": ["everyone"], - "extra-code": "", - "module": "test.services.records.permissions", - "class": "test.services.records.permissions.TestPermissionPolicy", - "base-classes": ["invenio_records_permissions.RecordPermissionPolicy"], - "imports": [], - }, - "edtf-interval-dumper": { - "generate": True, - "module": "test.records.dumpers.edtf", - "class": "test.records.dumpers.edtf.TestEDTFIntervalDumperExt", - "base-classes": [ - "oarepo_runtime.records.dumpers.edtf_interval.EDTFIntervalDumperExt" - ], - "extra-code": "", - "extensions": [], - "imports": [], - }, - "record-list": { - "generate": True, - "module": "test.services.records.results", - "class": "test.services.records.results.TestRecordList", - "extra-code": "", - "base-classes": ["oarepo_runtime.services.results.RecordList"], - "components": [], - "imports": [], - }, - "record-item": { - "generate": True, - "module": "test.services.records.results", - "class": "test.services.records.results.TestRecordItem", - "extra-code": "", - "base-classes": ["oarepo_runtime.services.results.RecordItem"], - "components": [], - "imports": [], - }, - "sortable": [], - "properties": { - "$schema": { - "type": "keyword", - "marshmallow": {"read": False, "write": False}, - "facets": {"searchable": True, "facet": False}, - "ui": {"marshmallow": {"read": False, "write": False}}, - "sample": {"skip": True}, - }, - "created": { - "type": "datetime", - "facets": {"searchable": True, "facet": False}, - "ui": {"marshmallow": {"read": False, "write": False}}, - "marshmallow": {"read": False, "write": False}, - "sample": {"skip": True}, - }, - "id": { - "type": "keyword", - "marshmallow": {"read": False, "write": False}, - "facets": {"searchable": True, "facet": False}, - "ui": {"marshmallow": {"read": False, "write": False}}, - "sample": {"skip": True}, - }, - "pid": { - "facets": {"facet": False, "searchable": True}, - "marshmallow": { - "class": "test.services.records.schema.FakePIDSchema", - "generate": False, - "read": False, - "skip": True, - "write": False, - }, - "sample": {"skip": True}, - "properties": { - "obj_type": { - "facets": {"facet": False, "searchable": True}, - "type": "keyword", - }, - "pid_type": { - "facets": {"facet": False, "searchable": True}, - "type": "keyword", - }, - "pk": { - "facets": {"facet": False, "searchable": True}, - "type": "integer", - }, - "status": { - "facets": {"facet": False, "searchable": True}, - "type": "keyword", - }, - }, - "type": "object", - "ui": { - "marshmallow": { - "class": "test.services.records.ui_schema.FakeUIPIDSchema", - "generate": False, - "read": False, - "skip": True, - "write": False, - } - }, - }, - "updated": { - "type": "datetime", - "facets": {"searchable": True, "facet": False}, - "ui": {"marshmallow": {"read": False, "write": False}}, - "marshmallow": {"read": False, "write": False}, - "sample": {"skip": True}, - }, - }, - } + assert data[0]["model"] == {'api-blueprint': {'alias': 'test', + 'extra_code': '', + 'function': 'test.views.records.api.create_api_blueprint', + 'generate': True, + 'imports': [], + 'module': 'test.views.records.api'}, + 'app-blueprint': {'alias': 'test', + 'extra_code': '', + 'function': 'test.views.records.app.create_app_blueprint', + 'generate': True, + 'imports': [], + 'module': 'test.views.records.app'}, + 'config': {'extra_code': '', + 'generate': True, + 'imports': [], + 'module': 'test.config'}, + 'edtf-interval-dumper': {'base-classes': [ + 'oarepo_runtime.records.dumpers.edtf_interval.EDTFIntervalDumperExt'], + 'class': 'test.records.dumpers.edtf.TestEDTFIntervalDumperExt', + 'extensions': [], + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.records.dumpers.edtf'}, + 'ext': {'alias': 'test', + 'base-classes': [], + 'class': 'test.ext.TestExt', + 'extra_code': '', + 'generate': True, + 'imports': [], + 'module': 'test.ext'}, + 'ext-resource': {'generate': True, 'skip': False}, + 'facets': {'extra-code': '', + 'generate': True, + 'groups': True, + 'module': 'test.services.records.facets'}, + 'json-schema-settings': {'alias': 'test', + 'file': 'test/records/jsonschemas/test-1.0.0.json', + 'generate': True, + 'module': 'test.records.jsonschemas', + 'name': 'test-1.0.0.json', + 'version': '1.0.0'}, + 'json-serializer': { + 'base-classes': ['oarepo_runtime.resources.LocalizedUIJSONSerializer'], + 'class': 'test.resources.records.ui.TestUIJSONSerializer', + 'extra-code': '', + 'format_serializer_cls': 'flask_resources.serializers.JSONSerializer', + 'generate': True, + 'imports': [], + 'list_schema_cls': 'flask_resources.BaseListSchema', + 'module': 'test.resources.records.ui', + 'schema-context-args': {'"identity"': '{{ ' + 'flask.g{g.identity} ' + '}}', + '"object_key"': '"ui"'}}, + 'mapping': {'alias': 'test', + 'file': 'test/records/mappings/os-v2/test/test-1.0.0.json', + 'generate': True, + 'index': 'test-test-1.0.0', + 'index-field-args': [], + 'module': 'test.records.mappings'}, + 'marshmallow': { + 'base-classes': ['oarepo_runtime.services.schema.marshmallow.BaseRecordSchema', + 'oarepo_runtime.services.schema.rdm.RDMRecordMixin'], + 'class': 'test.services.records.schema.TestSchema', + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.services.records.schema'}, + 'model-name': 'Test', + 'module': {'alias': 'test', + 'base': 'test', + 'base-title': 'Test', + 'base-upper': 'TEST', + 'kebab-module': 'test', + 'path': 'test', + 'prefix': 'Test', + 'prefix-snake': 'test', + 'prefix-upper': 'TEST', + 'qualified': 'test', + 'suffix': 'test', + 'suffix-snake': 'test', + 'suffix-upper': 'TEST'}, + 'permissions': {'base-classes': ['invenio_records_permissions.RecordPermissionPolicy'], + 'class': 'test.services.records.permissions.TestPermissionPolicy', + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.services.records.permissions', + 'presets': ['everyone']}, + 'pid': { + 'context-class': 'invenio_records_resources.records.systemfields.pid.PIDFieldContext', + 'extra-code': '', + 'field-args': ['create=True'], + 'field-class': 'invenio_records_resources.records.systemfields.pid.PIDField', + 'generate': True, + 'imports': [], + 'module': 'test.records.api', + 'provider-base-classes': [ + 'invenio_pidstore.providers.recordid_v2.RecordIdProviderV2'], + 'provider-class': 'test.records.api.TestIdProvider', + 'type': 'test'}, + 'properties': {'$schema': {'facets': {'facet': False, 'searchable': True}, + 'marshmallow': {'read': False, 'write': False}, + 'sample': {'skip': True}, + 'type': 'keyword', + 'ui': {'marshmallow': {'read': False, + 'write': False}}}, + 'created': {'facets': {'facet': False, 'searchable': True}, + 'marshmallow': {'read': False, 'write': False}, + 'sample': {'skip': True}, + 'type': 'datetime', + 'ui': {'marshmallow': {'read': False, + 'write': False}}}, + 'id': {'facets': {'facet': False, 'searchable': True}, + 'marshmallow': {'read': False, 'write': False}, + 'sample': {'skip': True}, + 'type': 'keyword', + 'ui': {'marshmallow': {'read': False, 'write': False}}}, + 'pid': {'facets': {'facet': False, 'searchable': True}, + 'marshmallow': { + 'class': 'test.services.records.schema.FakePIDSchema', + 'generate': False, + 'read': False, + 'skip': True, + 'write': False}, + 'properties': {'obj_type': {'facets': {'facet': False, + 'searchable': True}, + 'type': 'keyword'}, + 'pid_type': {'facets': {'facet': False, + 'searchable': True}, + 'type': 'keyword'}, + 'pk': {'facets': {'facet': False, + 'searchable': True}, + 'type': 'integer'}, + 'status': {'facets': {'facet': False, + 'searchable': True}, + 'type': 'keyword'}}, + 'sample': {'skip': True}, + 'type': 'object', + 'ui': {'marshmallow': { + 'class': 'test.services.records.ui_schema.FakeUIPIDSchema', + 'generate': False, + 'read': False, + 'skip': True, + 'write': False}}}, + 'updated': {'facets': {'facet': False, 'searchable': True}, + 'marshmallow': {'read': False, 'write': False}, + 'sample': {'skip': True}, + 'type': 'datetime', + 'ui': {'marshmallow': {'read': False, + 'write': False}}}}, + 'proxy': {'generate': True, 'module': 'test.proxies'}, + 'record': {'base-classes': ['invenio_rdm_records.records.api.RDMRecord'], + 'class': 'test.records.api.TestRecord', + 'extra-code': '', + 'fields': {}, + 'generate': True, + 'imports': [], + 'module': 'test.records.api'}, + 'record-dumper': {'base-classes': ['oarepo_runtime.records.dumpers.SearchDumper'], + 'class': 'test.records.dumpers.dumper.TestDumper', + 'extensions': [ + '{{test.records.dumpers.edtf.TestEDTFIntervalDumperExt}}()'], + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.records.dumpers.dumper'}, + 'record-item': {'base-classes': ['oarepo_runtime.services.results.RecordItem'], + 'class': 'test.services.records.results.TestRecordItem', + 'components': [], + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.services.records.results'}, + 'record-list': {'base-classes': ['oarepo_runtime.services.results.RecordList'], + 'class': 'test.services.records.results.TestRecordList', + 'components': [], + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.services.records.results'}, + 'record-metadata': {'alembic': 'test.alembic', + 'alias': 'test', + 'base-classes': ['invenio_db.db{db.Model}', + 'invenio_records.models.RecordMetadataBase'], + 'class': 'test.records.models.TestMetadata', + 'extra-code': '', + 'generate': True, + 'imports': [{ + 'import': 'invenio_rdm_records.records.systemfields.deletion_status.RecordDeletionStatusEnum'}, + {'import': 'sqlalchemy_utils.types.ChoiceType'}], + 'module': 'test.records.models', + 'table': 'test_metadata', + 'use-versioning': True}, + 'resource': {'additional-args': [], + 'base-classes': ['invenio_records_resources.resources.RecordResource'], + 'class': 'test.resources.records.resource.TestResource', + 'config-key': 'TEST_RECORD_RESOURCE_CLASS', + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.resources.records.resource', + 'proxy': 'current_resource'}, + 'resource-config': {'additional-args': [], + 'base-classes': [ + 'invenio_records_resources.resources.RecordResourceConfig'], + 'base-html-url': '/test/', + 'base-url': '/test/', + 'class': 'test.resources.records.config.TestResourceConfig', + 'config-key': 'TEST_RECORD_RESOURCE_CONFIG', + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.resources.records.config'}, + 'sample': {'file': 'data/sample_data.yaml'}, + 'saved-model': {'alias': 'test', + 'file': 'test/models/records.json', + 'module': 'test.models'}, + 'search-options': {'base-classes': [ + 'invenio_records_resources.services.SearchOptions{InvenioSearchOptions}'], + 'class': 'test.services.records.search.TestSearchOptions', + 'extra-code': '', + 'fields': {}, + 'generate': True, + 'imports': [], + 'module': 'test.services.records.search', + 'sort-options-field': 'sort_options'}, + 'searchable': True, + 'service': {'additional-args': [], + 'base-classes': ['invenio_rdm_records.services.services.RDMRecordService'], + 'class': 'test.services.records.service.TestService', + 'config-key': 'TEST_RECORD_SERVICE_CLASS', + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.services.records.service', + 'proxy': 'current_service'}, + 'service-config': {'additional-args': [], + 'base-classes': [ + 'oarepo_runtime.services.config.service.PermissionsPresetsConfigMixin', + 'invenio_records_resources.services.RecordServiceConfig{InvenioRecordServiceConfig}'], + 'class': 'test.services.records.config.TestServiceConfig', + 'components': [], + 'config-key': 'TEST_RECORD_SERVICE_CONFIG', + 'extra-code': '', + 'generate': True, + 'module': 'test.services.records.config', + 'service-id': 'test'}, + 'sortable': [], + 'type': 'model', + 'ui': {'marshmallow': { + 'base-classes': ['oarepo_runtime.services.schema.ui.InvenioUISchema'], + 'class': 'test.services.records.ui_schema.TestUISchema', + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.services.records.ui_schema'}}} != { + 'api-blueprint': {'alias': 'test', + 'extra_code': '', + 'function': 'test.views.records.api.create_api_blueprint', + 'generate': True, + 'imports': [], + 'module': 'test.views.records.api'}, + 'app-blueprint': {'alias': 'test', + 'extra_code': '', + 'function': 'test.views.records.app.create_app_blueprint', + 'generate': True, + 'imports': [], + 'module': 'test.views.records.app'}, + 'config': {'extra_code': '', + 'generate': True, + 'imports': [], + 'module': 'test.config'}, + 'edtf-interval-dumper': { + 'base-classes': ['oarepo_runtime.records.dumpers.edtf_interval.EDTFIntervalDumperExt'], + 'class': 'test.records.dumpers.edtf.TestEDTFIntervalDumperExt', + 'extensions': [], + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.records.dumpers.edtf'}, + 'ext': {'alias': 'test', + 'base-classes': [], + 'class': 'test.ext.TestExt', + 'extra_code': '', + 'generate': True, + 'imports': [], + 'module': 'test.ext'}, + 'ext-resource': {'generate': True, 'skip': False}, + 'facets': {'extra-code': '', + 'generate': True, + 'groups': True, + 'module': 'test.services.records.facets'}, + 'json-schema-settings': {'alias': 'test', + 'file': 'test/records/jsonschemas/test-1.0.0.json', + 'generate': True, + 'module': 'test.records.jsonschemas', + 'name': 'test-1.0.0.json', + 'version': '1.0.0'}, + 'json-serializer': {'base-classes': ['oarepo_runtime.resources.LocalizedUIJSONSerializer'], + 'class': 'test.resources.records.ui.TestUIJSONSerializer', + 'extra-code': '', + 'format_serializer_cls': 'flask_resources.serializers.JSONSerializer', + 'generate': True, + 'imports': [], + 'list_schema_cls': 'flask_resources.BaseListSchema', + 'module': 'test.resources.records.ui', + 'schema-context-args': {'"identity"': '{{ ' + 'flask.g{g.identity} ' + '}}', + '"object_key"': '"ui"'}}, + 'mapping': {'alias': 'test', + 'file': 'test/records/mappings/os-v2/test/test-1.0.0.json', + 'generate': True, + 'index': 'test-test-1.0.0', + 'index-field-args': [], + 'module': 'test.records.mappings'}, + 'marshmallow': {'base-classes': ['oarepo_runtime.services.schema.marshmallow.BaseRecordSchema'], + 'class': 'test.services.records.schema.TestSchema', + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.services.records.schema'}, + 'model-name': 'Test', + 'module': {'alias': 'test', + 'base': 'test', + 'base-title': 'Test', + 'base-upper': 'TEST', + 'kebab-module': 'test', + 'path': 'test', + 'prefix': 'Test', + 'prefix-snake': 'test', + 'prefix-upper': 'TEST', + 'qualified': 'test', + 'suffix': 'test', + 'suffix-snake': 'test', + 'suffix-upper': 'TEST'}, + 'permissions': {'base-classes': ['invenio_records_permissions.RecordPermissionPolicy'], + 'class': 'test.services.records.permissions.TestPermissionPolicy', + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.services.records.permissions', + 'presets': ['everyone']}, + 'pid': {'context-class': 'invenio_records_resources.records.systemfields.pid.PIDFieldContext', + 'extra-code': '', + 'field-args': ['create=True'], + 'field-class': 'invenio_records_resources.records.systemfields.pid.PIDField', + 'generate': True, + 'imports': [], + 'module': 'test.records.api', + 'provider-base-classes': ['invenio_pidstore.providers.recordid_v2.RecordIdProviderV2'], + 'provider-class': 'test.records.api.TestIdProvider', + 'type': 'test'}, + 'properties': {'$schema': {'facets': {'facet': False, 'searchable': True}, + 'marshmallow': {'read': False, 'write': False}, + 'sample': {'skip': True}, + 'type': 'keyword', + 'ui': {'marshmallow': {'read': False, + 'write': False}}}, + 'created': {'facets': {'facet': False, 'searchable': True}, + 'marshmallow': {'read': False, 'write': False}, + 'sample': {'skip': True}, + 'type': 'datetime', + 'ui': {'marshmallow': {'read': False, + 'write': False}}}, + 'id': {'facets': {'facet': False, 'searchable': True}, + 'marshmallow': {'read': False, 'write': False}, + 'sample': {'skip': True}, + 'type': 'keyword', + 'ui': {'marshmallow': {'read': False, 'write': False}}}, + 'pid': {'facets': {'facet': False, 'searchable': True}, + 'marshmallow': {'class': 'test.services.records.schema.FakePIDSchema', + 'generate': False, + 'read': False, + 'skip': True, + 'write': False}, + 'properties': {'obj_type': {'facets': {'facet': False, + 'searchable': True}, + 'type': 'keyword'}, + 'pid_type': {'facets': {'facet': False, + 'searchable': True}, + 'type': 'keyword'}, + 'pk': {'facets': {'facet': False, + 'searchable': True}, + 'type': 'integer'}, + 'status': {'facets': {'facet': False, + 'searchable': True}, + 'type': 'keyword'}}, + 'sample': {'skip': True}, + 'type': 'object', + 'ui': {'marshmallow': {'class': 'test.services.records.ui_schema.FakeUIPIDSchema', + 'generate': False, + 'read': False, + 'skip': True, + 'write': False}}}, + 'updated': {'facets': {'facet': False, 'searchable': True}, + 'marshmallow': {'read': False, 'write': False}, + 'sample': {'skip': True}, + 'type': 'datetime', + 'ui': {'marshmallow': {'read': False, + 'write': False}}}}, + 'proxy': {'generate': True, 'module': 'test.proxies'}, + 'record': {'base-classes': ['invenio_records_resources.records.api.Record{InvenioRecord}'], + 'class': 'test.records.api.TestRecord', + 'extra-code': '', + 'fields': {}, + 'generate': True, + 'imports': [], + 'module': 'test.records.api'}, + 'record-dumper': {'base-classes': ['oarepo_runtime.records.dumpers.SearchDumper'], + 'class': 'test.records.dumpers.dumper.TestDumper', + 'extensions': ['{{test.records.dumpers.edtf.TestEDTFIntervalDumperExt}}()'], + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.records.dumpers.dumper'}, + 'record-item': {'base-classes': ['oarepo_runtime.services.results.RecordItem'], + 'class': 'test.services.records.results.TestRecordItem', + 'components': [], + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.services.records.results'}, + 'record-list': {'base-classes': ['oarepo_runtime.services.results.RecordList'], + 'class': 'test.services.records.results.TestRecordList', + 'components': [], + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.services.records.results'}, + 'record-metadata': {'alembic': 'test.alembic', + 'alias': 'test', + 'base-classes': ['invenio_db.db{db.Model}', + 'invenio_records.models.RecordMetadataBase'], + 'class': 'test.records.models.TestMetadata', + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.records.models', + 'table': 'test_metadata', + 'use-versioning': True}, + 'resource': {'additional-args': [], + 'base-classes': ['invenio_records_resources.resources.RecordResource'], + 'class': 'test.resources.records.resource.TestResource', + 'config-key': 'TEST_RECORD_RESOURCE_CLASS', + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.resources.records.resource', + 'proxy': 'current_resource'}, + 'resource-config': {'additional-args': [], + 'base-classes': ['invenio_records_resources.resources.RecordResourceConfig'], + 'base-html-url': '/test/', + 'base-url': '/test/', + 'class': 'test.resources.records.config.TestResourceConfig', + 'config-key': 'TEST_RECORD_RESOURCE_CONFIG', + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.resources.records.config'}, + 'sample': {'file': 'data/sample_data.yaml'}, + 'saved-model': {'alias': 'test', + 'file': 'test/models/records.json', + 'module': 'test.models'}, + 'search-options': { + 'base-classes': ['invenio_records_resources.services.SearchOptions{InvenioSearchOptions}'], + 'class': 'test.services.records.search.TestSearchOptions', + 'extra-code': '', + 'fields': {}, + 'generate': True, + 'imports': [], + 'module': 'test.services.records.search', + 'sort-options-field': 'sort_options'}, + 'searchable': True, + 'service': {'additional-args': [], + 'base-classes': ['invenio_records_resources.services.RecordService{InvenioRecordService}'], + 'class': 'test.services.records.service.TestService', + 'config-key': 'TEST_RECORD_SERVICE_CLASS', + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.services.records.service', + 'proxy': 'current_service'}, + 'service-config': {'additional-args': [], + 'base-classes': [ + 'oarepo_runtime.services.config.service.PermissionsPresetsConfigMixin', + 'invenio_records_resources.services.RecordServiceConfig{InvenioRecordServiceConfig}'], + 'class': 'test.services.records.config.TestServiceConfig', + 'components': [], + 'config-key': 'TEST_RECORD_SERVICE_CONFIG', + 'extra-code': '', + 'generate': True, + 'module': 'test.services.records.config', + 'service-id': 'test'}, + 'sortable': [], + 'type': 'model', + 'ui': {'marshmallow': {'base-classes': ['oarepo_runtime.services.schema.ui.InvenioUISchema'], + 'class': 'test.services.records.ui_schema.TestUISchema', + 'extra-code': '', + 'generate': True, + 'imports': [], + 'module': 'test.services.records.ui_schema'}}} diff --git a/tests/test_raw.py b/tests/test_raw.py index d9644ce..c835c8e 100644 --- a/tests/test_raw.py +++ b/tests/test_raw.py @@ -36,7 +36,9 @@ def test_raw_type(): import marshmallow as ma from marshmallow import fields as ma_fields from oarepo_runtime.services.schema.marshmallow import BaseRecordSchema -class TestSchema(BaseRecordSchema): +from oarepo_runtime.services.schema.rdm import RDMRecordMixin + +class TestSchema(BaseRecordSchema, RDMRecordMixin): class Meta: unknown = ma.RAISE a = ma_fields.Dict() diff --git a/tests/test_schema_props.py b/tests/test_schema_props.py index 0344abb..5f4114e 100644 --- a/tests/test_schema_props.py +++ b/tests/test_schema_props.py @@ -50,7 +50,7 @@ def test_enum(): assert ( strip_whitespaces( """ -class TestSchema(BaseRecordSchema): +class TestSchema(BaseRecordSchema, RDMRecordMixin): class Meta: unknown = ma.RAISE diff --git a/tests/test_shortcuts.py b/tests/test_shortcuts.py index 27484b1..3a91351 100644 --- a/tests/test_shortcuts.py +++ b/tests/test_shortcuts.py @@ -35,7 +35,7 @@ def test_array_shortcuts(): assert ( strip_whitespaces( """ -class TestSchema(BaseRecordSchema): +class TestSchema(BaseRecordSchema, RDMRecordMixin): class Meta: unknown = ma.RAISE diff --git a/tests/test_simple_builders.py b/tests/test_simple_builders.py index 9c642d0..5184b3f 100644 --- a/tests/test_simple_builders.py +++ b/tests/test_simple_builders.py @@ -88,8 +88,8 @@ def test_record_builder(): from invenio_records_resources.records.systemfields.pid import PIDFieldContext from test.records.models import TestMetadata from test.records.dumpers.dumper import TestDumper -from invenio_records_resources.records.api import Record as InvenioRecord -class TestRecord(InvenioRecord): +from invenio_rdm_records.records.api import RDMRecord +class TestRecord(RDMRecord): model_cls = TestMetadata schema = ConstantField("$schema", "local://test-1.0.0.json") index = IndexField("test-test-1.0.0",) @@ -123,12 +123,11 @@ def test_record_pid_provider_builder(): from invenio_records_resources.records.systemfields.pid import PIDFieldContext from test.records.models import TestMetadata from test.records.dumpers.dumper import TestDumper -from invenio_records_resources.records.api import Record as InvenioRecord - +from invenio_rdm_records.records.api import RDMRecord class TestIdProvider(RecordIdProviderV2): pid_type = "test" -class TestRecord(InvenioRecord): +class TestRecord(RDMRecord): model_cls = TestMetadata schema = ConstantField("$schema", "local://test-1.0.0.json") index = IndexField("test-test-1.0.0",) @@ -151,13 +150,13 @@ def test_record_metadata_builder(): ], os.path.join("test", "records", "models.py"), ) - + print(data) assert strip_whitespaces(data) == strip_whitespaces( ''' from invenio_db import db - - +from invenio_rdm_records.records.systemfields.deletion_status import RecordDeletionStatusEnum from invenio_records.models import RecordMetadataBase +from sqlalchemy_utils.types import ChoiceType class TestMetadata(db.Model, RecordMetadataBase): @@ -167,6 +166,12 @@ class TestMetadata(db.Model, RecordMetadataBase): # Enables SQLAlchemy-Continuum versioning __versioned__ = {} + + deletion_status = db.Column( + ChoiceType(RecordDeletionStatusEnum, impl=db.String(1)), + nullable=False, + default=RecordDeletionStatusEnum.PUBLISHED.value, + ) ''' ) @@ -361,9 +366,9 @@ def test_service_builder(): assert strip_whitespaces(data) == strip_whitespaces( ''' -from invenio_records_resources.services import RecordService as InvenioRecordService +from invenio_rdm_records.services.services import RDMRecordService -class TestService(InvenioRecordService): +class TestService(RDMRecordService): """TestRecord service.""" ''' )