#NEWLINE# def test_validation_with_size_limits( ) : #NEWLINE# #INDENT# class User ( Model ) : #NEWLINE# #INDENT# name = StringType ( ) #NEWLINE# #UNINDENT# class Card ( Model ) : #NEWLINE# #INDENT# users = ListType ( ModelType ( User ) , min_size = 1 , max_size = 2 , required = True ) #NEWLINE# #UNINDENT# with pytest . raises ( DataError ) as exception : #NEWLINE# #INDENT# c = Card ( { #NEWLINE# #INDENT# 'users' : None , #NEWLINE# #UNINDENT# } ) #NEWLINE# c . validate ( ) #NEWLINE# #UNINDENT# assert ( c . value . messages [ 'users' ] == [ 'This field is required.' ] ) #NEWLINE# with pytest . raises ( DataError ) as exception : #NEWLINE# #INDENT# c = Card ( { #NEWLINE# #INDENT# 'users' : [ ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# c . validate ( ) #NEWLINE# #UNINDENT# assert ( exception . value . messages [ 'users' ] == [ 'Please provide at least 1 item.' ] ) #NEWLINE# with pytest . raises ( DataError ) as exception : #NEWLINE# #INDENT# c = Card ( { #NEWLINE# #INDENT# 'users' : [ User ( ) , User ( ) , User ( ) ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# c . validate ( ) #NEWLINE# #UNINDENT# assert ( exception . value . messages [ 'users' ] == [ 'Please provide no more than 2 items.' ] )