def test_basic(self): result = parse(["/foo exact http://giraffe.com/bar"]) assert result == [ Redirect( src="/foo", dst="http://giraffe.com/bar", internal=False, prefix=False ) ]
def test_basic(self): result = parse(['/foo exact http://giraffe.com/bar']) assert result == [ Redirect(src='/foo', dst='http://giraffe.com/bar', internal=False, prefix=False), ]
def test_multiline(self): result = parse(['/foo exact http://giraffe.com/bar', '/bar prefix http://elephant.org/', '/baz/bat internal-exact tapir', '/qux internal-prefix donkey']) assert result == [ Redirect(src='/foo', dst='http://giraffe.com/bar', internal=False, prefix=False), Redirect(src='/bar', dst='http://elephant.org/', internal=False, prefix=True), Redirect(src='/baz/bat', dst='tapir', internal=True, prefix=False), Redirect(src='/qux', dst='donkey', internal=True, prefix=True), ]
def test_ignores_whitespace(self, data): line = [ data.draw(st.text(alphabet=WHITESPACE)), '/foo', data.draw(st.text(alphabet=WHITESPACE, min_size=1)), 'exact', data.draw(st.text(alphabet=WHITESPACE, min_size=1)), 'http://giraffe.com/bar', data.draw(st.text(alphabet=WHITESPACE)), ] result = parse([''.join(line)]) assert result == [ Redirect(src='/foo', dst='http://giraffe.com/bar', internal=False, prefix=False), ]
def test_multiline(self): result = parse([ "/foo exact http://giraffe.com/bar", "/bar prefix http://elephant.org/", "/baz/bat internal-exact tapir", "/qux internal-prefix donkey", ]) assert result == [ Redirect(src="/foo", dst="http://giraffe.com/bar", internal=False, prefix=False), Redirect(src="/bar", dst="http://elephant.org/", internal=False, prefix=True), Redirect(src="/baz/bat", dst="tapir", internal=True, prefix=False), Redirect(src="/qux", dst="donkey", internal=True, prefix=True), ]
def test_multiline(self): result = parse( [ "/foo exact http://giraffe.com/bar", "/bar prefix http://elephant.org/", "/baz/bat internal-exact tapir", "/qux internal-prefix donkey", ] ) assert result == [ Redirect( src="/foo", dst="http://giraffe.com/bar", internal=False, prefix=False ), Redirect( src="/bar", dst="http://elephant.org/", internal=False, prefix=True ), Redirect(src="/baz/bat", dst="tapir", internal=True, prefix=False), Redirect(src="/qux", dst="donkey", internal=True, prefix=True), ]
def test_ignores_comment_lines(self, lines): result = parse(["#" + l for l in lines]) assert result == []
def test_ignores_whitespace_only_lines(self, lines): result = parse(lines) assert result == []
def test_unknown_type_raises(self): with pytest.raises(ParseError) as e: parse(["/foo magic http://giraffe.com/bar"]) assert "type" in str(e.value)
def test_unknown_type_raises(self): with pytest.raises(ParseError) as e: parse(['/foo magic http://giraffe.com/bar']) assert 'type' in e.value.message
def test_misformatted_line_raises(self): with pytest.raises(ParseError) as e: parse(['/foo exact somethingelse http://giraffe.com/bar']) assert 'invalid' in e.value.message
def test_misformatted_line_raises(self): with pytest.raises(ParseError) as e: parse(["/foo exact somethingelse http://giraffe.com/bar"]) assert "invalid" in str(e.value)