def test_serialize_message_hello_response():
    msg = HelloResponse(hostname="euler.test", domains=["example.com"])

    expected = """<?xml version="1.0"?>
    <pcoip-client version="2.1">
        <hello-resp>
            <brokers-info>
                <broker-info>
                    <product-name>{msg.product_name}</product-name>
                    <product-version>{msg.product_version}</product-version>
                    <platform>{msg.platform}</platform>
                    <locale>{msg.locale}</locale>
                    <ip-address>{msg.ip_address}</ip-address>
                    <hostname>{msg.hostname}</hostname>
                </broker-info>
            </brokers-info>
            <next-authentication>
                <authentication-methods>
                    <method>{msg.authentication_methods[0]}</method>
                </authentication-methods>
                <domains>
                    <domain>{msg.domains[0]}</domain>
                </domains>
            </next-authentication>
        </hello-resp>
    </pcoip-client>
    """.format(
        msg=msg
    )

    xml_et = serialize_message(msg)

    assert xml_tree_equal_to_xml_string(xml_et, expected)
def test_serialize_message_allocate_resource_success_response():
    msg = AllocateResourceSuccessResponse(
        "euler", "euler.gov", "lagrange", 666, "1234", "1234", 999
    )
    expected = """<?xml version="1.0"?>
    <pcoip-client version="2.1">
        <allocate-resource-resp>
            <result>
                <result-id>ALLOC_SUCCESSFUL</result-id>
                <result-str>The Spice must flow</result-str>
            </result>
            <target>
                <ip-address>{msg.ip_address}</ip-address>
                <hostname>{msg.hostname}</hostname>
                <sni>{msg.sni}</sni>
                <port>{msg.port}</port>
                <session-id>{msg.session_id}</session-id>
                <connect-tag>{msg.connect_tag}</connect-tag>
            </target>
            <resource-id>{msg.resource_id}</resource-id>
            <protocol>{msg.protocol}</protocol>
        </allocate-resource-resp>
    </pcoip-client>
    """.format(
        msg=msg
    )

    xml_et = serialize_message(msg)

    assert xml_tree_equal_to_xml_string(xml_et, expected)
def test_serialize_message_get_resource_list_response():
    resource = TeradiciResource("Euler", "Lagrange")
    msg = GetResourceListResponse([resource])

    expected = """<?xml version="1.0"?>
        <pcoip-client version="2.1">
            <get-resource-list-resp>
                <result>
                    <result-id>LIST_SUCCESSFUL</result-id>
                    <result-str>Khajit has wares.</result-str>
                </result>
                <resource>
                    <resource-name>{msg.resources[0].resource_name}</resource-name>
                    <resource-id>{msg.resources[0].resource_id}</resource-id>
                    <resource-type session-type="{msg.resources[0].session_type}">{msg.resources[0].resource_type}</resource-type>
                    <resource-state>{msg.resources[0].resource_state}</resource-state>
                    <protocols>
                        <protocol is-default="true">{msg.resources[0].protocol}</protocol>
                    </protocols>
                </resource>
            </get-resource-list-resp>
        </pcoip-client>
        """.format(
        msg=msg
    )

    xml_et = serialize_message(msg)

    assert xml_tree_equal_to_xml_string(xml_et, expected)
def test_serialize_message_bye_response():
    msg = ByeResponse()
    expected = """<?xml version="1.0"?>
    <pcoip-client version="2.1">
        <bye-resp />
    </pcoip-client>
    """.format(
        msg=msg
    )

    xml_et = serialize_message(msg)

    assert xml_tree_equal_to_xml_string(xml_et, expected)
def test_serialize_message_allocate_resource_failure_response():
    msg = AllocateResourceFailureResponse(result_id="XENOMORPHS_RUNNING_LOSE")
    expected = """<?xml version="1.0"?>
    <pcoip-client version="2.1">
        <allocate-resource-resp>
            <result>
                <result-id>{msg.result_id}</result-id>
                <result-str>Failed to allocate a session on the given resource 😢.</result-str>
            </result>
        </allocate-resource-resp>
    </pcoip-client>
    """.format(
        msg=msg
    )

    xml_et = serialize_message(msg)

    assert xml_tree_equal_to_xml_string(xml_et, expected)
def test_serialize_message_authenticate_failed_response():
    msg = AuthenticateFailedResponse()

    expected = """<?xml version="1.0"?>
    <pcoip-client version="2.1">
        <authenticate-resp method="password">
            <result>
                <result-id>AUTH_FAILED_UNKNOWN_USERNAME_OR_PASSWORD</result-id>
                <result-str>Could not authenticate.</result-str>
            </result>
        </authenticate-resp>
    </pcoip-client>
    """.format(
        msg=msg
    )

    xml_et = serialize_message(msg)

    assert xml_tree_equal_to_xml_string(xml_et, expected)
def test_serialize_message_authenticate_success_response():
    msg = AuthenticateSuccessResponse()

    expected = """<?xml version="1.0"?>
    <pcoip-client version="2.1">
        <authenticate-resp method="password">
            <result>
                <result-id>AUTH_SUCCESSFUL_AND_COMPLETE</result-id>
                <result-str>Authentication was a resounding success.</result-str>
            </result>
        </authenticate-resp>
    </pcoip-client>
    """.format(
        msg=msg
    )

    xml_et = serialize_message(msg)

    assert xml_tree_equal_to_xml_string(xml_et, expected)
def test_serialize_message_bad_argument():
    with pytest.raises(ValueError):
        serialize_message(123)