Esempio n. 1
0
    def test_conversion_POST_JSON_to_XML_rpc_with_list_input(self):
        self.maxDiff = None

        url = '/api/operations/in-list-no-out'
        json = _collapse_string('''
{
  "input" : 
    {
        "in" :
          [
        {"k" : "asdf"},
        {"k" : "fdsa"}
          ]
    }
}
        ''')

        expected_xml = _collapse_string('''
<vehicle-a:in-list-no-out xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><in xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">asdf</k></in><in xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">fdsa</k></in></vehicle-a:in-list-no-out>

       ''')

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("POST", url,
                                       (json, "application/data+json"))

        self.assertEqual(actual_xml, expected_xml)
Esempio n. 2
0
    def test_conversion_POST_JSON_to_XML_rpc_with_list_input(self):
        self.maxDiff = None

        url = "/api/operations/in-list-no-out"
        json = _collapse_string(
            """
{
  "input" : 
    {
        "in" :
          [
        {"k" : "asdf"},
        {"k" : "fdsa"}
          ]
    }
}
        """
        )

        expected_xml = _collapse_string(
            """
<vehicle-a:in-list-no-out xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><in xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">asdf</k></in><in xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><k xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">fdsa</k></in></vehicle-a:in-list-no-out>

       """
        )

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("POST", url, (json, "application/data+json"))

        self.assertEqual(actual_xml, expected_xml)
Esempio n. 3
0
    def test_conversion_PUT_JSON_to_XML_1(self):
        self.maxDiff = None

        url = '/api/config/car'
        json = _collapse_string('''
{
    "car":[
        {
            "brand":"subaru",
            "models":{
                "name-m":"WRX",
                "year":2015,
                "capacity":5,
                "is-cool":"True"
            }
        }
    ]
}
       ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><car xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><brand xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">subaru</brand><models xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><name-m xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">WRX</name-m><year xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">2015</year><capacity xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">5</capacity><is-cool xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">true</is-cool></models></car></config>
        ''')

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("PUT", url,
                                       (json, "application/data+json"))

        self.compare_doms(actual_xml, expected_xml)
Esempio n. 4
0
    def test_conversion_PUT_JSON_to_XML_1(self):
        self.maxDiff = None

        url = "/api/config/car"
        json = _collapse_string(
            """
{
    "car":[
        {
            "brand":"subaru",
            "models":{
                "name-m":"WRX",
                "year":2015,
                "capacity":5,
                "is-cool":"True"
            }
        }
    ]
}
       """
        )

        expected_xml = _collapse_string(
            """
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><car xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><brand xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">subaru</brand><models xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><name-m xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">WRX</name-m><year xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">2015</year><capacity xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">5</capacity><is-cool xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">true</is-cool></models></car></config>
        """
        )

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("PUT", url, (json, "application/data+json"))

        self.compare_doms(actual_xml, expected_xml)
Esempio n. 5
0
    def test_conversion_POST_JSON_to_XML_rpc_negative(self):
        self.maxDiff = None

        url = "/api/operations/in-list-no-out"
        json = _collapse_string(
            """
{
  "input" : 
    {
"extra":"asdf"
    }
}
        """
        )

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        caught = False
        try:
            actual_xml = converter.convert("POST", url, (json, "application/data+json"))
        except ValueError:
            caught = True
        self.assertEquals(True, caught)
Esempio n. 6
0
    def test_conversion_PUT_JSON_to_XML_list_with_escaped_url(self):
        self.maxDiff = None

        url = '/api/config/car/subaru%252F1%252F1/models/WRX/'
        json = _collapse_string('''
{
            "models":{
                "name-m":"WRX",
                "year":2015,
                "capacity":5,
                "is-cool":"True"
            }


}
       ''')

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><car xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><brand>subaru/1/1</brand><models xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><name-m xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">WRX</name-m><year xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">2015</year><capacity xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">5</capacity><is-cool xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">true</is-cool></models></car></config>
        ''')

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("PUT", url, (json,"application/data+json"))

        self.assertEqual(actual_xml, expected_xml)
Esempio n. 7
0
    def test_conversion_CONFD_URL_to_XML_6(self):
        self.maxDiff = None  # expected_xml is too large
        url = "/api/operational/car?select=brand"
        expected_xml = _collapse_string('''
<data><vehicle-a:car xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"/></data>
        ''')

        schema = load_schema_root("vehicle-a")

        actual_xml = convert_get_request_to_xml(schema, url)

        self.assertEquals(actual_xml, expected_xml)
Esempio n. 8
0
    def test_conversion_CONFD_URL_to_XML_6(self):
        self.maxDiff = None # expected_xml is too large
        url = "/api/operational/car?select=brand"
        expected_xml = _collapse_string('''
<data><vehicle-a:car xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"/></data>
        ''')

        schema = load_schema_root("vehicle-a")
        
        actual_xml = convert_get_request_to_xml(schema, url)        

        self.assertEquals(actual_xml, expected_xml)
Esempio n. 9
0
    def test_conversion_CONFD_URL_to_XML_1(self):
        self.maxDiff = None  # expected_xml is too large
        # trailing '/' is on purpose to test that edge case
        url = "/api/operational/car/subaru/models/"
        expected_xml = _collapse_string('''
<data><vehicle-a:car xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><brand>subaru</brand><vehicle-a:models><name-m></name-m></vehicle-a:models></vehicle-a:car></data>
        ''')

        schema = load_schema_root("vehicle-a")

        actual_xml = convert_get_request_to_xml(schema, url)

        self.assertEquals(actual_xml, expected_xml)
Esempio n. 10
0
    def test_conversion_CONFD_URL_to_XML_1(self):
        self.maxDiff = None # expected_xml is too large
        # trailing '/' is on purpose to test that edge case
        url = "/api/operational/car/subaru/models/" 
        expected_xml = _collapse_string('''
