<s> """<STR_LIT>""" <EOL> from . import test_settings <EOL> from datetime import date <EOL> from rest_framework . serializers import ValidationError <EOL> from rest_framework import ISO_8601 <EOL> from rest_framework . serializers import CharField <EOL> from rest_framework . serializers import DateField <EOL> import pytest <EOL> from drf_compound_fields . fields import DictField <EOL> def test_to_internal_value_with_child ( ) : <EOL> """<STR_LIT>""" <EOL> field = DictField ( child = DateField ( ) ) <EOL> data = { "<STR_LIT:a>" : "<STR_LIT>" , "<STR_LIT:b>" : "<STR_LIT>" } <EOL> obj = field . to_internal_value ( data ) <EOL> assert { "<STR_LIT:a>" : date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , "<STR_LIT:b>" : date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:2> ) } == obj <EOL> def test_to_representation_with_child ( ) : <EOL> """<STR_LIT>""" <EOL> field = DictField ( child = DateField ( format = ISO_8601 ) ) <EOL> obj = { "<STR_LIT:a>" : date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , "<STR_LIT:b>" : date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:2> ) } <EOL> data = field . to_representation ( obj ) <EOL> assert { "<STR_LIT:a>" : "<STR_LIT>" , "<STR_LIT:b>" : "<STR_LIT>" } == data <EOL> def test_validate_non_dict ( ) : <EOL> """<STR_LIT>""" <EOL> field = DictField ( child = DateField ( ) ) <EOL> with pytest . raises ( ValidationError ) : <EOL> field . to_internal_value ( '<STR_LIT>' ) <EOL> def test_validate_elements_valid ( ) : <EOL> """<STR_LIT>""" <EOL> field = DictField ( child = CharField ( max_length = <NUM_LIT:5> ) ) <EOL> try : <EOL> field . to_internal_value ( { "<STR_LIT:a>" : "<STR_LIT:a>" , "<STR_LIT:b>" : "<STR_LIT:b>" , "<STR_LIT:c>" : "<STR_LIT:c>" } ) <EOL> except ValidationError : <EOL> assert False , "<STR_LIT>" <EOL> def test_validate_elements_invalid ( ) : <EOL> """<STR_LIT>""" <EOL> field = DictField ( child = CharField ( max_length = <NUM_LIT:5> ) ) <EOL> with pytest . raises ( ValidationError ) : <EOL> field . to_internal_value ( { "<STR_LIT:a>" : "<STR_LIT>" , "<STR_LIT:b>" : "<STR_LIT>" } ) </s>
