from bandwidth_sdk import xml
from .utils import SdkTestCase


class XmlTest(SdkTestCase):
    def test_pause_xml(self):
        expected_result = str.encode("<?xml version=\'1.0\' encoding=\'ASCII\'?>\n"
                                     "<Response>\n"
                                     "  <Pause duration=\"6\"></Pause>\n"
                                     "</Response>\n")

        xml_response = xml.Response()
        pause = xml.Pause(duration=6)
        xml_response.push(pause)
        actual_result = xml_response.to_xml()

        self.assertEqual(expected_result, actual_result)

    def test_pause_direct_xml(self):
        expected_result = str.encode("<?xml version=\'1.0\' encoding=\'ASCII\'?>\n"
                                     "<Response>\n"
                                     "  <Pause duration=\"6\"></Pause>\n"
                                     "</Response>\n")

        xml_response = xml.Response()
        pause = xml.Pause(6)
        xml_response.push(pause)
        actual_result = xml_response.to_xml()

        self.assertEqual(expected_result, actual_result)

    def test_transfer_direct_xml(self):
        expected_result = str.encode("<?xml version=\'1.0\' encoding=\'ASCII\'?>\n"
                                     "<Response>\n"
                                     "  <Transfer transferCallerId=\"+11234567891\" transferTo=\"+11234567892\"/>\n"
                                     "</Response>\n")

        xml_response = xml.Response()
        xml_response.push(xml.Transfer(transfer_caller_id="+11234567891", transfer_to="+11234567892"))
        actual_result = xml_response.to_xml()

        self.assertEqual(expected_result, actual_result)

    def test_hangup_xml(self):
        expected_result = str.encode("<?xml version=\'1.0\' encoding=\'ASCII\'?>\n"
                                     "<Response>\n"
                                     "  <Hangup></Hangup>\n"
                                     "</Response>\n")

        xml_response = xml.Response()
        xml_response.push(xml.Hangup())
        actual_result = xml_response.to_xml()

        self.assertEqual(expected_result, actual_result)