def test_conversion(self): """ Check converting to PDU item works correctly """ primitive = SOPClassExtendedNegotiation() primitive.sop_class_uid = b'1.2.840.10008.5.1.4.1.1.2' primitive.service_class_application_information = b'\x02\x00\x03\x00\x01\x00' item = primitive.from_primitive() self.assertTrue(item.encode() == b'\x56\x00\x00\x21\x00\x19\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30' \ b'\x30\x30\x38\x2e\x35\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x2e\x32\x02' \ b'\x00\x03\x00\x01\x00')
def test_scp_callback_sop_class_extended(self): """Test that the SOP Class Extended info is available.""" def on_ext(req): return req self.scp = DummyStorageSCP() self.scp.ae.on_sop_class_extended = on_ext self.scp.start() ae = AE() ae.add_requested_context(CTImageStorage) ae.acse_timeout = 5 ae.dimse_timeout = 5 ext_neg = [] item = SOPClassExtendedNegotiation() item.sop_class_uid = '1.2.3' item.service_class_application_information = b'\x00\x01' ext_neg.append(item) item = SOPClassExtendedNegotiation() item.sop_class_uid = '1.2.4' item.service_class_application_information = b'\x00\x02' ext_neg.append(item) assoc = ae.associate('localhost', 11112, ext_neg=ext_neg) assert assoc.is_established status = assoc.send_c_store(DATASET) assert status.Status == 0x0000 assoc.release() assert assoc.is_released info = self.scp.info['sop_class_extended'] assert len(info) == 2 assert info['1.2.3'] == b'\x00\x01' assert info['1.2.4'] == b'\x00\x02' self.scp.stop()
def test_assignment_and_exceptions(self): """ Check incorrect types/values for properties raise exceptions """ primitive = SOPClassExtendedNegotiation() ## Check assignment # SOP Class UID reference_uid = UID('1.2.840.10008.5.1.4.1.1.2') primitive.sop_class_uid = b'1.2.840.10008.5.1.4.1.1.2' self.assertTrue(primitive.sop_class_uid == reference_uid) primitive.sop_class_uid = '1.2.840.10008.5.1.4.1.1.2' self.assertTrue(primitive.sop_class_uid == reference_uid) primitive.sop_class_uid = UID('1.2.840.10008.5.1.4.1.1.2') self.assertTrue(primitive.sop_class_uid == reference_uid) # Service Class Application Information primitive.service_class_application_information = b'\x02\x00\x03\x00\x01\x00' self.assertTrue(primitive.service_class_application_information == b'\x02\x00\x03\x00\x01\x00') ## Check exceptions # SOP Class UID with pytest.raises(TypeError): primitive.sop_class_uid = 10 with pytest.raises(TypeError): primitive.sop_class_uid = 45.2 with pytest.raises(ValueError): primitive.sop_class_uid = 'abc' # Service Class Application Information with pytest.raises(TypeError): primitive.service_class_application_information = 10 with pytest.raises(TypeError): primitive.service_class_application_information = 45.2 # Python 2 compatibility all bytes are str #with pytest.raises(TypeError): # primitive.service_class_application_information = 'abc' # No value set primitive = SOPClassExtendedNegotiation() with pytest.raises(ValueError): item = primitive.from_primitive() primitive.sop_class_uid = b'1.2.840.10008.5.1.4.1.1.2' with pytest.raises(ValueError): item = primitive.from_primitive() primitive = SOPClassExtendedNegotiation() primitive.service_class_application_information = b'\x02\x00\x03\x00\x01\x00' with pytest.raises(ValueError): item = primitive.from_primitive()