Exemplo n.º 1
0
def basicUnitTest():
    loop = TestLoopEx()
    asyncio.set_event_loop(loop)
    client = ClolorClientPro(loop)
    server = ColorServerPro()
    transportToServer = MockTransportToProtocol(server)
    transportToClient = MockTransportToProtocol(client)
    server.connection_made(transportToClient)
    client.connection_made(transportToServer)

    assert server.state == 'connected'
    assert client.state == 'connected'

    cid = 1
    message = 'A52A2A'
    server.findcolor(cid, message)
    client.sendfirst()

    assert server.state == 'r_decode'
    assert client.state == 'r_result'

    colorhex = client.passcode()
    R = int(colorhex[:2], 16)
    G = int(colorhex[2:4], 16)
    B = int(colorhex[4:], 16)
    client.senddecode(R, G, B)

    assert server.state == 'complete'
    assert server.state == 'complete'
Exemplo n.º 2
0
def BasicUnitTest():
    asyncio.set_event_loop(TestLoopEx())
    client = ClientProtocol(packet2)
    server = ServerProtocol()
    transportToServer = MockTransportToProtocol(server)
    transportToClient = MockTransportToProtocol(client)
    server.connection_made(transportToClient)
    client.connection_made(transportToServer)
Exemplo n.º 3
0
def basicUnitTest():
    asyncio.set_event_loop(TestLoopEx())
    client = EchoClientProtocol()
    server = EchoServerProtocol()
    transportToServer = MockTransportToProtocol(server)
    transportToClient = MockTransportToProtocol(client)

    server.connection_made(transportToClient)
    client.connection_made(transportToServer)

    assert client.status == 2
    assert server.status == 2
Exemplo n.º 4
0
def basicUnitTest():
    loop = asyncio.set_event_loop(TestLoopEx())

    serverProtocol = MyServerProtocol()
    clientProtocol = MyClientProtocol(loop)

    # calling transportToServer’s write method will route the data directly to server’s data_received method
    #transportToServer = MockTransportToProtocol(serverProtocol)
    #transportToClient = MockTransportToProtocol(clientProtocol)

    transportToServer = MockTransportToProtocol(myProtocol=clientProtocol)
    transportToClient = MockTransportToProtocol(myProtocol=serverProtocol)

    # when setRemoteTransport is called, it writes data to the transport's protocol
    transportToServer.setRemoteTransport(transportToClient)
    transportToClient.setRemoteTransport(transportToServer)

    # serverProtocol.connection_made(transportToClient)
    # clientProtocol.connection_made(transportToServer)

    clientProtocol.connection_made(transportToServer)
    serverProtocol.connection_made(transportToClient)

    # try to send a pkt with clientID = 1
    clientProtocol.sendRequest(1)

    # try to send something not packet
    try:
        serverProtocol.data_received('Test')
    except TypeError:
        print(TypeError)
Exemplo n.º 5
0
def basicUnitTest():
    asyncio.set_event_loop(TestLoopEx())
    packet1 = RequestProblem()
    packet1.id = 1
    packet1.info = 'Request Current Date'

    server = EchoServerProtocol()
    client = EchoClientProtocol(packet1)

    transportToServer = MockTransportToProtocol(server)
    transportToClient = MockTransportToProtocol(client)

    server.connection_made(transportToClient)
    client.connection_made(transportToServer)
Exemplo n.º 6
0
def basicUnitTest():
    #asyncio.set_event_loop(TestLoopEx())
    # server = EchoServerProtocol()
    # client = EchoClientProtocol()
    # transportToServer = MockTransportToProtocol(server)
    # transportToClient = MockTransportToProtocol(client)
    # server.connection_made(transportToClient)
    # client.connection_made(transportToServer)
    client = EchoClientProtocol()
    server = EchoServerProtocol()
    cTransport, sTransport = MockTransportToProtocol.CreateTransportPair(
        client, server)
    client.connection_made(cTransport)
    server.connection_made(sTransport)
    firstRequest = packetClass.RequestRecommandation()
    client.Request(firstRequest)
    assert server.serverstatus == 1
    assert client.clientstatus == 1
    #client.method(firstRequest)
    OneAnswer = packetClass.Answer()
    OneAnswer.answer = "oliy"
    OneAnswer.ID = 1
    client.method(OneAnswer)
    assert server.serverstatus == 2
    assert client.clientstatus == 2
