From 3622c7dcfaeaf055318a22da7c2a791cb46766d2 Mon Sep 17 00:00:00 2001 From: Alzbeta Pokorna Date: Tue, 7 Jan 2025 13:38:50 +0100 Subject: [PATCH] additional rdm fields --- .../builtin_models/invenio.json | 168 ++++ .../components/marshmallow/object.py | 1 - setup.cfg | 2 +- tests/test_builder_from_entrypoints.py | 59 +- tests/test_model_saver.py | 891 +++++++++++------- tests/test_raw.py | 112 ++- tests/test_schema_props.py | 97 +- tests/test_shortcuts.py | 97 +- 8 files changed, 926 insertions(+), 501 deletions(-) diff --git a/oarepo_model_builder/builtin_models/invenio.json b/oarepo_model_builder/builtin_models/invenio.json index fa77297..9cf884b 100644 --- a/oarepo_model_builder/builtin_models/invenio.json +++ b/oarepo_model_builder/builtin_models/invenio.json @@ -130,6 +130,174 @@ } } }, + "is_published": { + "type": "boolean", + "marshmallow": { + "read": false, + "write": false + }, + "sample": { + "skip": true + }, + "facets": { + "searchable": true, + "facet": false + } + }, + "deletion_status": { + "type": "keyword", + "marshmallow": { + "read": false, + "write": false + }, + "sample": { + "skip": true + }, + "facets": { + "searchable": true, + "facet": false + } + }, + "version_id": { + "type": "integer", + "marshmallow": { + "read": false, + "write": false + }, + "sample": { + "skip": true + }, + "facets": { + "searchable": true, + "facet": false + } + }, + "is_deleted": { + "type": "boolean", + "marshmallow": { + "read": false, + "write": false + }, + "sample": { + "skip": true + }, + "facets": { + "searchable": true, + "facet": false + } + }, + "versions": { + "type": "object", + "marshmallow": { + "skip": true, + "read": false, + "write": false, + "generate": false, + "class": "FakeVersionsSchema" + }, + "ui": { + "marshmallow": { + "read": false, + "write": false, + "generate": false, + "skip": true, + "class": "FakeVersionsUISchema" + } + }, + "sample": { + "skip": true + }, + "facets": { + "searchable": true, + "facet": false + }, + "properties": { + "index": { + "type": "integer", + "marshmallow": { + "read": false, + "write": false + }, + "sample": { + "skip": true + }, + "facets": { + "searchable": true, + "facet": false + } + }, + "is_latest": { + "type": "boolean", + "marshmallow": { + "read": false, + "write": false + }, + "sample": { + "skip": true + }, + "facets": { + "searchable": true, + "facet": false + } + }, + "is_latest_draft": { + "type": "boolean", + "marshmallow": { + "read": false, + "write": false + }, + "sample": { + "skip": true + }, + "facets": { + "searchable": true, + "facet": false + } + }, + "latest_id": { + "type": "keyword", + "marshmallow": { + "read": false, + "write": false + }, + "sample": { + "skip": true + }, + "facets": { + "searchable": true, + "facet": false + } + }, + "latest_index": { + "type": "integer", + "marshmallow": { + "read": false, + "write": false + }, + "sample": { + "skip": true + }, + "facets": { + "searchable": true, + "facet": false + } + }, + "next_draft_id": { + "type": "keyword", + "marshmallow": { + "read": false, + "write": false + }, + "sample": { + "skip": true + }, + "facets": { + "searchable": true, + "facet": false + } + } + } + }, "$schema": { "type": "keyword", "marshmallow": { diff --git a/oarepo_model_builder/datatypes/components/marshmallow/object.py b/oarepo_model_builder/datatypes/components/marshmallow/object.py index 0b1d483..7142e3e 100644 --- a/oarepo_model_builder/datatypes/components/marshmallow/object.py +++ b/oarepo_model_builder/datatypes/components/marshmallow/object.py @@ -98,7 +98,6 @@ def _build_class_name( ): schema_class = marshmallow_config.get("class") generate = marshmallow_config.get("generate", True) - if schema_class: qualified_schema_class = qualified_name(marshmallow_module, schema_class) if qualified_schema_class != schema_class: diff --git a/setup.cfg b/setup.cfg index d1e0495..5eeff3f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-model-builder -version = 4.0.99 +version = 4.0.100 description = A utility library that generates OARepo required data model files from a JSON specification file authors = Miroslav Bauer , Miroslav Simek readme = README.md diff --git a/tests/test_builder_from_entrypoints.py b/tests/test_builder_from_entrypoints.py index 0dd4c17..dc32d75 100644 --- a/tests/test_builder_from_entrypoints.py +++ b/tests/test_builder_from_entrypoints.py @@ -65,7 +65,7 @@ class Meta: data = builder.filesystem.open( os.path.join("test", "services", "records", "ui_schema.py") ).read() - print(data) + assert ( strip_whitespaces( """ @@ -84,32 +84,37 @@ class Meta: os.path.join("test", "records", "mappings", "os-v2", "test", "test-1.0.0.json") ) data = json.loads(data) - assert data == { - "mappings": { - "properties": { - "$schema": {"type": "keyword", "ignore_above": 1024}, - "a": {"type": "keyword", "ignore_above": 1024}, - "created": { - "type": "date", - "format": "strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction", - }, - "id": {"type": "keyword", "ignore_above": 1024}, - "pid": { - "properties": { - "obj_type": {"ignore_above": 1024, "type": "keyword"}, - "pid_type": {"ignore_above": 1024, "type": "keyword"}, - "pk": {"type": "integer"}, - "status": {"ignore_above": 1024, "type": "keyword"}, - }, - "type": "object", - }, - "updated": { - "type": "date", - "format": "strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction", - }, - }, - } - } + print(data) + assert data == {'mappings': {'properties': {'$schema': {'ignore_above': 1024, + 'type': 'keyword'}, + 'a': {'ignore_above': 1024, 'type': 'keyword'}, + 'created': {'format': 'strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction', + 'type': 'date'}, + 'deletion_status': {'ignore_above': 1024, + 'type': 'keyword'}, + 'id': {'ignore_above': 1024, 'type': 'keyword'}, + 'is_deleted': {'type': 'boolean'}, + 'is_published': {'type': 'boolean'}, + 'pid': {'properties': {'obj_type': {'ignore_above': 1024, + 'type': 'keyword'}, + 'pid_type': {'ignore_above': 1024, + 'type': 'keyword'}, + 'pk': {'type': 'integer'}, + 'status': {'ignore_above': 1024, + 'type': 'keyword'}}, + 'type': 'object'}, + 'updated': {'format': 'strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction', + 'type': 'date'}, + 'version_id': {'type': 'integer'}, + 'versions': {'properties': {'index': {'type': 'integer'}, + 'is_latest': {'type': 'boolean'}, + 'is_latest_draft': {'type': 'boolean'}, + 'latest_id': {'ignore_above': 1024, + 'type': 'keyword'}, + 'latest_index': {'type': 'integer'}, + 'next_draft_id': {'ignore_above': 1024, + 'type': 'keyword'}}, + 'type': 'object'}}}} data = builder.filesystem.read("setup.cfg") assert "version = 1.0.0" in data diff --git a/tests/test_model_saver.py b/tests/test_model_saver.py index 10f7c0c..f7e07ed 100644 --- a/tests/test_model_saver.py +++ b/tests/test_model_saver.py @@ -394,340 +394,557 @@ 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, 'service-kwargs': {}, "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": [], - "search-item-links-template-cls": "invenio_records_resources.services.LinksTemplate", - }, - "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, 'service-kwargs': {}, '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}}}, + 'deletion_status': {'facets': {'facet': False, + 'searchable': True}, + 'marshmallow': {'read': False, + 'write': False}, + 'sample': {'skip': True}, + 'type': 'keyword'}, + 'id': {'facets': {'facet': False, 'searchable': True}, + 'marshmallow': {'read': False, 'write': False}, + 'sample': {'skip': True}, + 'type': 'keyword', + 'ui': {'marshmallow': {'read': False, 'write': False}}}, + 'is_deleted': {'facets': {'facet': False, 'searchable': True}, + 'marshmallow': {'read': False, 'write': False}, + 'sample': {'skip': True}, + 'type': 'boolean'}, + 'is_published': {'facets': {'facet': False, 'searchable': True}, + 'marshmallow': {'read': False, 'write': False}, + 'sample': {'skip': True}, + 'type': 'boolean'}, + '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}}}, + 'version_id': {'facets': {'facet': False, 'searchable': True}, + 'marshmallow': {'read': False, 'write': False}, + 'sample': {'skip': True}, + 'type': 'integer'}, + 'versions': {'facets': {'facet': False, 'searchable': True}, + 'marshmallow': {'class': 'test.services.records.schema.FakeVersionsSchema', + 'generate': False, + 'read': False, + 'skip': True, + 'write': False}, + 'properties': {'index': {'facets': {'facet': False, + 'searchable': True}, + 'marshmallow': {'read': False, + 'write': False}, + 'sample': {'skip': True}, + 'type': 'integer'}, + 'is_latest': {'facets': {'facet': False, + 'searchable': True}, + 'marshmallow': {'read': False, + 'write': False}, + 'sample': {'skip': True}, + 'type': 'boolean'}, + 'is_latest_draft': {'facets': {'facet': False, + 'searchable': True}, + 'marshmallow': {'read': False, + 'write': False}, + 'sample': {'skip': True}, + 'type': 'boolean'}, + 'latest_id': {'facets': {'facet': False, + 'searchable': True}, + 'marshmallow': {'read': False, + 'write': False}, + 'sample': {'skip': True}, + 'type': 'keyword'}, + 'latest_index': {'facets': {'facet': False, + 'searchable': True}, + 'marshmallow': {'read': False, + 'write': False}, + 'sample': {'skip': True}, + 'type': 'integer'}, + 'next_draft_id': {'facets': {'facet': False, + 'searchable': True}, + 'marshmallow': {'read': False, + 'write': False}, + 'sample': {'skip': True}, + 'type': 'keyword'}}, + 'sample': {'skip': True}, + 'type': 'object', + 'ui': {'marshmallow': {'class': 'test.services.records.ui_schema.FakeVersionsUISchema', + 'generate': False, + 'read': False, + 'skip': True, + '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', + 'search-item-links-template-cls': 'invenio_records_resources.services.LinksTemplate', + '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, 'service-kwargs': {}, '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', + 'search-item-links-template-cls': 'invenio_records_resources.services.LinksTemplate', + '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..7a41c4f 100644 --- a/tests/test_raw.py +++ b/tests/test_raw.py @@ -50,53 +50,75 @@ class Meta: ) data = json.loads(data) - assert data == { - "mappings": { - "properties": { - "a": {"type": "flat_object"}, - "id": {"type": "keyword", "ignore_above": 1024}, - "pid": { - "properties": { - "obj_type": {"ignore_above": 1024, "type": "keyword"}, - "pid_type": {"ignore_above": 1024, "type": "keyword"}, - "pk": {"type": "integer"}, - "status": {"ignore_above": 1024, "type": "keyword"}, - }, - "type": "object", - }, - "created": { - "type": "date", - "format": "strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction", - }, - "updated": { - "type": "date", - "format": "strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction", - }, - "$schema": {"type": "keyword", "ignore_above": 1024}, - }, - } - } + assert data == {'mappings': {'properties': {'$schema': {'ignore_above': 1024, + 'type': 'keyword'}, + 'a': {'type': 'flat_object'}, + 'created': {'format': 'strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction', + 'type': 'date'}, + 'deletion_status': {'ignore_above': 1024, + 'type': 'keyword'}, + 'id': {'ignore_above': 1024, 'type': 'keyword'}, + 'is_deleted': {'type': 'boolean'}, + 'is_published': {'type': 'boolean'}, + 'pid': {'properties': {'obj_type': {'ignore_above': 1024, + 'type': 'keyword'}, + 'pid_type': {'ignore_above': 1024, + 'type': 'keyword'}, + 'pk': {'type': 'integer'}, + 'status': {'ignore_above': 1024, + 'type': 'keyword'}}, + 'type': 'object'}, + 'updated': {'format': 'strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction', + 'type': 'date'}, + 'version_id': {'type': 'integer'}, + 'versions': {'properties': {'index': {'type': 'integer'}, + 'is_latest': {'type': 'boolean'}, + 'is_latest_draft': {'type': 'boolean'}, + 'latest_id': {'ignore_above': 1024, + 'type': 'keyword'}, + 'latest_index': {'type': 'integer'}, + 'next_draft_id': {'ignore_above': 1024, + 'type': 'keyword'}}, + 'type': 'object'}}}} != {'mappings': {'properties': {'$schema': {'ignore_above': 1024, + 'type': 'keyword'}, + 'a': {'type': 'flat_object'}, + 'created': {'format': 'strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction', + 'type': 'date'}, + 'id': {'ignore_above': 1024, 'type': 'keyword'}, + 'pid': {'properties': {'obj_type': {'ignore_above': 1024, + 'type': 'keyword'}, + 'pid_type': {'ignore_above': 1024, + 'type': 'keyword'}, + 'pk': {'type': 'integer'}, + 'status': {'ignore_above': 1024, + 'type': 'keyword'}}, + 'type': 'object'}, + 'updated': {'format': 'strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction', + 'type': 'date'}}}} data = builder.filesystem.read( os.path.join("test", "records", "jsonschemas", "test-1.0.0.json") ) data = json.loads(data) - assert data == { - "properties": { - "a": {"type": "object"}, - "id": {"type": "string"}, - "pid": { - "properties": { - "obj_type": {"type": "string"}, - "pid_type": {"type": "string"}, - "pk": {"type": "integer"}, - "status": {"type": "string"}, - }, - "type": "object", - }, - "created": {"type": "string", "format": "date-time"}, - "updated": {"type": "string", "format": "date-time"}, - "$schema": {"type": "string"}, - }, - "type": "object", - } + assert data == {'properties': {'$schema': {'type': 'string'}, + 'a': {'type': 'object'}, + 'created': {'format': 'date-time', 'type': 'string'}, + 'deletion_status': {'type': 'string'}, + 'id': {'type': 'string'}, + 'is_deleted': {'type': 'boolean'}, + 'is_published': {'type': 'boolean'}, + 'pid': {'properties': {'obj_type': {'type': 'string'}, + 'pid_type': {'type': 'string'}, + 'pk': {'type': 'integer'}, + 'status': {'type': 'string'}}, + 'type': 'object'}, + 'updated': {'format': 'date-time', 'type': 'string'}, + 'version_id': {'type': 'integer'}, + 'versions': {'properties': {'index': {'type': 'integer'}, + 'is_latest': {'type': 'boolean'}, + 'is_latest_draft': {'type': 'boolean'}, + 'latest_id': {'type': 'string'}, + 'latest_index': {'type': 'integer'}, + 'next_draft_id': {'type': 'string'}}, + 'type': 'object'}}, + 'type': 'object'} diff --git a/tests/test_schema_props.py b/tests/test_schema_props.py index 0344abb..9f7278e 100644 --- a/tests/test_schema_props.py +++ b/tests/test_schema_props.py @@ -66,53 +66,60 @@ class Meta: os.path.join("test", "records", "jsonschemas", "test-1.0.0.json") ) data = json.loads(data) - assert data == { - "properties": { - "$schema": {"type": "string"}, - "a": {"type": "string"}, - "created": {"format": "date-time", "type": "string"}, - "id": {"type": "string"}, - "pid": { - "properties": { - "obj_type": {"type": "string"}, - "pid_type": {"type": "string"}, - "pk": {"type": "integer"}, - "status": {"type": "string"}, - }, - "type": "object", - }, - "updated": {"format": "date-time", "type": "string"}, - }, - "type": "object", - } + assert data == {'properties': {'$schema': {'type': 'string'}, + 'a': {'type': 'string'}, + 'created': {'format': 'date-time', 'type': 'string'}, + 'deletion_status': {'type': 'string'}, + 'id': {'type': 'string'}, + 'is_deleted': {'type': 'boolean'}, + 'is_published': {'type': 'boolean'}, + 'pid': {'properties': {'obj_type': {'type': 'string'}, + 'pid_type': {'type': 'string'}, + 'pk': {'type': 'integer'}, + 'status': {'type': 'string'}}, + 'type': 'object'}, + 'updated': {'format': 'date-time', 'type': 'string'}, + 'version_id': {'type': 'integer'}, + 'versions': {'properties': {'index': {'type': 'integer'}, + 'is_latest': {'type': 'boolean'}, + 'is_latest_draft': {'type': 'boolean'}, + 'latest_id': {'type': 'string'}, + 'latest_index': {'type': 'integer'}, + 'next_draft_id': {'type': 'string'}}, + 'type': 'object'}}, + 'type': 'object'} data = builder.filesystem.read( os.path.join("test", "records", "mappings", "os-v2", "test", "test-1.0.0.json") ) data = json.loads(data) - assert data == { - "mappings": { - "properties": { - "$schema": {"type": "keyword", "ignore_above": 1024}, - "a": {"type": "keyword", "ignore_above": 1024}, - "created": { - "type": "date", - "format": "strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction", - }, - "id": {"type": "keyword", "ignore_above": 1024}, - "pid": { - "properties": { - "obj_type": {"ignore_above": 1024, "type": "keyword"}, - "pid_type": {"ignore_above": 1024, "type": "keyword"}, - "pk": {"type": "integer"}, - "status": {"ignore_above": 1024, "type": "keyword"}, - }, - "type": "object", - }, - "updated": { - "type": "date", - "format": "strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction", - }, - } - } - } + assert data == {'mappings': {'properties': {'$schema': {'ignore_above': 1024, + 'type': 'keyword'}, + 'a': {'ignore_above': 1024, 'type': 'keyword'}, + 'created': {'format': 'strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction', + 'type': 'date'}, + 'deletion_status': {'ignore_above': 1024, + 'type': 'keyword'}, + 'id': {'ignore_above': 1024, 'type': 'keyword'}, + 'is_deleted': {'type': 'boolean'}, + 'is_published': {'type': 'boolean'}, + 'pid': {'properties': {'obj_type': {'ignore_above': 1024, + 'type': 'keyword'}, + 'pid_type': {'ignore_above': 1024, + 'type': 'keyword'}, + 'pk': {'type': 'integer'}, + 'status': {'ignore_above': 1024, + 'type': 'keyword'}}, + 'type': 'object'}, + 'updated': {'format': 'strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction', + 'type': 'date'}, + 'version_id': {'type': 'integer'}, + 'versions': {'properties': {'index': {'type': 'integer'}, + 'is_latest': {'type': 'boolean'}, + 'is_latest_draft': {'type': 'boolean'}, + 'latest_id': {'ignore_above': 1024, + 'type': 'keyword'}, + 'latest_index': {'type': 'integer'}, + 'next_draft_id': {'ignore_above': 1024, + 'type': 'keyword'}}, + 'type': 'object'}}}} diff --git a/tests/test_shortcuts.py b/tests/test_shortcuts.py index 27484b1..c39ada7 100644 --- a/tests/test_shortcuts.py +++ b/tests/test_shortcuts.py @@ -51,56 +51,63 @@ class Meta: os.path.join("test", "records", "mappings", "os-v2", "test", "test-1.0.0.json") ) data = json.loads(data) - assert data == { - "mappings": { - "properties": { - "$schema": {"type": "keyword", "ignore_above": 1024}, - "a": {"type": "keyword", "ignore_above": 1024}, - "created": { - "type": "date", - "format": "strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction", - }, - "id": {"type": "keyword", "ignore_above": 1024}, - "pid": { - "properties": { - "obj_type": {"ignore_above": 1024, "type": "keyword"}, - "pid_type": {"ignore_above": 1024, "type": "keyword"}, - "pk": {"type": "integer"}, - "status": {"ignore_above": 1024, "type": "keyword"}, - }, - "type": "object", - }, - "updated": { - "type": "date", - "format": "strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction", - }, - } - } - } + assert data == {'mappings': {'properties': {'$schema': {'ignore_above': 1024, + 'type': 'keyword'}, + 'a': {'ignore_above': 1024, 'type': 'keyword'}, + 'created': {'format': 'strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction', + 'type': 'date'}, + 'deletion_status': {'ignore_above': 1024, + 'type': 'keyword'}, + 'id': {'ignore_above': 1024, 'type': 'keyword'}, + 'is_deleted': {'type': 'boolean'}, + 'is_published': {'type': 'boolean'}, + 'pid': {'properties': {'obj_type': {'ignore_above': 1024, + 'type': 'keyword'}, + 'pid_type': {'ignore_above': 1024, + 'type': 'keyword'}, + 'pk': {'type': 'integer'}, + 'status': {'ignore_above': 1024, + 'type': 'keyword'}}, + 'type': 'object'}, + 'updated': {'format': 'strict_date_time||strict_date_time_no_millis||basic_date_time||basic_date_time_no_millis||basic_date||strict_date||strict_date_hour_minute_second||strict_date_hour_minute_second_fraction', + 'type': 'date'}, + 'version_id': {'type': 'integer'}, + 'versions': {'properties': {'index': {'type': 'integer'}, + 'is_latest': {'type': 'boolean'}, + 'is_latest_draft': {'type': 'boolean'}, + 'latest_id': {'ignore_above': 1024, + 'type': 'keyword'}, + 'latest_index': {'type': 'integer'}, + 'next_draft_id': {'ignore_above': 1024, + 'type': 'keyword'}}, + 'type': 'object'}}}} data = builder.filesystem.read( os.path.join("test", "records", "jsonschemas", "test-1.0.0.json") ) data = json.loads(data) - assert data == { - "properties": { - "$schema": {"type": "string"}, - "a": {"items": {"type": "string"}, "type": "array"}, - "created": {"format": "date-time", "type": "string"}, - "id": {"type": "string"}, - "pid": { - "properties": { - "obj_type": {"type": "string"}, - "pid_type": {"type": "string"}, - "pk": {"type": "integer"}, - "status": {"type": "string"}, - }, - "type": "object", - }, - "updated": {"format": "date-time", "type": "string"}, - }, - "type": "object", - } + assert data == {'properties': {'$schema': {'type': 'string'}, + 'a': {'items': {'type': 'string'}, 'type': 'array'}, + 'created': {'format': 'date-time', 'type': 'string'}, + 'deletion_status': {'type': 'string'}, + 'id': {'type': 'string'}, + 'is_deleted': {'type': 'boolean'}, + 'is_published': {'type': 'boolean'}, + 'pid': {'properties': {'obj_type': {'type': 'string'}, + 'pid_type': {'type': 'string'}, + 'pk': {'type': 'integer'}, + 'status': {'type': 'string'}}, + 'type': 'object'}, + 'updated': {'format': 'date-time', 'type': 'string'}, + 'version_id': {'type': 'integer'}, + 'versions': {'properties': {'index': {'type': 'integer'}, + 'is_latest': {'type': 'boolean'}, + 'is_latest_draft': {'type': 'boolean'}, + 'latest_id': {'type': 'string'}, + 'latest_index': {'type': 'integer'}, + 'next_draft_id': {'type': 'string'}}, + 'type': 'object'}}, + 'type': 'object'} def test_singleline_type_shortcut():