<commit_before><commit_msg>Add tests for polymorphic types<commit_after>"""
Tests of polymorphic behaviours
"""
import odin
from odin.resources import create_resource_from_dict


class AbstractResource(odin.Resource):
    class Meta:
        abstract = True
        namespace = "au.com.example.abstracts"
        type_field = "type"


class ResourceA(AbstractResource):
    class Meta:
        type_field = "type"


class ResourceB(AbstractResource):
    pass


def test_resolve_resource_using_full_type_field():
    actual = create_resource_from_dict(
        {"type": "au.com.example.abstracts.ResourceA"},
        AbstractResource,
        full_clean=False,
    )

    assert isinstance(actual, ResourceA)


def test_resolve_resource_using_partial_type_field():
    actual = create_resource_from_dict(
        {"type": "ResourceB"},
        AbstractResource,
        full_clean=False,
    )

    assert isinstance(actual, ResourceB)
{'fraction_non_alphanumeric': 0.0877005347593583, 'fraction_numerical': 0.0, 'mean_word_length': 3.633663366336634, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '485336', 'n_tokens_mistral': 276, 'n_tokens_neox': 261, 'n_words': 56}