<data><vehicle-a:car xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><brand>subaru</brand><vehicle-a:models><name-m></name-m></vehicle-a:models></vehicle-a:car></data>
        ''')

        schema = load_schema_root("vehicle-a")
        
        actual_xml = convert_get_request_to_xml(schema, url)        

        self.assertEquals(actual_xml, expected_xml)
Esempio n. 11
0
    def test_conversion_CONFD_URL_to_XML_5(self):
        self.maxDiff = None  # expected_xml is too large
        url = "/api/operational/whatever/inner-whatever"
        expected_xml = _collapse_string(
            """
<data><vehicle-a:whatever xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><vehicle-a:inner-whatever/></vehicle-a:whatever></data>
        """
        )

        schema = load_schema_root("vehicle-a")

        actual_xml = convert_get_request_to_xml(schema, url)

        self.assertEquals(actual_xml, expected_xml)
Esempio n. 12
0
    def test_conversion_PUT_JSON_to_XML_199(self):
        self.maxDiff = None

        url = '/api/running/rwrestconf-configuration/log-timing'
        json = _collapse_string('''
{"log-timing" : "True"
}

       ''')

        root = load_schema_root("rw-restconf")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("POST", url, (json,"application/data+json"))
Esempio n. 13
0
    def test_conversion_PUT_JSON_to_XML_199(self):
        self.maxDiff = None

        url = '/api/running/rwrestconf-configuration/log-timing'
        json = _collapse_string('''
{"log-timing" : "True"
}

       ''')

        root = load_schema_root("rw-restconf")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("POST", url,
                                       (json, "application/data+json"))
Esempio n. 14
0
    def test_conversion_POST_JSON_to_XML_asdf(self):
        self.maxDiff = None

        url = "/api/operations/exec-ns-config-primitive"
        json = _collapse_string(
            """
{
    "input":{
        "vehicle-a:name":"create-user",
        "vehicle-a:nsr_id_ref":"1181c5ce-9c8b-4e1d-9247-2a38cdf128bb",
        "vehicle-a:vnf-primitive-group":[
            {
                "member-vnf-index-ref":"1",
                "vnfr-id-ref":"76d116e8-cf66-11e5-841e-6cb3113b406f",
                "primitive":[
                    {
                        "name":"number",
                        "value":"123"
                    },
                    {
                        "name":"password",
                        "value":"letmein"
                    }
                ]
            }
        ]
    }
}
        """
        )

        expected_xml = _collapse_string(
            """
<vehicle-a:exec-ns-config-primitive xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><name xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">create-user</name><nsr_id_ref xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">1181c5ce-9c8b-4e1d-9247-2a38cdf128bb</nsr_id_ref><vnf-primitive-group xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><member-vnf-index-ref xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">1</member-vnf-index-ref><vnfr-id-ref xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">76d116e8-cf66-11e5-841e-6cb3113b406f</vnfr-id-ref><primitive xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><name xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">number</name><value xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">123</value></primitive><primitive xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><name xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">password</name><value xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">letmein</value></primitive></vnf-primitive-group></vehicle-a:exec-ns-config-primitive>
        """
        )

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("POST", url, (json, "application/data+json"))

        self.assertEqual(actual_xml, expected_xml)
Esempio n. 15
0
    def test_conversion_POST_JSON_to_XML_asdf(self):
        self.maxDiff = None

        url = '/api/operations/exec-ns-config-primitive'
        json = _collapse_string('''
{
    "input":{
        "vehicle-a:name":"create-user",
        "vehicle-a:nsr_id_ref":"1181c5ce-9c8b-4e1d-9247-2a38cdf128bb",
        "vehicle-a:vnf-primitive-group":[
            {
                "member-vnf-index-ref":"1",
                "vnfr-id-ref":"76d116e8-cf66-11e5-841e-6cb3113b406f",
                "primitive":[
                    {
                        "name":"number",
                        "value":"123"
                    },
                    {
                        "name":"password",
                        "value":"letmein"
                    }
                ]
            }
        ]
    }
}
        ''')

        expected_xml = _collapse_string('''
<vehicle-a:exec-ns-config-primitive xmlns:vehicle-a="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><name xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">create-user</name><nsr_id_ref xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">1181c5ce-9c8b-4e1d-9247-2a38cdf128bb</nsr_id_ref><vnf-primitive-group xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><member-vnf-index-ref xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">1</member-vnf-index-ref><vnfr-id-ref xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">76d116e8-cf66-11e5-841e-6cb3113b406f</vnfr-id-ref><primitive xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><name xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">number</name><value xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">123</value></primitive><primitive xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><name xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">password</name><value xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">letmein</value></primitive></vnf-primitive-group></vehicle-a:exec-ns-config-primitive>
        ''')

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        actual_xml = converter.convert("POST", url,
                                       (json, "application/data+json"))

        self.assertEqual(actual_xml, expected_xml)
Esempio n. 16
0
    def test_conversion_POST_JSON_to_XML_rpc_negative(self):
        self.maxDiff = None

        url = '/api/operations/in-list-no-out'
        json = _collapse_string('''
{
  "input" : 
    {
"extra":"asdf"
    }
}
        ''')

        root = load_schema_root("vehicle-a")

        converter = ConfdRestTranslator(root)

        caught = False
        try:
            actual_xml = converter.convert("POST", url,
                                           (json, "application/data+json"))
        except ValueError:
            caught = True
        self.assertEquals(True, caught)