Exemplo n.º 7
0
def basicUnitTest():
    asyncio.set_event_loop(TestLoopEx())
    client = EchoClientProtocol()
    server = EchoServerProtocol()

    transportToServer = MockTransportToProtocol(server)
    transportToClient = MockTransportToProtocol(client)

    server.connection_made(transportToClient)
    client.connection_made(transportToServer)

    #	packet1=RequestIDProblem()
    #	packet1.ID=1
    #	client.transport.write(packet1.__serizalize__())

    assert client.status == 2
    assert server.status == 2
def UnitTest():
    asyncio.set_event_loop(TestLoopEx())
    clientProtocol = ClientSide()
    serverProtocol = ServerSide()
    cTransport, sTransport = MockTransportToProtocol.CreateTransportPair(
        clientProtocol, serverProtocol)
    serverProtocol.connection_made(sTransport)
    clientProtocol.connection_made(cTransport)
Exemplo n.º 9
0
def basicUnitTest():
    clientProtocol = MyProtocolClient("hello", TestLoopEx())
    serverProtocol = MyProtocolServer()
    transportToServer = MockTransportToProtocol(myProtocol=clientProtocol)
    transportToClient = MockTransportToProtocol(myProtocol=serverProtocol)
    transportToServer.setRemoteTransport(transportToClient)
    transportToClient.setRemoteTransport(transportToServer)

    serverProtocol.connection_made(transportToClient)
    clientProtocol.connection_made(transportToServer)
Exemplo n.º 10
0
def basicUnitTest():
    asyncio.set_event_loop(TestLoopEx())
    client = ClientProtocol()
    server = ServerProtocol()
    transportToServer = MockTransportToProtocol(myProtocol=client)
    transportToClient = MockTransportToProtocol(myProtocol=server)
    transportToServer.setRemoteTransport(transportToClient)
    transportToClient.setRemoteTransport(transportToServer)
    client.connection_made(transportToServer)
    server.connection_made(transportToClient)
    client.sendpkt1(b"ABC123", b"EN.601.644", True)
Exemplo n.º 11
0
def basicUnitTest():
    # Build a MockConnection between Client and Server
    set_event_loop(TestLoopEx())
    client = ClientProtocol()  #sending data from the protocol
    server = ServerProtocol()
    transportToServer = MockTransportToProtocol(myProtocol=client)
    transportToClient = MockTransportToProtocol(myProtocol=server)
    transportToServer.setRemoteTransport(transportToClient)
    transportToClient.setRemoteTransport(transportToServer)
    server.connection_made(transportToClient)
    client.connection_made(transportToServer)
    client.Login("wwz", "hellowwz")
Exemplo n.º 12
0
def basicProtocolTest():
    asyncio.set_event_loop(TestLoopEx())
    clientProtocol = EchoClientProtocol()
    serverProtocol = EchoServerProtocol()
    cTransport, sTransport = MockTransportToProtocol.CreateTransportPair(
        clientProtocol, serverProtocol)
    clientProtocol.connection_made(cTransport)
    serverProtocol.connection_made(sTransport)

    clientProtocol.send_request()
Exemplo n.º 13
0
def UnitTest1():
    set_event_loop(TestLoopEx())
    clientProtocol = EchoClientProtocol()
    serverProtocol = EchoServerProtocol()
    transportToServer = MockTransportToProtocol(myProtocol=clientProtocol)
    transportToClient = MockTransportToProtocol(myProtocol=serverProtocol)
    transportToServer.setRemoteTransport(transportToClient)
    transportToClient.setRemoteTransport(transportToServer)
    clientProtocol.connection_made(transportToServer)
    serverProtocol.connection_made(transportToClient)

    clientProtocol.SetIdentityInfo(123, "Alex", "2017alex")
    clientProtocol.SendLoginRequest()
Exemplo n.º 14
0
def UnitTest2():
    set_event_loop(TestLoopEx())
    clientProtocol = EchoClientProtocol()
    serverProtocol = EchoServerProtocol()
    cTransport, sTransport = MockTransportToProtocol.CreateTransportPair(
        clientProtocol, serverProtocol)
    clientProtocol.connection_made(cTransport)
    serverProtocol.connection_made(sTransport)

    clientProtocol.SetIdentityInfo(123, "Jack", "2017jack")
    clientProtocol.SendLoginRequest()
