If I have a function like this:
def get_vcard():
new_vcard = vobject.vCard()
new_vcard.add('fn')
new_card.fn.value = 'First Last'
work_phone = new_vcard.add('tel')
work_phone.value = '+18005555555'
mobile_phone = new_vcard.add('tel')
mobile_phone.value = '+18885555555'
And a test like this:
@patch('myapp.vobject.vCard', autospec=True)
def test_create_card(self, mock_vcard_constructor):
mock_vcard = mock_vcard_constructor.return_value
myapp.get_vcard()
self.assertEqual('First Last', mock_vcard.fn.value)
I want to also reference those different phone number objects so I can check that they are set correctly as well. I'm not sure how I can get a reference to them.
You can access all children of the vCard with
.getChildren()
For example:Now your unit test would look like:
Another possibility is accessing all the phone numbers with
vcard.contents['tel']
and then interating over them.