def test_ready_error(self): """Test AssociationSocket.ready.""" sock = AssociationSocket(self.assoc) assert sock.ready is False sock._is_connected = True assert sock.ready is True sock.socket.close() assert sock.ready is False assert sock.event_queue.get() == 'Evt17'
def dev_handle_connection(self, client_socket): # Create a new Association self.ae.port = self.port assoc = Association(self.ae, "acceptor") assoc.set_socket(AssociationSocket(assoc, client_socket)) # Association Acceptor object -> local AE assoc.acceptor.maximum_length = self.ae.maximum_pdu_size assoc.acceptor.ae_title = self.ae.ae_title assoc.acceptor.address = self.ae.address assoc.acceptor.port = self.port assoc.acceptor.implementation_class_uid = ( self.ae.implementation_class_uid) assoc.acceptor.implementation_version_name = ( self.ae.implementation_version_name) assoc.acceptor.supported_contexts = deepcopy( self.ae.supported_contexts) # Association Requestor object -> remote AE assoc.requestor.address = client_socket.getpeername()[0] assoc.requestor.port = client_socket.getpeername()[1] assoc._a_abort_assoc_rq = self.send_a_abort assoc._a_p_abort_assoc_rq = self.send_ap_abort assoc.start()
def test_init_raises(self, caplog): """Test exception is raised if init with client_socket and address.""" msg = (r"AssociationSocket instantiated with both a 'client_socket' " r"and bind 'address'. The original socket will not be rebound") with caplog.at_level(logging.WARNING, logger='pynetdicom'): sock = AssociationSocket(self.assoc, client_socket='abc', address=('', 11112)) assert msg in caplog.text
def test_init_existing(self): """Test creating a new AssociationSocket around existing socket.""" sock = AssociationSocket(self.assoc, client_socket='abc') assert sock.tls_args is None assert sock.select_timeout == 0.5 assert sock._assoc == self.assoc assert sock.socket == 'abc' assert sock._is_connected is True assert sock.event_queue.get(block=False) == "Evt5"
def test_init_new(self): """Test creating a new AssociationSocket instance.""" sock = AssociationSocket(self.assoc) assert sock.tls_args is None assert sock.select_timeout == 0.5 assert sock._assoc == self.assoc assert isinstance(sock.socket, socket.socket) assert sock._is_connected is False with pytest.raises(queue.Empty): sock.event_queue.get(block=False)
def test_close_connect(self): """Test closing and connecting.""" sock = AssociationSocket(self.assoc) sock._is_connected = True assert sock.socket is not None sock.close() assert sock.socket is None # Tries to connect, sets to None if fails sock.connect(('', 11112)) assert sock.event_queue.get() == 'Evt17' assert sock.socket is None
def test_init_address(self): """Test creating a new bound AssociationSocket instance.""" sock = AssociationSocket(self.assoc, address=('', 11112)) assert sock.tls_args is None assert sock.select_timeout == 0.5 assert sock._assoc == self.assoc assert isinstance(sock.socket, socket.socket) assert sock.socket.getsockname()[0] == '0.0.0.0' assert sock.socket.getsockname()[1] == 11112 assert sock._is_connected is False with pytest.raises(queue.Empty): sock.event_queue.get(block=False)
def test_print(self): """Test str(AssociationSocket).""" sock = AssociationSocket(self.assoc) assert sock.__str__() == sock.socket.__str__()