def test_optional_nested_entity_makes_all_its_fields_optional(): result = abstract_entity_tree.build(AggregateWithOptionalNested) assert result == AbstractEntityTree(root=EntityNode( name="aggregate_with_optional_nested", type=AggregateWithOptionalNested, children=( FieldNode(name="id", type=int, optional=False, children=(), is_identity=True), ValueObjectNode( name="wallet", type=NestedValueObject, optional=True, children=( FieldNode(name="amount", type=Decimal, optional=False, children=(), is_identity=False), FieldNode(name="currency", type=str, optional=False, children=(), is_identity=False), ), ), ), ))
def test_builds_simple_flat_entity(): result = abstract_entity_tree.build(SimpleFlat) assert result == AbstractEntityTree(root=EntityNode( name="simple_flat", type=SimpleFlat, optional=False, children=( FieldNode(name="guid", type=UUID, optional=False, children=(), is_identity=True), FieldNode(name="name", type=str, optional=True, children=(), is_identity=False), FieldNode(name="score", type=int, optional=False, children=(), is_identity=False), FieldNode(name="enumerated", type=DummyEnum, optional=False, children=(), is_identity=False), FieldNode(name="balance", type=Decimal, optional=True, children=(), is_identity=False), ), ))
def test_builds_aggregate_with_list_of_value_objects(): result = abstract_entity_tree.build(AggregateWithValueObjectList) assert result == AbstractEntityTree(root=EntityNode( name="aggregate_with_value_object_list", type=AggregateWithValueObjectList, optional=False, children=( FieldNode(name="id", type=int, optional=False, children=(), is_identity=True), ListOfValueObjectsNode( name="wallets", type=NestedValueObject, optional=False, children=( FieldNode(name="amount", type=Decimal, optional=False, children=(), is_identity=False), FieldNode(name="currency", type=str, optional=False, children=(), is_identity=False), ), ), ), ))
def test_builds_aggregate_with_embedded_entity_and_value_object(): result = abstract_entity_tree.build(SomeAggregate) assert result == AbstractEntityTree(root=EntityNode( name="some_aggregate", type=SomeAggregate, optional=False, children=( FieldNode(name="guid", type=UUID, optional=False, children=(), is_identity=True), EntityNode( name="nested", type=NestedEntity, children=( FieldNode(name="nested_guid", type=UUID, optional=False, children=(), is_identity=True), FieldNode(name="name", type=str, optional=True, children=(), is_identity=False), ), ), ValueObjectNode( name="balance", type=NestedValueObject, optional=False, children=( FieldNode(name="amount", type=Decimal, optional=False, children=(), is_identity=False), FieldNode(name="currency", type=str, optional=False, children=(), is_identity=False), ), ), ), ))
def __new__( mcs, name: str, bases: typing.Tuple[typing.Type, ...], namespace: dict, tvars=None, args=None, origin=None, extra=None, orig_bases=None, ) -> typing.Type: cls = super().__new__(mcs, name, bases, namespace, tvars=tvars, args=args, origin=origin, extra=extra, orig_bases=orig_bases) if not inspect.isabstract(cls): assert isinstance(getattr(cls, "registry", None), Registry) last_base_class_origin = getattr(bases[-1], "__origin__", None) assert (last_base_class_origin is ReadOnlyRepository or last_base_class_origin is Repository ) # TODO: komunikat? args = getattr(bases[-1], "__args__", None) if args: entity_cls, _identity_cls = args if entity_cls not in cls.registry.entities_to_aets: cls.registry.entities_to_aets[entity_cls] = build( entity_cls) if hasattr(cls, "prepare"): entity_cls, _identity_cls = bases[-1].__args__ cls.prepare(entity_cls) return cls