<s> from django . http . request import QueryDict <EOL> from rest_framework import serializers <EOL> from ralph . api . tests . _base import RalphAPITestCase <EOL> from ralph . data_center . tests . factories import IPAddressFactory <EOL> from ralph . security . api import SaveSecurityScanSerializer <EOL> from ralph . security . tests . factories import ( <EOL> SecurityScanFactory , <EOL> VulnerabilityFactory <EOL> ) <EOL> class SaveSecurityScanSerializerTests ( RalphAPITestCase ) : <EOL> def setUp ( self ) : <EOL> super ( ) . setUp ( ) <EOL> self . security_scan = SecurityScanFactory ( ) <EOL> def _dict2QueryDict ( self , data_dict ) : <EOL> qdict = QueryDict ( '<STR_LIT>' , mutable = True ) <EOL> qdict . update ( data_dict ) <EOL> return qdict <EOL> def test_external_id_is_converted_to_local ( self ) : <EOL> ip = IPAddressFactory ( address = "<STR_LIT>" ) <EOL> vulnerability_1 = VulnerabilityFactory ( ) <EOL> vulnerability_2 = VulnerabilityFactory ( ) <EOL> data = self . _dict2QueryDict ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ip . address , <EOL> '<STR_LIT>' : vulnerability_1 . id , <EOL> '<STR_LIT>' : vulnerability_2 . external_vulnerability_id , <EOL> } ) <EOL> scan_serializer = SaveSecurityScanSerializer ( <EOL> context = { '<STR_LIT>' : None } ) <EOL> deserialized = scan_serializer . to_internal_value ( data ) <EOL> self . assertEqual ( <EOL> deserialized [ '<STR_LIT>' ] , <EOL> [ vulnerability_1 , vulnerability_2 ] , <EOL> ) <EOL> def test_error_raised_when_unknown_external_id ( self ) : <EOL> ip = IPAddressFactory ( address = "<STR_LIT>" ) <EOL> vulnerability = VulnerabilityFactory ( ) <EOL> data = self . _dict2QueryDict ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ip . address , <EOL> '<STR_LIT>' : vulnerability . id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> scan_serializer = SaveSecurityScanSerializer ( <EOL> context = { '<STR_LIT>' : None } ) <EOL> with self . assertRaises ( serializers . ValidationError ) : <EOL> scan_serializer . to_internal_value ( data ) </s>
