Beispiel #1
0
 def test_copy_from_person(self):
     person1 = RwpersonDbYang.Person()
     person1.name = "Alice"
     person1.email = "*****@*****.**"
     person1.employed = True
     person1.id = 12345
     person1.blob = bytearray([0x1, 0x2, 0x3, 0x0, 0x4])
     person1.emergency_phone.number = "123-456-7890"
     person1.phone.add()
     person1.phone[0].number = '100'
     person1.favourite.numbers = [10, 8]
     person1.favourite.colors = ['blue', 'purple']
     person1.favourite.places = ['LA', 'MA']
     self.person.copy_from(person1)
     self.assertEqual(self.person.name, "Alice")
     self.assertEqual(self.person.email, "*****@*****.**")
     self.assertTrue(self.person.employed)
     self.assertEqual(self.person.id, 12345)
     self.assertEqual(self.person.blob, bytearray([0x1, 0x2, 0x3, 0x0,
                                                   0x4]))
     self.assertEqual(self.person.emergency_phone.number, "123-456-7890")
     self.assertEqual(self.person.phone[0].number, '100')
     self.assertEqual(self.person.favourite.numbers[0], 10)
     self.assertEqual(self.person.favourite.numbers[1], 8)
     self.assertEqual(self.person.favourite.colors[0], 'blue')
     self.assertEqual(self.person.favourite.colors[1], 'purple')
     self.assertEqual(self.person.favourite.places[0], 'LA')
     self.assertEqual(self.person.favourite.places[1], 'MA')
Beispiel #2
0
    def setUp(self):
        self._serializer = ProtoMessageSerializer(RwpersonDbYang,
                                                  RwpersonDbYang.Person)

        self._sample_person = RwpersonDbYang.Person(name="Fred")
        self._model = RwYang.model_create_libncx()
        self._model.load_schema_ypbc(RwpersonDbYang.get_schema())
Beispiel #3
0
    def test_person_json_conversion(self):
        if sys.version_info < (3, 0):
            # to_json is python3 only
            return
        model, module = _load_person_db()
        person = _make_person()

        # recreate a person using to_json and from_json methods
        json_str = person.to_json(model)
        recreated_person = RwpersonDbYang.Person()
        recreated_person.from_json(model, json_str)

        self._assert_people_are_equal(person, recreated_person)
Beispiel #4
0
    def setUp(self):
        self._serializer = ProtoMessageSerializer(
            RwpersonDbYang,
            RwpersonDbYang.Person,
            RwProjectPersonDbYang,
            RwProjectPersonDbYang.YangData_RwProject_Project_Person,
        )

        self._sample_person = RwpersonDbYang.Person(name="Fred")
        self._project_person = RwProjectPersonDbYang.YangData_RwProject_Project_Person(
            name="Fred")
        self._model = RwYang.model_create_libyang()
        self._model.load_schema_ypbc(RwpersonDbYang.get_schema())
Beispiel #5
0
    def test_person_xml_conversion(self):
        # Open rwperson-database yang model
        yang = rw_peas.PeasPlugin('yangmodel_plugin-c', 'YangModelPlugin-1.0')
        yang_model = yang.get_interface('Model')
        yang_module = yang.get_interface('Module')
        yang_node = yang.get_interface('Node')
        yang_key = yang.get_interface('Key')
        model = yang_model.alloc()
        module = yang_model.load_module(model, "rwperson-db")

        #populate the person
        self.person.name = "test-name"
        self.person.email = "*****@*****.**"
        self.person.employed = True
        self.person.id = 12345
        self.person.emergency_phone.number = "123-456-7890"
        self.person.emergency_phone.type_yang = 'WORK'
        new_phone = [
            RwpersonDbYang.PhoneNumber(),
            RwpersonDbYang.PhoneNumber()
        ]
        new_phone[0].number = '#1'
        new_phone[1].number = '#2'
        self.person.phone = new_phone

        # recreate a person using to_xml and from_xml methods
        xml_str = self.person.to_xml(model)
        recreated_person = RwpersonDbYang.Person()
        recreated_person.from_xml(model, xml_str)
        print("Person           : ", self.person)
        print("Recreated Person : ", recreated_person)

        # check the newly created person is identical
        self.assertEqual(self.person.name, recreated_person.name)
        self.assertEqual(self.person.email, recreated_person.email)
        self.assertEqual(self.person.employed, recreated_person.employed)
        self.assertEqual(self.person.id, recreated_person.id)
        self.assertEqual(self.person.emergency_phone.number,
                         recreated_person.emergency_phone.number)
        self.assertEqual(self.person.emergency_phone.type_yang,
                         recreated_person.emergency_phone.type_yang)
        self.assertEqual(len(self.person.phone), len(recreated_person.phone))
        for phone, recreated_phone in zip(self.person.phone,
                                          recreated_person.phone):
            self.assertEqual(phone.number, recreated_phone.number)
            self.assertEqual(phone.type_yang, recreated_phone.type_yang)

        person = None
        recreated_person = None
        new_phone = None
