def test_diffs_deletions(self):
        curent_entries = [
            IssuerEntry('SHC Example Issuer 1', 'https://spec.smarthealth.cards/examples/issuer1', None, None),
            IssuerEntry('SHC Example Issuer 2', 'https://spec.smarthealth.cards/examples/issuer2', None, None),
            IssuerEntry('SHC Example Issuer 3', 'https://spec.smarthealth.cards/examples/issuer3', None, None),
            IssuerEntry('SHC Example Issuer 4', 'https://spec.smarthealth.cards/examples/issuer4', None, None),
            IssuerEntry('SHC Example Issuer 5', 'https://spec.smarthealth.cards/examples/issuer5', None, None),
        ]
        new_entries = [
            IssuerEntry('SHC Example Issuer 1', 'https://spec.smarthealth.cards/examples/issuer1', None, None),
            IssuerEntry('SHC Example Issuer 2', 'https://spec.smarthealth.cards/examples/issuer2', None, None),
            IssuerEntry('SHC Example Issuer 3', 'https://spec.smarthealth.cards/examples/issuer3', None, None),
        ]

        diffs = compute_diffs(curent_entries, new_entries)

        self.assertEqual(diffs.additions, [])
        self.assertEqual(
            diffs.deletions, 
            [
                IssuerEntry('SHC Example Issuer 4', 'https://spec.smarthealth.cards/examples/issuer4', None, None),
                IssuerEntry('SHC Example Issuer 5', 'https://spec.smarthealth.cards/examples/issuer5', None, None),
            ]
        )
        self.assertEqual(diffs.changes, [])
    def test_no_duplicates(self):
        entries = [
            IssuerEntry('SHC Example Issuer 1', 'https://spec.smarthealth.cards/examples/issuer1', None, None),
            IssuerEntry('SHC Example Issuer 2', 'https://spec.smarthealth.cards/examples/issuer2', None, None),
            IssuerEntry('SHC Example Issuer 3', 'https://spec.smarthealth.cards/examples/issuer3', None, None),
            IssuerEntry('SHC Example Issuer 4', 'https://spec.smarthealth.cards/examples/issuer4', None, None),
        ]

        actual = duplicate_entries(entries)
        expected = []
        self.assertEqual(actual, expected)
    def test_duplicate_issuer_names(self):
        actual = read_issuer_entries_from_tsv_file(
            f'{FIXTURE_DIRECTORY}/duplicate_issuer_names.tsv',
            encoding='ISO-8859-1'
        )

        expected = [
            IssuerEntry('Example Issuer', 'https://example.com/issuer', None, None),
            IssuerEntry('Example Issuer', 'https://example.com/issuer2', None, None),
        ]

        self.assertEqual(actual, expected)
    def test_valid_canonical_iss(self):
        entries = [
            IssuerEntry('State of California', 'https://myvaccinerecord.cdph.ca.gov/creds', None, None),
            IssuerEntry('State of Louisiana', 'https://healthcardcert.lawallet.com', None, None),
            IssuerEntry('SHC Example Issuer', 'https://spec.smarthealth.cards/examples/issuer', None, 'https://myvaccinerecord.cdph.ca.gov/creds'),
        ]

        actual = validate_entries(entries)

        expected = [ValidationResult(entry, True, []) for entry in entries]

        self.assertEqual(actual, expected)
    def test1(self):
        actual = read_issuer_entries_from_tsv_file(
            f'{FIXTURE_DIRECTORY}/example1.tsv',
            encoding='ISO-8859-1'
        )

        expected = [
            IssuerEntry('State of California', 'https://myvaccinerecord.cdph.ca.gov/creds', None, None),
            IssuerEntry('State of Louisiana', 'https://healthcardcert.lawallet.com', None, None),
        ]

        self.assertEqual(actual, expected)
    def test_validate_entries_integration(self):
        entries_from_json = read_issuer_entries_from_json_file(f'{FIXTURE_DIRECTORY}/sample_directory.json')

        expected = [
            IssuerEntry('State of California', 'https://myvaccinerecord.cdph.ca.gov/creds', 'https://myvaccinerecord.cdph.ca.gov', None),
            IssuerEntry('State of Louisiana', 'https://healthcardcert.lawallet.com', None, None),
            IssuerEntry('SHC Example Issuer', 'https://spec.smarthealth.cards/examples/issuer', None, 'https://healthcardcert.lawallet.com')
        ]

        self.assertEqual(entries_from_json, expected)

        validation_results = validate_entries(entries_from_json)
        valid = analyze_results(validation_results, True, True)
        self.assertTrue(valid)
    def test_invalid_website_entry(self):
        entries = [
            IssuerEntry('SHC Example Issuer', 'https://spec.smarthealth.cards/examples/issuer', 'https://spec.smarthealth.cards/unknown', None),
        ]

        actual = validate_entries(entries)
        self.assertEqual(actual[0].issuer_entry, entries[0])
        self.assertEqual(actual[0].is_valid, False)
        self.assertEqual(actual[0].issues[0].type, IssueType.WEBSITE_DOES_NOT_RESOLVE)
    def test_invalid_canonical_iss_multihop_reference(self):
        entries = [
            IssuerEntry('State of California', 'https://myvaccinerecord.cdph.ca.gov/creds', None, None),
            IssuerEntry('State of Louisiana', 'https://healthcardcert.lawallet.com', None, 'https://myvaccinerecord.cdph.ca.gov/creds'),
            IssuerEntry('SHC Example Issuer', 'https://spec.smarthealth.cards/examples/issuer', None, 'https://healthcardcert.lawallet.com'),
        ]

        actual = validate_entries(entries)
        self.assertEqual(actual[0].issuer_entry, entries[0])
        self.assertEqual(actual[0].is_valid, True)
        self.assertEqual(actual[0].issues, [])

        self.assertEqual(actual[1].issuer_entry, entries[1])
        self.assertEqual(actual[1].is_valid, True)
        self.assertEqual(actual[1].issues, [])

        self.assertEqual(actual[2].issuer_entry, entries[2])
        self.assertEqual(actual[2].is_valid, False)
        self.assertEqual(actual[2].issues[0].type, IssueType.CANONICAL_ISS_MULTIHOP_REFERENCE)
    def test_valid_and_invalid_entry(self):
        entries = [
            IssuerEntry('SHC Example Issuer', 'https://spec.smarthealth.cards/examples/issuer', None, None),
            IssuerEntry('Invalid issuer 1', 'https://spec.smarthealth.cards/examples/iss', None, None),
            IssuerEntry('Invalid issuer 2', 'https://spec.smarthealth.cards/examples/issuer/', None, None),
        ]

        actual = validate_entries(entries)
        self.assertEqual(actual[0].issuer_entry, entries[0])
        self.assertEqual(actual[0].is_valid, True)
        self.assertEqual(actual[0].issues, [])

        self.assertEqual(actual[1].issuer_entry, entries[1])
        self.assertEqual(actual[1].is_valid, False)
        self.assertEqual(actual[1].issues[0].type, IssueType.FETCH_EXCEPTION)

        self.assertEqual(actual[2].issuer_entry, entries[2])
        self.assertEqual(actual[2].is_valid, False)
        self.assertEqual(actual[2].issues[0].type, IssueType.ISS_ENDS_WITH_TRAILING_SLASH)
    def test_validate_entries1(self):
        entries = [
            IssuerEntry('SHC Example Issuer 1', 'https://spec.smarthealth.cards/examples/issuer', 'https://smarthealth.cards/', None),
            IssuerEntry('SHC Example Issuer 2', 'https://spec.smarthealth.cards/examples/issuer', 'https://spec.smarthealth.cards/', None),
            IssuerEntry('SHC Example Issuer 3', 'https://spec.smarthealth.cards/examples/issuer', None, None),
            IssuerEntry('SHC Example Issuer 4', 'https://spec.smarthealth.cards/examples/issuer', None, None),
            IssuerEntry('SHC Example Issuer 5', 'https://spec.smarthealth.cards/examples/issuer', None, None),
            IssuerEntry('SHC Example Issuer 6', 'https://spec.smarthealth.cards/examples/issuer', None, None),
            IssuerEntry('SHC Example Issuer 7', 'https://spec.smarthealth.cards/examples/issuer', None, None),
            IssuerEntry('SHC Example Issuer 8', 'https://spec.smarthealth.cards/examples/issuer', None, None),
            IssuerEntry('SHC Example Issuer 9', 'https://spec.smarthealth.cards/examples/issuer', None, None),
            IssuerEntry('SHC Example Issuer 10', 'https://spec.smarthealth.cards/examples/issuer', None, None)
        ]

        actual = validate_entries(entries)

        expected = [ValidationResult(entry, True, []) for entry in entries]

        self.assertEqual(actual, expected)
    def test_duplicate_iss_values(self):
        actual = read_issuer_entries_from_tsv_file(
            f'{FIXTURE_DIRECTORY}/duplicate_iss_values.tsv',
            encoding='ISO-8859-1'
        )

        ## ensure that last value seen in file is preserved
        expected = [
            IssuerEntry('Example Issuer 2', 'https://example.com/issuer', None, None),
        ]

        self.assertEqual(actual, expected)