Exemplo n.º 15
0
def basicUnitTest():
    asyncio.set_event_loop(TestLoopEx())
    server = MoviesServer()
    client = MoviesClient()
    transportToServer = MockTransportToProtocol(myProtocol=client)
    transportToClient = MockTransportToProtocol(myProtocol=server)
    transportToServer.setRemoteTransport(transportToClient)
    transportToClient.setRemoteTransport(transportToServer)
    server.connection_made(transportToClient)
    client.connection_made(transportToServer)
    client.requestMovieInfo("frozen", "genre")
    assert MoviesClient.str == "Comedy"
    assert MoviesServer.str == "genre"
Exemplo n.º 16
0
def basicUnitTest():
    asyncio.set_event_loop(TestLoopEx())
    server = EchoServerProtocol()
    client = EchoClientProtocol()
    transportToServer = MockTransportToProtocol(server)
    transportToClient = MockTransportToProtocol(client)
    server.connection_made(transportToClient)
    client.connection_made(transportToServer)
    firstRequest =  RequestRecommandation()
    firstRequest.request ="request connection"
    client.Request(firstRequest)
    assert server.serverstatus == 1
    assert client.clientstatus == 1
    #client.method(firstRequest)
    OneAnswer = Answer()
    OneAnswer.answer = "oliy"
    OneAnswer.ID = 1
    client.method(OneAnswer)
    assert server.serverstatus == 2
    assert client.clientstatus == 2
Exemplo n.º 17
0
 def test_connection(self):
     asyncio.set_event_loop(TestLoopEx())
     testData = RequestFlip()
     testData.headOrTail = True
     testData.numFlips = 1000
     client = CoinClientProtocol(testData)
     server = CoinServerProtocol()
     transportToServer = MockTransportToProtocol(myProtocol=server)
     transportToClient = MockTransportToProtocol(myProtocol=client)
     transportToServer.setRemoteTransport(transportToClient)
     transportToClient.setRemoteTransport(transportToServer)
     client.connection_made(transportToServer)
     server.connection_made(transportToClient)
Exemplo n.º 18
0
def basic_unit_test():
    set_event_loop(TestLoopEx())
    client = ClientProtocol("harry", "123456", "*****@*****.**")
    server = ServerProtocol()

    transport_to_server = MockTransportToProtocol(client)
    transport_to_client = MockTransportToProtocol(server)
    transport_to_server.setRemoteTransport(transport_to_client)
    transport_to_client.setRemoteTransport(transport_to_server)
    client.connection_made(transport_to_server)
    server.connection_made(transport_to_client)

    client.sign_up()
Exemplo n.º 19
0
def basicUnitTest():
    print('Begin')
    asyncio.set_event_loop(TestLoopEx())

    clientProtocol = ClientProtocol()
    serverProtocol = ServerProtocol()
    cTransport, sTransport = MockTransportToProtocol.CreateTransportPair(
        clientProtocol, serverProtocol)
    clientProtocol.connection_made(cTransport)
    serverProtocol.connection_made(sTransport)

    clientProtocol.start()
Exemplo n.º 20
0
def unitTest():
    #for now params are picked within the protocols
    from playground.network.testing import MockTransportToProtocol
    from playground.asyncio_lib.testing import TestLoopEx

    asyncio.set_event_loop(TestLoopEx())

    server = PlaneServer()
    client = PlaneClient()
    cTransport, sTransport = MockTransportToProtocol.CreateTransportPair(
        client, server)
    server.connection_made(sTransport)
    client.connection_made(cTransport)
Exemplo n.º 21
0
def basicUnitTest():

    # asyncio.set_event_loop(TestLoopEx())
    clientProtocol = MyClientProtocol()
    serverProtocol = MyServerProtocol()
    cTransport, sTransport = MockTransportToProtocol.CreateTransportPair(
        clientProtocol, serverProtocol)
    clientProtocol.connection_made(cTransport)
    serverProtocol.connection_made(sTransport)

    packet1 = RequestConnect()
    packet1.iD = "ELROY"
    clientProtocol.transport.write(packet1.__serialize__())
