コード例 #1
0
ファイル: test_network.py プロジェクト: chyla/pat-lms
    def test_connect_ipv4_when_ip_is_wrong_and_contains_wrong_characters(self, socket_function_mock):
        socket_function_mock.return_value = self.socket_mock

        with pytest.raises(ValueError):
            sock = Network.connect_ipv4("127.0.0.1a", 80)

        assert socket_function_mock.called == False
コード例 #2
0
ファイル: test_network.py プロジェクト: chyla/pat-lms
    def test_connect_ipv4_correct_call(self, socket_function_mock):
        socket_function_mock.return_value = self.socket_mock

        sock = Network.connect_ipv4("127.0.0.1", 80)

        socket_function_mock.assert_called_once_with(socket.AF_INET, socket.SOCK_STREAM)
        assert socket_function_mock.return_value == sock
        sock.connect.assert_called_once_with(("127.0.0.1", 80))
コード例 #3
0
ファイル: util.py プロジェクト: chyla/pat-lms
def connect_and_get_result_from_command(command, args=None):
    n = Network.connect_ipv4(SERVER_ADDRESS, SERVER_PORT)

    json_object = {}
    json_object["command"] = command
    if args:
        json_object["args"] = args

    json_string = json.dumps(json_object)

    Network.send_text(n, json_string)

    response = Network.receive_text(n)

    json_response = json.loads(response)
    if json_response["status"] == "ok":
        if "result" in json_response:
            return json_response["result"]
    else:
        raise CommandException(json_response["message"])