def test_match(): mimeaccept = MIMEAccept('Content-Type', 'image/jpg') assert mimeaccept._match('image/jpg', 'image/jpg') assert mimeaccept._match('image/*', 'image/jpg') assert mimeaccept._match('*/*', 'image/jpg') assert not mimeaccept._match('text/html', 'image/jpg') assert_raises(ValueError, mimeaccept._match, 'image/jpg', '*/*')
def test_match(): mimeaccept = MIMEAccept('image/jpg') assert mimeaccept._match('image/jpg', 'image/jpg') assert mimeaccept._match('image/*', 'image/jpg') assert mimeaccept._match('*/*', 'image/jpg') assert not mimeaccept._match('text/html', 'image/jpg') assert_raises(ValueError, mimeaccept._match, 'image/jpg', '*/*')
def test_match(): mimeaccept = MIMEAccept("image/jpg") assert mimeaccept._match("image/jpg", "image/jpg") assert mimeaccept._match("image/*", "image/jpg") assert mimeaccept._match("*/*", "image/jpg") assert not mimeaccept._match("text/html", "image/jpg") mismatches = [("B/b", "A/a"), ("B/b", "B/a"), ("B/b", "A/b"), ("A/a", "B/b"), ("B/a", "B/b"), ("A/b", "B/b")] for mask, offer in mismatches: assert not mimeaccept._match(mask, offer)
def test_match(): mimeaccept = MIMEAccept('image/jpg') assert mimeaccept._match('image/jpg', 'image/jpg') assert mimeaccept._match('image/*', 'image/jpg') assert mimeaccept._match('*/*', 'image/jpg') assert not mimeaccept._match('text/html', 'image/jpg') mismatches = [('B/b', 'A/a'), ('B/b', 'B/a'), ('B/b', 'A/b'), ('A/a', 'B/b'), ('B/a', 'B/b'), ('A/b', 'B/b')] for mask, offer in mismatches: assert not mimeaccept._match(mask, offer)
def test_match(): mimeaccept = MIMEAccept('image/jpg') assert mimeaccept._match('image/jpg', 'image/jpg') assert mimeaccept._match('image/*', 'image/jpg') assert mimeaccept._match('*/*', 'image/jpg') assert not mimeaccept._match('text/html', 'image/jpg') mismatches = [ ('B/b', 'A/a'), ('B/b', 'B/a'), ('B/b', 'A/b'), ('A/a', 'B/b'), ('B/a', 'B/b'), ('A/b', 'B/b') ] for mask, offer in mismatches: assert not mimeaccept._match(mask, offer)
def test_wildcard_matching(): """ Wildcard matching forces the match to take place against the type or subtype of the mask and offer (depending on where the wildcard matches) """ mimeaccept = MIMEAccept('type/subtype') matches = [ ('*/*', '*/*'), ('*/*', 'A/*'), ('*/*', '*/a'), ('*/*', 'A/a'), ('A/*', '*/*'), ('A/*', 'A/*'), ('A/*', '*/a'), ('A/*', 'A/a'), ('*/a', '*/*'), ('*/a', 'A/*'), ('*/a', '*/a'), ('*/a', 'A/a'), ('A/a', '*/*'), ('A/a', 'A/*'), ('A/a', '*/a'), ('A/a', 'A/a'), # Offers might not contain a subtype ('*/*', '*'), ('A/*', '*'), ('*/a', '*')] for mask, offer in matches: assert mimeaccept._match(mask, offer) # Test malformed mask and offer variants where either is missing # a type or subtype assert mimeaccept._match('A', offer) assert mimeaccept._match(mask, 'a') mismatches = [ ('B/b', 'A/*'), ('B/*', 'A/a'), ('B/*', 'A/*'), ('*/b', '*/a')] for mask, offer in mismatches: assert not mimeaccept._match(mask, offer)
def test_wildcard_matching(): """ Wildcard matching forces the match to take place against the type or subtype of the mask and offer (depending on where the wildcard matches) """ mimeaccept = MIMEAccept("type/subtype") matches = [ ("*/*", "*/*"), ("*/*", "A/*"), ("*/*", "*/a"), ("*/*", "A/a"), ("A/*", "*/*"), ("A/*", "A/*"), ("A/*", "*/a"), ("A/*", "A/a"), ("*/a", "*/*"), ("*/a", "A/*"), ("*/a", "*/a"), ("*/a", "A/a"), ("A/a", "*/*"), ("A/a", "A/*"), ("A/a", "*/a"), ("A/a", "A/a"), # Offers might not contain a subtype ("*/*", "*"), ("A/*", "*"), ("*/a", "*"), ] for mask, offer in matches: assert mimeaccept._match(mask, offer) # Test malformed mask and offer variants where either is missing # a type or subtype assert mimeaccept._match("A", offer) assert mimeaccept._match(mask, "a") mismatches = [("B/b", "A/*"), ("B/*", "A/a"), ("B/*", "A/*"), ("*/b", "*/a")] for mask, offer in mismatches: assert not mimeaccept._match(mask, offer)