Example #1
0
    def test_gi_typename(self):
        co = CompanyYang.Company()
        copbcm = co.to_pbcm()
        self.assertEqual(copbcm.get_gi_typename(), "CompanyYang.Company")
        desc = co.retrieve_descriptor()
        field_names = desc.get_field_names()
        self.assertEqual(desc.get_gi_typename(), "CompanyYang.Company")
        self.assertTrue('employee' in field_names)
        self.assertTrue('contact_info' in field_names)
        self.assertTrue('product' in field_names)
        self.assertTrue(desc.get_field_by_name('employee').is_list())
        self.assertFalse(desc.get_field_by_name('contact_info').is_list())

        keys = desc.get_key_names()
        self.assertTrue(0 == len(keys))

        person = CompanyYang.Company_Employee()
        desc = person.retrieve_descriptor()
        field_names = desc.get_field_names()

        self.assertTrue('id' in field_names)
        self.assertTrue('name' in field_names)
        self.assertTrue('title' in field_names)
        self.assertTrue('start_date' in field_names)

        keys = desc.get_key_names()
        self.assertTrue('id' in keys)
        self.assertTrue(len(keys) == 1)

        field_names = CompanyYang.Company.change_to_descriptor(
            CompanyYang.Company.schema()).get_field_names()
        self.assertTrue('employee' in field_names)
        self.assertTrue('contact_info' in field_names)
        self.assertTrue('product' in field_names)
Example #2
0
    def setUp(self):
        self.co = CompanyYang.Company()

        for i in range(32):
            person = CompanyYang.Company_Employee()
            person.id = i
            person.name = "bob"
            self.co.employee.append(person)
Example #3
0
 def test_fref_methods(self):
     fref = ProtobufC.FieldReference.alloc()
     self.assertTrue(fref)
     co = CompanyYang.Company()
     cinfo = co.contact_info
     cinfo.name = "*****@*****.**"
     cinfo.address = "Burlington"
     pbcmp = cinfo.to_pbcm()
     fref.goto_proto_name(pbcmp, "name")
     fref.pb_text_set("*****@*****.**")
     fref.goto_proto_name(pbcmp, "address")
     fref.pb_text_set("Burlington")
     fref.goto_proto_name(pbcmp, "name")
     self.assertTrue(fref.is_field_present())
     fref.goto_proto_name(pbcmp, "address")
     self.assertTrue(fref.is_field_present())
     fref.goto_proto_name(pbcmp, "phone_number")
     self.assertFalse(fref.is_field_present())
     fref.mark_field_deleted()
     self.assertTrue(fref.is_field_deleted())
Example #4
0
    def test_list_key_order(self):
        comp = CompanyYang.Company()
        dep = comp.department.add()
        dep.name = 'engineering'
        dep.id = 1
        dep.level = 5
        dep.director = 'Wolverine'

        expected_resp_xml = """
<company:company xmlns:company="http://riftio.com/ns/core/util/yangtools/tests/company">

  <company:department>
    <company:id>1</company:id>
    <company:name>engineering</company:name>
    <company:level>5</company:level>
    <company:director>Wolverine</company:director>
  </company:department>

</company:company>"""

        resp = comp.to_xml_v2(self.model, pretty_print=True)
        self.assertEqual(resp, expected_resp_xml)
Example #5
0
    def test_protobuf_are_unequal(self):
        proto_a = CompanyYang.Company()
        proto_b = DocumentYang.MainBook_Chapters()

        self.assertNotEqual(proto_a, proto_b)
Example #6
0
    def test_protobuf_are_equal(self):
        proto_a = CompanyYang.Company()
        proto_b = CompanyYang.Company()

        self.assertEqual(proto_a, proto_b)
Example #7
0
 def test_fref_goto_xpath(self):
     fref = ProtobufC.FieldReference.alloc()
     self.assertTrue(fref)
     co = CompanyYang.Company()
     co.contact_info.name = "*****@*****.**"
     co.contact_info.address = "Burlington"
     co.contact_info.phone_number = "1234567"
     emp = co.employee.add()
     emp.id = 1234
     emp.name = "abc"
     emp.title = "MTS"
     co1 = CompanyYang.Company()
     pbcmc = co1.to_pbcm()
     fref.goto_xpath(pbcmc, "D,/company:company/company:contact-info")
     self.assertTrue(fref.is_field_missing())
     cinfo = co1.contact_info
     fref.goto_xpath(pbcmc, "D,/company:company/company:contact-info")
     self.assertTrue(fref.is_field_present())
     fref.goto_xpath(
         pbcmc, "D,/company:company/company:contact-info/company:name")
     self.assertTrue(fref.is_field_missing())
     fref.pb_text_set("*****@*****.**")
     self.assertTrue(fref.is_field_present())
     fref.goto_xpath(
         pbcmc, "D,/company:company/company:contact-info/company:address")
     self.assertTrue(fref.is_field_missing())
     fref.pb_text_set("Burlington")
     self.assertTrue(fref.is_field_present())
     fref.goto_xpath(
         pbcmc,
         "D,/company:company/company:contact-info/company:phone-number")
     self.assertTrue(fref.is_field_missing())
     fref.pb_text_set("1234567")
     self.assertTrue(fref.is_field_present())
     emp = co1.employee.add()
     emp.id = 1234
     fref.goto_xpath(
         pbcmc,
         "D,/company:company/company:employee[company:id='1234']/company:name"
     )
     self.assertTrue(fref.is_field_missing())
     fref.pb_text_set("abc")
     self.assertTrue(fref.is_field_present())
     fref.goto_xpath(
         pbcmc,
         "D,/company:company/company:employee[company:id='1234']/company:title"
     )
     self.assertTrue(fref.is_field_missing())
     fref.pb_text_set("MTS")
     self.assertTrue(fref.is_field_present())
     self.assertTrue(
         ProtobufC.Message.is_equal_deep(None, pbcmc, co.to_pbcm()))
     fref.goto_proto_name(emp.to_pbcm(), "id")
     try:
         fref.pb_text_set("hello")
     except GLib.GError:
         pass
     except e:
         self.fail('Unexpected exception thrown:', e)
     else:
         self.fail('ExpectedException not thrown')