<s> from django . test import TestCase <EOL> from ralph . assets . models import BaseObject <EOL> from ralph . data_importer . widgets import ( <EOL> ExportManyToManyStrTroughWidget , <EOL> ManyToManyThroughWidget <EOL> ) <EOL> from ralph . licences . models import BaseObjectLicence <EOL> from ralph . licences . tests . factories import ( <EOL> DataCenterAssetLicenceFactory , <EOL> LicenceFactory <EOL> ) <EOL> class ManyToManyThroughWidgetTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . licence = LicenceFactory ( ) <EOL> DataCenterAssetLicenceFactory . create_batch ( <NUM_LIT:3> , licence = self . licence ) <EOL> self . base_objects_ids = [ <EOL> bo . pk for bo in self . licence . base_objects . all ( ) <EOL> ] <EOL> self . widget = ManyToManyThroughWidget ( <EOL> model = BaseObjectLicence , <EOL> related_model = BaseObject , <EOL> through_field = '<STR_LIT>' <EOL> ) <EOL> def test_clean ( self ) : <EOL> result = self . widget . clean ( '<STR_LIT:U+002C>' . join ( map ( str , self . base_objects_ids ) ) ) <EOL> self . assertCountEqual ( <EOL> result , <EOL> BaseObject . objects . filter ( pk__in = self . base_objects_ids ) <EOL> ) <EOL> def test_clean_empty_value ( self ) : <EOL> result = self . widget . clean ( '<STR_LIT>' ) <EOL> self . assertCountEqual ( result , BaseObject . objects . none ( ) ) <EOL> self . assertEqual ( result . model , BaseObject ) <EOL> def test_render ( self ) : <EOL> result = self . widget . render ( self . licence . baseobjectlicence_set . all ( ) ) <EOL> self . assertCountEqual ( <EOL> map ( int , result . split ( '<STR_LIT:U+002C>' ) ) , self . base_objects_ids <EOL> ) <EOL> class ExportManyToManyStrThroughWidgetTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . licence = LicenceFactory ( ) <EOL> DataCenterAssetLicenceFactory . create_batch ( <NUM_LIT:3> , licence = self . licence ) <EOL> self . base_objects_ids = [ <EOL> bo . pk for bo in self . licence . base_objects . all ( ) <EOL> ] <EOL> self . widget = ExportManyToManyStrTroughWidget ( <EOL> model = BaseObjectLicence , <EOL> related_model = BaseObject , <EOL> through_field = '<STR_LIT>' <EOL> ) <EOL> def test_render ( self ) : <EOL> result = self . widget . render ( self . licence . baseobjectlicence_set . all ( ) ) <EOL> self . assertCountEqual ( result . split ( '<STR_LIT:U+002C>' ) , [ <EOL> str ( obj ) for obj in BaseObject . objects . filter ( <EOL> pk__in = self . base_objects_ids <EOL> ) <EOL> ] ) </s>
