def test_stream_encode(self): """ Check encoding an assoc_ac produces the correct output """ pdu = A_ASSOCIATE_AC() pdu.Decode(a_associate_ac) s = pdu.Encode() self.assertEqual(s, a_associate_ac)
def test_new_encode(self): """ Check encoding using new generic method """ pdu = A_ASSOCIATE_AC() pdu.Decode(a_associate_ac) s = pdu.encode() self.assertEqual(s, a_associate_ac)
def test_decode_properties(self): """ Check decoding the assoc_ac stream produces the correct properties """ pdu = A_ASSOCIATE_AC() pdu.Decode(a_associate_ac) # Check AE titles self.assertEqual(pdu.reserved_aec.decode('utf-8'), 'ECHOSCU ') self.assertEqual(pdu.reserved_aet.decode('utf-8'), 'ANY-SCP ') self.assertTrue(isinstance(pdu.reserved_aec, bytes)) self.assertTrue(isinstance(pdu.reserved_aet, bytes)) # Check application_context_name property app_name = pdu.application_context_name self.assertTrue(isinstance(app_name, UID)) self.assertEqual(app_name, '1.2.840.10008.3.1.1.1') # Check presentation_context property contexts = pdu.presentation_context self.assertTrue(isinstance(contexts, list)) for context in contexts: self.assertTrue(isinstance(context, PresentationContextItemAC)) # Check user_information property user_info = pdu.user_information self.assertTrue(isinstance(user_info, UserInformationItem))
def test_generic_encode(self): """ Check using the new pdu.encode produces the correct output """ pdu = A_ASSOCIATE_AC() pdu.Decode(a_associate_ac) s = pdu.Encode() t = pdu.encode() self.assertEqual(s, t)
def test_decode_value_type(self): """ Check decoding an assoc_ac produces the correct transfer syntax """ pdu = A_ASSOCIATE_AC() pdu.Decode(a_associate_ac) context = pdu.presentation_context[0] syntax = context.transfer_syntax self.assertTrue(isinstance(syntax, UID)) self.assertTrue(syntax.is_transfer_syntax) self.assertEqual(syntax, UID('1.2.840.10008.1.2'))
def test_from_primitive(self): """ Check converting PDU to primitive """ orig = A_ASSOCIATE_AC() orig.Decode(a_associate_ac) primitive = orig.ToParams() new = A_ASSOCIATE_AC() new.FromParams(primitive) self.assertEqual(new, orig)
def test_property_setters(self): """Test the property setters""" # presentation_context pdu = A_ASSOCIATE_AC() pdu.Decode(a_associate_ac) role_selection = SCP_SCU_RoleSelectionSubItem() role_selection.sop_class_uid = '1.2.840.10008.1.1' role_selection.scu_role = 1 role_selection.scp_role = 1 pdu.user_information.user_data.append(role_selection) context = pdu.presentation_context[0] self.assertTrue(context.transfer_syntax == '1.2.840.10008.1.2')
def test_stream_decode_values_types(self): """ Check decoding an assoc_ac produces the correct presentation context """ pdu = A_ASSOCIATE_AC() pdu.Decode(a_associate_ac) # Check PresentationContextItemRQ attributes presentation_context = pdu.variable_items[1] self.assertEqual(presentation_context.item_type, 0x21) self.assertEqual(presentation_context.presentation_context_id, 0x0001) self.assertEqual(presentation_context.item_length, 25) self.assertEqual(presentation_context.result_reason, 0) self.assertTrue(isinstance(presentation_context.item_type, int)) self.assertTrue( isinstance(presentation_context.presentation_context_id, int)) self.assertTrue(isinstance(presentation_context.item_length, int))
def test_update_data(self): """ Check that updating the PDU data works correctly """ original = A_ASSOCIATE_AC() original.Decode(a_associate_ac) original.user_information.user_data = [ original.user_information.user_data[1] ] original.get_length() primitive = original.ToParams() new = A_ASSOCIATE_AC() new.FromParams(primitive) self.assertEqual(original, new)
def test_stream_decode_values_types(self): """ Check decoding an assoc_ac produces the correct application context """ pdu = A_ASSOCIATE_AC() pdu.Decode(a_associate_ac) app_context = pdu.variable_items[0] self.assertEqual(app_context.item_type, 0x10) self.assertEqual(app_context.item_length, 21) self.assertEqual(app_context.application_context_name, '1.2.840.10008.3.1.1.1') self.assertTrue(isinstance(app_context.item_type, int)) self.assertTrue(isinstance(app_context.item_length, int)) self.assertTrue(isinstance(app_context.application_context_name, UID)) self.assertEqual(app_context.application_context_name, '1.2.840.10008.3.1.1.1') self.assertTrue(isinstance(app_context.application_context_name, UID))
def test_stream_decode_values_types(self): """ Check decoding the assoc_ac stream produces the correct objects """ pdu = A_ASSOCIATE_AC() pdu.Decode(a_associate_ac) self.assertEqual(pdu.pdu_type, 0x02) self.assertEqual(pdu.pdu_length, 184) self.assertEqual(pdu.protocol_version, 0x0001) self.assertTrue(isinstance(pdu.pdu_type, int)) self.assertTrue(isinstance(pdu.pdu_length, int)) self.assertTrue(isinstance(pdu.protocol_version, int)) # Check VariableItems # The actual items will be tested separately self.assertTrue( isinstance(pdu.variable_items[0], ApplicationContextItem)) self.assertTrue( isinstance(pdu.variable_items[1], PresentationContextItemAC)) self.assertTrue(isinstance(pdu.variable_items[2], UserInformationItem))
def test_decode_value_type(self): """ Check decoding an assoc_rq produces the correct user information """ pdu = A_ASSOCIATE_AC() pdu.Decode(a_associate_ac) user_info = pdu.variable_items[2] self.assertEqual(user_info.item_type, 0x50) self.assertEqual(user_info.item_length, 58) self.assertTrue(isinstance(user_info.item_type, int)) self.assertTrue(isinstance(user_info.item_length, int)) self.assertTrue(isinstance(user_info.user_data, list)) # Test user items for item in user_info.user_data: # Maximum PDU Length (required) if isinstance(item, MaximumLengthSubItem): self.assertEqual(item.maximum_length_received, 16384) self.assertEqual(user_info.maximum_length, 16384) self.assertTrue(isinstance(item.maximum_length_received, int)) self.assertTrue(isinstance(user_info.maximum_length, int)) # Implementation Class UID (required) elif isinstance(item, ImplementationClassUIDSubItem): self.assertEqual(item.item_type, 0x52) self.assertEqual(item.item_length, 27) self.assertEqual(item.implementation_class_uid, UID('1.2.276.0.7230010.3.0.3.6.0')) self.assertTrue(isinstance(item.item_type, int)) self.assertTrue(isinstance(item.item_length, int)) self.assertTrue(isinstance(item.implementation_class_uid, UID)) # Implementation Version Name (optional) elif isinstance(item, ImplementationVersionNameSubItem): self.assertEqual(item.item_type, 0x55) self.assertEqual(item.item_length, 15) self.assertEqual(item.implementation_version_name, b'OFFIS_DCMTK_360') self.assertTrue(isinstance(item.item_type, int)) self.assertTrue(isinstance(item.item_length, int)) self.assertTrue( isinstance(item.implementation_version_name, bytes))
def test_decode_properties(self): """ Check decoding the stream produces the correct properties """ pdu = A_ASSOCIATE_AC() pdu.Decode(a_associate_ac) context = pdu.presentation_context[0] # Check ID property context_id = context.ID self.assertTrue(isinstance(context_id, int)) self.assertEqual(context_id, 1) # Check Result result = pdu.presentation_context[0].result_reason self.assertEqual(result, 0) self.assertTrue(isinstance(result, int)) # Check transfer syntax syntax = pdu.presentation_context[0].transfer_syntax self.assertTrue(syntax.is_transfer_syntax) self.assertTrue(isinstance(syntax, UID)) self.assertEqual(syntax, UID('1.2.840.10008.1.2'))
def test_to_primitive(self): """ Check converting PDU to primitive """ pdu = A_ASSOCIATE_AC() pdu.Decode(a_associate_ac) primitive = pdu.ToParams() self.assertEqual(primitive.application_context_name, UID('1.2.840.10008.3.1.1.1')) self.assertEqual(primitive.calling_ae_title, b'ECHOSCU ') self.assertEqual(primitive.called_ae_title, b'ANY-SCP ') # Test User Information for item in primitive.user_information: # Maximum PDU Length (required) if isinstance(item, MaximumLengthNegotiation): self.assertEqual(item.maximum_length_received, 16384) self.assertTrue(isinstance(item.maximum_length_received, int)) # Implementation Class UID (required) elif isinstance(item, ImplementationClassUIDNotification): self.assertEqual(item.implementation_class_uid, UID('1.2.276.0.7230010.3.0.3.6.0')) self.assertTrue(isinstance(item.implementation_class_uid, UID)) # Implementation Version Name (optional) elif isinstance(item, ImplementationVersionNameNotification): self.assertEqual(item.implementation_version_name, b'OFFIS_DCMTK_360') self.assertTrue( isinstance(item.implementation_version_name, bytes)) # Test Presentation Contexts for context in primitive.presentation_context_definition_list: self.assertEqual(context.ID, 1) self.assertEqual(context.TransferSyntax[0], UID('1.2.840.10008.1.2')) self.assertTrue(isinstance(primitive.application_context_name, UID)) self.assertTrue(isinstance(primitive.calling_ae_title, bytes)) self.assertTrue(isinstance(primitive.called_ae_title, bytes)) self.assertTrue(isinstance(primitive.user_information, list)) self.assertEqual(primitive.result, 0) self.assertEqual( len(primitive.presentation_context_definition_results_list), 1) # Not used by A-ASSOCIATE-AC or fixed value self.assertEqual(primitive.mode, "normal") self.assertEqual(primitive.responding_ae_title, primitive.called_ae_title) self.assertEqual(primitive.result_source, None) self.assertEqual(primitive.diagnostic, None) self.assertEqual(primitive.calling_presentation_address, None) self.assertEqual(primitive.called_presentation_address, None) self.assertEqual(primitive.responding_presentation_address, primitive.called_presentation_address) self.assertEqual(primitive.presentation_context_definition_list, []) self.assertEqual(primitive.presentation_requirements, "Presentation Kernel") self.assertEqual(primitive.session_requirements, "")
def test_string_output(self): """Test the string output""" pdu = A_ASSOCIATE_AC() pdu.Decode(a_associate_ac) self.assertTrue("Implicit VR Little Endian" in pdu.__str__()) self.assertTrue("1.2.276.0.7230010" in pdu.__str__())
def test_length_property(self): """ Check that the length property returns the correct value """ pdu = A_ASSOCIATE_AC() pdu.Decode(a_associate_ac) self.assertEqual(pdu.length, pdu.get_length())