def test_loading_vcards_from_disk(self): abook = address_book.VdirAddressBook('test', 'test/fixture/test.abook') # At this point we do not really care about the type of abook.contacts, # it could be a list or dict or set or whatever. self.assertEqual(len(abook.contacts), 0) abook.load() self.assertEqual(len(abook.contacts), 3)
def test_vcards_without_uid_generate_a_warning(self): abook = address_book.VdirAddressBook('test', 'test/fixture/minimal.abook') with self.assertLogs(level='WARNING') as cm: abook.load() messages = ['WARNING:root:Card minimal contact from address book test ' 'has no UID and will not be available.'] self.assertListEqual(cm.output, messages)
def test_unparsable_files_can_be_skipped(self): abook = address_book.VdirAddressBook('test', 'test/fixture/broken.abook', skip=True) with self.assertLogs(level='WARNING') as cm: abook.load() self.assertEqual(cm.output, [ 'WARNING:root:1 of 1 vCard files of ' 'address book test could not be parsed.' ])
def test_unparsable_files_can_be_skipped(self): abook = address_book.VdirAddressBook( 'test', 'test/fixture/broken.abook', skip=True) with self.assertLogs(level='WARNING') as cm: abook.load() self.assertEqual( cm.output, ['WARNING:root:Filtering some problematic tags from ' 'test/fixture/broken.abook/unparsable.vcf', 'WARNING:root:1 of 1 vCard files of address book test ' 'could not be parsed.'])
def test_unparsable_files_can_be_skipped(self): abook = address_book.VdirAddressBook('test', 'test/fixture/broken.abook', skip=True) with self.assertLogs(level='WARNING') as cm: abook.load() self.assertEqual( cm.output[0], 'WARNING:khard.carddav_object:Filtering some problematic tags ' 'from test/fixture/broken.abook/unparsable.vcf') # FIXME Remove this regex assert when either # https://github.com/eventable/vobject/issues/156 is closed or we drop # support for python 3.6 self.assertRegex( cm.output[1], 'ERROR:khard.address_book:Error: Could not parse file ' 'test/fixture/broken.abook/unparsable.vcf\n' 'At line [35]: Component VCARD was never closed') self.assertEqual( cm.output[2], 'WARNING:khard.address_book:1 of 1 vCard files of address book ' 'test could not be parsed.')
def __enter__(self): self.tempdir = tempfile.TemporaryDirectory() for card in self.vcards: shutil.copy(self._card_path(card), self.tempdir.name) return address_book.VdirAddressBook("tmp", self.tempdir.name)
def test_loading_unparsable_vcard_fails(self): abook = address_book.VdirAddressBook('test', 'test/fixture/broken.abook') with self.assertRaises(address_book.AddressBookParseError): with self.assertLogs(level='ERROR'): abook.load()
def test_search_in_source_files_only_loads_matching_cards(self): abook = address_book.VdirAddressBook('test', 'test/fixture/test.abook') abook.load(query=query.TermQuery('second'), search_in_source_files=True) self.assertEqual(len(abook.contacts), 1)
def test_issue_159_uid_search_doesnt_return_items_twice(self): # This was the first half of bug report #159. abook = address_book.VdirAddressBook('test', 'test/fixture/test.abook') c = abook.search(query.TermQuery('testuid1')) self.assertEqual(len(list(c)), 1)
def test_expand_env_var_that_is_nonempty(self): # Env vars set to nonempty string should expand appropriately. abook = address_book.VdirAddressBook( "test", "${}/test.abook".format("KHARD_FOO")) self.assertEqual(abook.path, "test/fixture/test.abook")
def test_do_not_expand_env_var_that_is_unset(self): # Unset env vars shouldn't expand. with self.assertRaises(FileNotFoundError): address_book.VdirAddressBook( "test", "test/fixture/test.abook${}".format("KHARD_FOO"))
def test_issue_159_uid_search_doesnt_return_items_twice(self): # This was the first half of bug report #159. abook = address_book.VdirAddressBook('test', 'test/fixture/foo.abook') c = abook.search('testuid1', method='uid') self.assertEqual(len(c), 1)