Exemplo n.º 22
0
def basicUnitTest():
    client = Protocol.ForgotPasswordClientProtocol()
    server = Protocol.ForgotPasswordServerProtocol()
    cTransport, sTransport = MockTransportToProtocol.CreateTransportPair(
        client, server)

    server.connection_made(sTransport)
    client.connection_made(cTransport)
    # client.send_initial_message()

    packet1 = Packets.RequestForgotPasswordPacket()
    packet1.userId = 'ehsia1'
    packet1Bytes = packet1.__serialize__()
    sResponse1 = server.data_received(packet1Bytes)
    assert isinstance(sResponse1, Packets.SecurityQuestionPacket)
    packet2 = Packets.SecurityQuestionPacket()
    packet2.securityQuestion = 'What was your hometown?'
    packet2Bytes = packet2.__serialize__()
    cResponse1 = client.data_received(packet2Bytes)
    cResponse1 = PacketType.Deserialize(cResponse1)
    assert isinstance(cResponse1, Packets.SecurityAnswerPacket)
    packet3 = Packets.SecurityAnswerPacket()
    packet3.securityAnswer = 'Windsor, CT'
    packet3Bytes = packet3.__serialize__()
    sResponse2 = server.data_received(packet3Bytes)
    assert isinstance(sResponse2, Packets.ForgotPasswordTokenPacket)
    packet3.securityAnswer = 'Windsor'
    packet3Bytes = packet3.__serialize__()
    sResponse2 = server.data_received(packet3Bytes)
    assert sResponse2 == "Invalid"
    packet4 = Packets.ForgotPasswordTokenPacket()
    packet4.token = 'asdf2313241SqwerXq'
    packet4Bytes = packet4.__serialize__()
    cResponse2 = client.data_received(packet4Bytes)
    cResponse2 = PacketType.Deserialize(cResponse2)
    assert isinstance(cResponse2, Packets.ResetPasswordInputPacket)
    packet5 = Packets.ResetPasswordInputPacket()
    packet5.newPassword = '******'
    packet5.passwordConfirmation = 'gronkgronkgronk'
    packet5Bytes = packet5.__serialize__()
    sResponse3 = server.data_received(packet5Bytes)
    assert isinstance(sResponse3, Packets.PasswordResetPacket)
    assert sResponse3.verification == True
    packet5.newPassword = '******'
    packet5.passwordConfirmation = 'gronkgronkgronk'
    packet5Bytes = packet5.__serialize__()
    sResponse3 = server.data_received(packet5Bytes)
    assert isinstance(sResponse3, Packets.PasswordResetPacket)
    assert sResponse3.verification == False

    print("Protocol completed! All tests passed!")
Exemplo n.º 23
0
def basicUnitTest():

    loop = TestLoopEx()
    asyncio.set_event_loop(loop)
    Server = ServerProtocol()
    Client = ClientProtocol()

    transportToServer = MockTransportToProtocol(myProtocol=Client)
    transportToClient = MockTransportToProtocol(myProtocol=Server)
    transportToServer.setRemoteTransport(transportToClient)
    transportToClient.setRemoteTransport(transportToServer)

    Server.connection_made(transportToClient)
    Client.first_packet('111','POP')
    Client.connection_made(transportToServer)
Exemplo n.º 24
0
def UnitTest():

    loop = TestLoopEx()
    asyncio.set_event_loop(loop)

    Server = MyServer()
    Client = MyClient()

    transportToServer = MockTransportToProtocol(myProtocol=Client)
    transportToClient = MockTransportToProtocol(myProtocol=Server)
    transportToServer.setRemoteTransport(transportToClient)
    transportToClient.setRemoteTransport(transportToServer)

    Server.connection_made(transportToClient)
    Client.Initial_Packet()
    Client.connection_made(transportToServer)
Exemplo n.º 25
0
def BasicUnitTest():
    set_event_loop(TestLoopEx())
    client = IoTClientProtocol()
    server = IoTServerProtocol()
    transportToServer = MockTransportToProtocol(myProtocol=client)
    transportToClient = MockTransportToProtocol(myProtocol=server)
    transportToServer.setRemoteTransport(transportToClient)
    transportToClient.setRemoteTransport(transportToServer)

    client.connection_made(transportToServer)
    server.connection_made(transportToClient)

    client.GetDeviceList()
    server.DeviceList()
    client.ModifyDevice()
    server.Respond()
Exemplo n.º 26
0
def basicUnitTest():
	
	loop = 	TestLoopEx()
	asyncio.set_event_loop(TestLoopEx())
			

	clientProtocol = ClientProtocol(loop)
	serverProtocol = ServerProtocol()
	cTransport, sTransport = MockTransportToProtocol.CreateTransportPair(clientProtocol, serverProtocol)
	clientProtocol.connection_made(cTransport)
	serverProtocol.connection_made(sTransport)

	pkt1 = DB_connect()	
	clientProtocol.send_packet(pkt1)
