test_client_gemini.py 1.24 KB
#!/usr/bin/env python3

import unittest

import sys
sys.path.append('..')
from src.client.socket_client_gemini import SocketClient_GEMINI

class TestClient(unittest.TestCase):

    def setUp(self):
        self.seq = range(10)

    def test_run(self):
        
        #HOST, PORT = "localhost", 9999
        #HOST, PORT = "localhost", 20001
        HOST, PORT = "localhost", 11110
        
        qa = [
            ('toto', 'TOTO'),
            ('GD', '+12:28')
            #(':GD#', '+12:28')
        ]
        
        #tsock = SocketClient_UDP_TCP(HOST, PORT, "UDP")
        with SocketClient_GEMINI(HOST, PORT) as tsock:
            # Only useful for TCP (does nothing for UDP)
            tsock._connect_to_server()
            
            # 1) SEND REQUEST data to server
            
            for data in qa:
                question,answer = data
                tsock.send_data(question)
        
                # 2) RECEIVE REPLY data from server
                data_received = tsock.receive_data()
                self.assertEqual(data_received, answer)
            
            radec = tsock.get("RA-DEC")
            self.assertEqual(radec,  ['GR', '+12:28'])
            
            #tsock.close()

if __name__ == '__main__':
    unittest.main()