def test_variants_none(self): class Example(Model): pass tag = Tag() tag._bind(Example) assert tag.variants() == [Example]
def test_variants_abstract(self): class Example(Model): class Meta: abstract = True class Example2(Example): pass tag = Tag(recurse=True) tag._bind(Example) assert tag.variants() == [Example2]
def test_variants_recurse(self): class Example(Model): pass class Example2(Example): pass class Example3(Example): pass tag = Tag(recurse=True) tag._bind(Example) assert tag.variants() == [Example, Example2, Example3]
def test_variants_basic(self): class Example(Model): pass class Example2(Example): pass class Example3(Example2): pass tag = Tag() tag._bind(Example) assert tag.variants() == [Example, Example2]
def test_lookup_tag(self): class Example(Model): pass if six.PY2: prefix = 'tests.test_tags' else: prefix = 'tests.test_tags.TestTag.test_lookup_tag.<locals>' assert Tag().lookup_tag(Example) == prefix + '.Example'
def test_serialize(self): class Example(Model): pass if six.PY2: prefix = 'tests.test_tags' else: prefix = 'tests.test_tags.TestTag.test_serialize.<locals>' assert Tag().serialize(Example) == prefix + '.Example'
def test_lookup_variant(self): class Example(Model): pass class Example2(Example): pass class Example3(Example): pass tag = Tag(recurse=True) tag._bind(Example) prefix = 'tests.test_tags.TestTag.test_lookup_variant.<locals>' assert tag.lookup_variant(prefix + '.Example') is Example assert tag.lookup_variant(prefix + '.Example2') is Example2 assert tag.lookup_variant(prefix + '.Example3') is Example3 assert tag.lookup_variant(prefix + '.Example4') is None
def test_deserialize(self): class Example(Model): pass class Example2(Example): pass class Example3(Example): pass tag = Tag(recurse=True) tag._bind(Example) prefix = 'tests.test_tags.TestTag.test_deserialize.<locals>' assert tag.deserialize(prefix + '.Example') is Example assert tag.deserialize(prefix + '.Example2') is Example2 assert tag.deserialize(prefix + '.Example3') is Example3 tag_value = prefix + '.Example4' with raises(ValidationError) as e: tag.deserialize(tag_value) assert e.value.messages() == 'no variant found'
def test___init___options(self): tag = Tag(recurse=True, serializers=[None], deserializers=[1, 2, 3]) assert tag.recurse is True assert tag.serializers == [None] assert tag.deserializers == [1, 2, 3]
def test___init___basic(self): tag = Tag() assert tag.recurse is False assert tag.serializers == [] assert tag.deserializers == []