Exemplo n.º 1
0
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', '*/*')
Exemplo n.º 2
0
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', '*/*')
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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)