How to use vcard - 10 common examples

To help you get started, we’ve selected a few vcard examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github l0b0 / vcard / tests / test_package.py View on Github external
def test_valid(self):
        """Valid (but not necessarily sane) vCards"""
        for vcard_file in VCARDS_VALID:
            vcard_text = _get_vcard_file(vcard_file)
            if vcard_text is None:
                continue

            try:
                with warnings.catch_warnings(record=True):
                    vc_obj = vcard_validator.VCard(vcard_text, filename=vcard_file)
                self.assertNotEqual(vc_obj, None)
            except vcard_errors.VCardError as error:
                error_message = '\n\n'.join((
                    'Expected valid vCard for {vcard_file!r}, but it failed to validate'.format(
                        vcard_file=vcard_file
                    ),
                    str(error)
                ))
                self.fail(error_message)
github l0b0 / vcard / tests / test_package.py View on Github external
def test_valid(self):
        """Valid (but not necessarily sane) vCards"""
        for vcard_file in VCARDS_VALID:
            vcard_text = _get_vcard_file(vcard_file)
            if vcard_text is None:
                continue

            try:
                with warnings.catch_warnings(record=True):
                    vc_obj = vcard_validator.VCard(vcard_text, filename=vcard_file)
                self.assertNotEqual(vc_obj, None)
            except vcard_errors.VCardError as error:
                error_message = '\n\n'.join((
                    'Expected valid vCard for {vcard_file!r}, but it failed to validate'.format(
                        vcard_file=vcard_file
                    ),
                    str(error)
                ))
                self.fail(error_message)
github l0b0 / vcard / tests / test_package.py View on Github external
def test_online(self):
        """vCards in references which are invalid"""
        for vcard_file in VCARDS_REFERENCE_ERRORS:
            vcard_text = _get_vcard_file(vcard_file)
            if vcard_text is None:
                continue

            with warnings.catch_warnings(record=True):
                self.assertRaises(
                    vcard_errors.VCardError,
                    vcard_validator.VCard,
                    vcard_text)
github l0b0 / vcard / tests / test_package.py View on Github external
def test_failing(self):
        """vCards with errors"""
        for test_group in VCARDS_WITH_ERROR:
            for vcard_file in test_group['vcards']:
                vcard_text = _get_vcard_file(vcard_file)
                if vcard_text is None:
                    continue

                try:
                    with warnings.catch_warnings(record=True):
                        vcard_validator.VCard(vcard_text, filename=vcard_file)
                        self.fail('Invalid vCard created:\n{0}'.format(vcard_text))
                except vcard_errors.VCardError as error:
                    error_message = '\n\n'.join((
                        'Wrong message for vCard {vcard_file!r}:'.format(vcard_file=vcard_file),
                        'Expected: {expected}'.format(expected=test_group['message']),
                        'Got: {got}'.format(got=str(error)),
                        ))
                    self.assertTrue(
                        test_group['message'] in str(error),
                        msg=error_message
                    )
github l0b0 / vcard / tests / test_vcard.py View on Github external
def test_main_fails_when_vcard_validator_fails_on_first_file(self, vcard_validator_mock, parse_arguments_mock):
        parse_arguments_mock.return_value = ARGUMENTS_WITH_PATHS
        vcard_validator_mock.side_effect = [
            mock.Mock(spec=vcard.VcardValidator, result='non-empty'),
            mock.Mock(spec=vcard.VcardValidator, result=None)]
        self.assertEqual(1, vcard.main())
github l0b0 / vcard / tests / test_vcard.py View on Github external
def test_main_fails_when_argument_parsing_fails(self, parse_arguments_mock):
        parse_arguments_mock.side_effect = vcard.UsageError('error')
        self.assertEqual(2, vcard.main())
github l0b0 / vcard / tests / test_vcard.py View on Github external
def test_main_succeeds_when_vcard_validator_returns_nothing(self, vcard_validator_mock, parse_arguments_mock):
        parse_arguments_mock.return_value = ARGUMENTS_WITH_PATH
        vcard_validator_mock.return_value.result = None
        self.assertEqual(0, vcard.main())
github l0b0 / vcard / tests / test_vcard.py View on Github external
def test_main_fails_when_vcard_validator_fails(self, vcard_validator_mock, parse_arguments_mock):
        parse_arguments_mock.return_value = ARGUMENTS_WITH_PATH
        vcard_validator_mock.return_value.result = 'non-empty'
        self.assertEqual(1, vcard.main())
github l0b0 / vcard / tests / test_vcard.py View on Github external
def test_parse_arguments_succeeds_with_multiple_paths(self):
        path1 = '/some/path'
        path2 = '/other/path'
        arguments = [path1, path2]
        expected_paths = arguments

        actual_paths = vcard.parse_arguments(arguments).paths

        self.assertEqual(expected_paths, actual_paths)
github l0b0 / vcard / tests / test_vcard.py View on Github external
def test_parse_arguments_verbose_off_by_default(self):
        path = '/some/path'

        actual_verbosity = vcard.parse_arguments([path]).verbose

        self.assertFalse(actual_verbosity)