Exemplo n.º 27
0
def basicUnitTest():
    from playground.asyncio_lib.testing import TestLoopEx
    from playground.network.testing import MockTransportToProtocol

    loop = asyncio.get_event_loop()
    print("Making the server choose a 'random' number of 5.")

    client_1 = RandomNumberGameClientProtocol(loop)
    server_1 = RandomNumberGameServerProtocol(seed=5)
    cTransport, sTransport = MockTransportToProtocol.CreateTransportPair(
        client_1, server_1)
    server_1.connection_made(sTransport)
    client_1.connection_made(cTransport)

    client_1.initiate_game(guess=4)

    client_2 = RandomNumberGameClientProtocol(loop)
    server_2 = RandomNumberGameServerProtocol(seed=5)
    cTransport, sTransport = MockTransportToProtocol.CreateTransportPair(
        client_2, server_2)
    server_2.connection_made(sTransport)
    client_2.connection_made(cTransport)

    client_2.initiate_game(guess=5)
Exemplo n.º 28
0
def basicUnitTestForPEEPProtocol(loggingFlag):
    asyncio.set_event_loop(TestLoopEx())
    loop = asyncio.get_event_loop()

    server = PEEPServerProtocol(False)
    client = PEEPClientProtocol(False)

    client.set_timeout_flag(False)
    client.set_mock_flag(True)
    server.set_mock_flag(True)

    cTransport, sTransport = MockTransportToProtocol.CreateTransportPair(
        client, server)

    # test for general connection_made
    client.connection_made(cTransport)
    server.connection_made(sTransport)

    if loggingFlag == True: print("- test for general connection_made SUCCESS")
    if loggingFlag == True: print("")

    # negative test for messing up packet order
    cTransport, sTransport = MockTransportToProtocol.CreateTransportPair(
        client, server)
    client.connection_made(cTransport)
    server.connection_made(sTransport)

    MockPEEPPacket_SYN = Util.create_outbound_packet(0, 1, 1, b"data")
    packetBytes = MockPEEPPacket_SYN.__serialize__()
    server.state = "SYN_State_1"
    client.state = "SYN_ACK_State_1"
    server.data_received(packetBytes)
    assert server.state == "error_state"
    if loggingFlag == True:
        print("- negative test for messing up packet order SUCCESS")
    if loggingFlag == True: print("")
Exemplo n.º 29
0
def basicUnitTest():
    loop = asyncio.set_event_loop(TestLoopEx())
    client = ClientProtocol(loop)
    server = ServerProtocol()
    transportToServer = MockTransportToProtocol(myProtocol=client)
    transportToClient = MockTransportToProtocol(myProtocol=server)
    transportToServer.setRemoteTransport(transportToClient)
    transportToClient.setRemoteTransport(transportToServer)
    server.connection_made(transportToClient)
    client.connection_made(transportToServer)

    loginWithUsername = LogInWithUsername()
    getUserProfile = GetUserProfleWithID()
    client.loginStart(loginWithUsername, getUserProfile)

    assert client.state == 1
    assert server.state == 1
Exemplo n.º 30
0
def basicUnitTest():

    loop = asyncio.set_event_loop(TestLoopEx())
    server = EchoServerProtocol()
    server.invite('Bob', 'California', 1, 1, '10.0.0.1', 65001,
                  ['G711u', 'G729', 'G722', 'OPUS', 'G711a'])
    client = EchoClientProtocol(loop)
    client.response('Alice', 'WashingtonDC', 1, 1, '192.168.1.254', 45532,
                    ["G722a", "G729"])
    #transportToServer = MockTransportToProtocol(server)
    #transportToClient = MockTransportToProtocol(client)
    transportToServer, transportToClient = MockTransportToProtocol.CreateTransportPair(
        client, server)
    server.connection_made(transportToClient)
    client.connection_made(transportToServer)
Exemplo n.º 31
0
def basicUnitTest():
    clientProtocol = MyProtocolClient("hello", TestLoopEx())
    serverProtocol = MyProtocolServer()
    transportToServer = MockTransportToProtocol(myProtocol=clientProtocol)
    transportToClient = MockTransportToProtocol(myProtocol=serverProtocol)
    transportToServer.setRemoteTransport(transportToClient)
    transportToClient.setRemoteTransport(transportToServer)

    serverProtocol.connection_made(transportToClient)
    clientProtocol.connection_made(transportToServer)