Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alzbeta Pokorna committed Oct 22, 2024
1 parent f7cb87b commit 2518dd1
Show file tree
Hide file tree
Showing 9 changed files with 563 additions and 386 deletions.
4 changes: 2 additions & 2 deletions tests/test_builder_from_entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions tests/test_datatype_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down Expand Up @@ -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,
Expand All @@ -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": [],
},
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 9 additions & 7 deletions tests/test_extend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
24 changes: 14 additions & 10 deletions tests/test_marshmallow_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()'''
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 2518dd1

Please sign in to comment.