<s> from six . moves import xrange <EOL> from testtools import TestCase <EOL> from kmip . core import utils <EOL> from kmip . core . messages . contents import ProtocolVersion <EOL> from kmip . core . messages . payloads import discover_versions <EOL> class TestDiscoverVersionsRequestPayload ( TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestDiscoverVersionsRequestPayload , self ) . setUp ( ) <EOL> self . protocol_versions_empty = list ( ) <EOL> self . protocol_versions_one = list ( ) <EOL> self . protocol_versions_one . append ( ProtocolVersion . create ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> self . protocol_versions_two = list ( ) <EOL> self . protocol_versions_two . append ( ProtocolVersion . create ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> self . protocol_versions_two . append ( ProtocolVersion . create ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> self . encoding_empty = utils . BytearrayStream ( ( <EOL> b'<STR_LIT>' ) ) <EOL> self . encoding_one = utils . BytearrayStream ( ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT:\x00>' ) ) <EOL> self . encoding_two = utils . BytearrayStream ( ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' ) ) <EOL> def tearDown ( self ) : <EOL> super ( TestDiscoverVersionsRequestPayload , self ) . tearDown ( ) <EOL> def test_init_with_none ( self ) : <EOL> discover_versions . DiscoverVersionsRequestPayload ( ) <EOL> def test_init_with_args ( self ) : <EOL> discover_versions . DiscoverVersionsRequestPayload ( <EOL> self . protocol_versions_empty ) <EOL> def test_validate_with_invalid_protocol_versions ( self ) : <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertRaisesRegexp ( <EOL> TypeError , "<STR_LIT>" , <EOL> discover_versions . DiscoverVersionsRequestPayload , ** kwargs ) <EOL> def test_validate_with_invalid_protocol_version ( self ) : <EOL> kwargs = { '<STR_LIT>' : [ '<STR_LIT>' ] } <EOL> self . assertRaisesRegexp ( <EOL> TypeError , "<STR_LIT>" , <EOL> discover_versions . DiscoverVersionsRequestPayload , ** kwargs ) <EOL> def _test_read ( self , stream , payload , protocol_versions ) : <EOL> payload . read ( stream ) <EOL> expected = len ( protocol_versions ) <EOL> observed = len ( payload . protocol_versions ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( <EOL> expected , observed ) <EOL> self . assertEqual ( expected , observed , msg ) <EOL> for i in xrange ( len ( protocol_versions ) ) : <EOL> expected = protocol_versions [ i ] <EOL> observed = payload . protocol_versions [ i ] <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( expected , observed ) <EOL> self . assertEqual ( expected , observed , msg ) <EOL> def test_read_with_empty_protocol_list ( self ) : <EOL> stream = self . encoding_empty <EOL> payload = discover_versions . DiscoverVersionsRequestPayload ( ) <EOL> protocol_versions = self . protocol_versions_empty <EOL> self . _test_read ( stream , payload , protocol_versions ) <EOL> def test_read_with_one_protocol_version ( self ) : <EOL> stream = self . encoding_one <EOL> payload = discover_versions . DiscoverVersionsRequestPayload ( ) <EOL> protocol_versions = self . protocol_versions_one <EOL> self . _test_read ( stream , payload , protocol_versions ) <EOL> def test_read_with_two_protocol_versions ( self ) : <EOL> stream = self . encoding_two <EOL> payload = discover_versions . DiscoverVersionsRequestPayload ( ) <EOL> protocol_versions = self . protocol_versions_two <EOL> self . _test_read ( stream , payload , protocol_versions ) <EOL> def _test_write ( self , payload , expected ) : <EOL> stream = utils . BytearrayStream ( ) <EOL> payload . write ( stream ) <EOL> length_expected = len ( expected ) <EOL> length_received = len ( stream ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( <EOL> length_expected , length_received ) <EOL> self . assertEqual ( length_expected , length_received , msg ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( expected , stream ) <EOL> self . assertEqual ( expected , stream , msg ) <EOL> def test_write_with_empty_protocol_list ( self ) : <EOL> payload = discover_versions . DiscoverVersionsRequestPayload ( <EOL> self . protocol_versions_empty ) <EOL> expected = self . encoding_empty <EOL> self . _test_write ( payload , expected ) <EOL> def test_write_with_one_protocol_version ( self ) : <EOL> payload = discover_versions . DiscoverVersionsRequestPayload ( <EOL> self . protocol_versions_one ) <EOL> expected = self . encoding_one <EOL> self . _test_write ( payload , expected ) <EOL> def test_write_with_two_protocol_versions ( self ) : <EOL> payload = discover_versions . DiscoverVersionsRequestPayload ( <EOL> self . protocol_versions_two ) <EOL> expected = self . encoding_two <EOL> self . _test_write ( payload , expected ) <EOL> class TestDiscoverVersionsResponsePayload ( TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestDiscoverVersionsResponsePayload , self ) . setUp ( ) <EOL> self . protocol_versions_empty = list ( ) <EOL> self . protocol_versions_one = list ( ) <EOL> self . protocol_versions_one . append ( ProtocolVersion . create ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> self . protocol_versions_two = list ( ) <EOL> self . protocol_versions_two . append ( ProtocolVersion . create ( <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> self . protocol_versions_two . append ( ProtocolVersion . create ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> self . encoding_empty = utils . BytearrayStream ( ( <EOL> b'<STR_LIT>' ) ) <EOL> self . encoding_one = utils . BytearrayStream ( ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT:\x00>' ) ) <EOL> self . encoding_two = utils . BytearrayStream ( ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' ) ) <EOL> def tearDown ( self ) : <EOL> super ( TestDiscoverVersionsResponsePayload , self ) . tearDown ( ) <EOL> def test_init_with_none ( self ) : <EOL> discover_versions . DiscoverVersionsResponsePayload ( ) <EOL> def test_init_with_args ( self ) : <EOL> discover_versions . DiscoverVersionsResponsePayload ( <EOL> self . protocol_versions_empty ) <EOL> def test_validate_with_invalid_protocol_versions ( self ) : <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertRaisesRegexp ( <EOL> TypeError , "<STR_LIT>" , <EOL> discover_versions . DiscoverVersionsResponsePayload , ** kwargs ) <EOL> def test_validate_with_invalid_protocol_version ( self ) : <EOL> kwargs = { '<STR_LIT>' : [ '<STR_LIT>' ] } <EOL> self . assertRaisesRegexp ( <EOL> TypeError , "<STR_LIT>" , <EOL> discover_versions . DiscoverVersionsResponsePayload , ** kwargs ) <EOL> def _test_read ( self , stream , payload , protocol_versions ) : <EOL> payload . read ( stream ) <EOL> expected = len ( protocol_versions ) <EOL> observed = len ( payload . protocol_versions ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( <EOL> expected , observed ) <EOL> self . assertEqual ( expected , observed , msg ) <EOL> for i in xrange ( len ( protocol_versions ) ) : <EOL> expected = protocol_versions [ i ] <EOL> observed = payload . protocol_versions [ i ] <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( expected , observed ) <EOL> self . assertEqual ( expected , observed , msg ) <EOL> def test_read_with_empty_protocol_list ( self ) : <EOL> stream = self . encoding_empty <EOL> payload = discover_versions . DiscoverVersionsResponsePayload ( ) <EOL> protocol_versions = self . protocol_versions_empty <EOL> self . _test_read ( stream , payload , protocol_versions ) <EOL> def test_read_with_one_protocol_version ( self ) : <EOL> stream = self . encoding_one <EOL> payload = discover_versions . DiscoverVersionsResponsePayload ( ) <EOL> protocol_versions = self . protocol_versions_one <EOL> self . _test_read ( stream , payload , protocol_versions ) <EOL> def test_read_with_two_protocol_versions ( self ) : <EOL> stream = self . encoding_two <EOL> payload = discover_versions . DiscoverVersionsResponsePayload ( ) <EOL> protocol_versions = self . protocol_versions_two <EOL> self . _test_read ( stream , payload , protocol_versions ) <EOL> def _test_write ( self , payload , expected ) : <EOL> stream = utils . BytearrayStream ( ) <EOL> payload . write ( stream ) <EOL> length_expected = len ( expected ) <EOL> length_received = len ( stream ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( <EOL> length_expected , length_received ) <EOL> self . assertEqual ( length_expected , length_received , msg ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( expected , stream ) <EOL> self . assertEqual ( expected , stream , msg ) <EOL> def test_write_with_empty_protocol_list ( self ) : <EOL> payload = discover_versions . DiscoverVersionsResponsePayload ( <EOL> self . protocol_versions_empty ) <EOL> expected = self . encoding_empty <EOL> self . _test_write ( payload , expected ) <EOL> def test_write_with_one_protocol_version ( self ) : <EOL> payload = discover_versions . DiscoverVersionsResponsePayload ( <EOL> self . protocol_versions_one ) <EOL> expected = self . encoding_one <EOL> self . _test_write ( payload , expected ) <EOL> def test_write_with_two_protocol_versions ( self ) : <EOL> payload = discover_versions . DiscoverVersionsResponsePayload ( <EOL> self . protocol_versions_two ) <EOL> expected = self . encoding_two <EOL> self . _test_write ( payload , expected ) </s>