Beispiel #6
0
def _make_person():
    person = RwpersonDbYang.Person()
    person.name = "test-name"
    person.email = "*****@*****.**"
    person.employed = True
    person.id = 12345
    person.emergency_phone.number = "123-456-7890"
    person.emergency_phone.type_yang = 'WORK'
    new_phone = [RwpersonDbYang.PhoneNumber(), RwpersonDbYang.PhoneNumber()]
    new_phone[0].number = '#1'
    new_phone[1].number = '#2'
    person.phone = new_phone

    return person
Beispiel #7
0
    def test_person_protobuf_conversion(self):
        self.person.name = "test-name"
        self.person.email = "*****@*****.**"
        self.person.employed = True
        self.person.id = 12345
        self.person.emergency_phone.number = "123-456-7890"
        self.person.emergency_phone.type_yang = 'WORK'
        new_phone = [
            RwpersonDbYang.PhoneNumber(),
            RwpersonDbYang.PhoneNumber()
        ]
        new_phone[0].number = '#1'
        new_phone[1].number = '#2'
        self.person.phone = new_phone

        # recreate a person using to_pbuf and from_pbuf methods
        pbuf = self.person.to_pbuf()
        recreated_person = RwpersonDbYang.Person()
        recreated_person.from_pbuf(pbuf)
        print("Person           : ", self.person)
        print("Recreated Person : ", recreated_person)

        # check the newly created person is identical
        self.assertEqual(self.person.name, recreated_person.name)
        self.assertEqual(self.person.email, recreated_person.email)
        self.assertEqual(self.person.employed, recreated_person.employed)
        self.assertEqual(self.person.id, recreated_person.id)
        self.assertEqual(self.person.emergency_phone.number,
                         recreated_person.emergency_phone.number)
        self.assertEqual(self.person.emergency_phone.type_yang,
                         recreated_person.emergency_phone.type_yang)
        self.assertEqual(len(self.person.phone), len(recreated_person.phone))
        for phone, recreated_phone in zip(self.person.phone,
                                          recreated_person.phone):
            self.assertEqual(phone.number, recreated_phone.number)
            self.assertEqual(phone.type_yang, recreated_phone.type_yang)

        ##
        # Need a testcase for this.
        ##
        ptr = recreated_person.to_ptr()
Beispiel #8
0
    def test_nullable(self):
        person = RwpersonDbYang.Person()
        person.name = "jeff"
        person.emergency_phone.type_yang = 'WORK'
        person.blob = bytearray([0x1, 0x2, 0x3, 0x0, 0x4])

        self.assertTrue(person.has_field('name'))
        try:
            person.name = None
        except Exception as e:
            self.fail('Unexpected exception thrown: ' + str(e))
        else:
            pass
        self.assertFalse(person.has_field('name'))

        self.assertTrue(person.emergency_phone.has_field('type'))
        try:
            person.emergency_phone.type_yang = None
        except TypeError:
            pass
        except Exception as e:
            self.fail('Unexpected exception thrown: ' + str(e))
        else:
            self.fail('ExpectedException not thrown')
        self.assertTrue(person.emergency_phone.has_field('type'))

        self.assertTrue(person.has_field('emergency_phone'))
        try:
            person.emergency_phone = None
        except Exception as e:
            self.fail('Unexpected exception thrown: ' + str(e))
        else:
            pass
        self.assertFalse(person.has_field('emergency_phone'))

        self.assertTrue(person.has_field('blob'))
        try:
            person.blob = None
        except TypeError:
            pass
        except Exception as e:
            self.fail('Unexpected exception thrown: ' + str(e))
        else:
            self.fail('ExpectedException not thrown')
        self.assertTrue(person.has_field('blob'))

        flat_person = RwpersonDbYang.FlatPerson()
        flat_person.name = "jeff"
        flat_person.emergency_phone.type_yang = 'WORK'
        flat_person.blob = bytearray([0x1, 0x2, 0x3, 0x0, 0x4])

        self.assertTrue(flat_person.has_field('name'))
        try:
            flat_person.name = None
        except TypeError:
            pass
        except Exception as e:
            self.fail('Unexpected exception thrown: ' + str(e))
        else:
            self.fail('ExpectedException not thrown')
        self.assertTrue(flat_person.has_field('name'))

        self.assertTrue(flat_person.emergency_phone.has_field('type'))
        try:
            flat_person.emergency_phone.type_yang = None
        except TypeError:
            pass
        except Exception as e:
            self.fail('Unexpected exception thrown: ' + str(e))
        else:
            self.fail('ExpectedException not thrown')
        self.assertTrue(flat_person.emergency_phone.has_field('type'))

        self.assertTrue(flat_person.has_field('emergency_phone'))
        try:
            flat_person.emergency_phone = None
        except TypeError:
            pass
        except Exception as e:
            self.fail('Unexpected exception thrown: ' + str(e))
        else:
            self.fail('ExpectedException not thrown')
        self.assertTrue(flat_person.has_field('emergency_phone'))

        self.assertTrue(flat_person.has_field('blob'))
        try:
            flat_person.blob = None
        except TypeError:
            pass
        except Exception as e:
            self.fail('Unexpected exception thrown: ' + str(e))
        else:
            self.fail('ExpectedException not thrown')
        self.assertTrue(flat_person.has_field('blob'))
Beispiel #9
0
 def setUp(self):
     self.person = RwpersonDbYang.Person()
     self.flat_person = RwpersonDbYang.FlatPerson()