|
| 1 | +from pytest import mark |
| 2 | + |
| 3 | +from shortener import parse_htaccess, choose |
| 4 | + |
| 5 | + |
| 6 | +HTACCESS_1 = """ |
| 7 | +ErrorDocument 404 /404.html |
| 8 | +
|
| 9 | +# main resources |
| 10 | +RedirectTemp /book https://www.oreilly.com/.../9781492056348/ |
| 11 | +RedirectTemp /home https://www.fluentpython.com/ # extra content site |
| 12 | +
|
| 13 | +# duplicate targets |
| 14 | +RedirectTemp /1-20 https://www.fluentpython.com/ |
| 15 | +RedirectTemp /ora https://www.oreilly.com/.../9781492056348/ |
| 16 | +
|
| 17 | +""" |
| 18 | + |
| 19 | +PARSED_HTACCESS_1 = [ |
| 20 | + ('book', 'https://www.oreilly.com/.../9781492056348/'), |
| 21 | + ('home', 'https://www.fluentpython.com/'), |
| 22 | + ('1-20', 'https://www.fluentpython.com/'), |
| 23 | + ('ora', 'https://www.oreilly.com/.../9781492056348/'), |
| 24 | + ] |
| 25 | + |
| 26 | +def test_parse_htaccess(): |
| 27 | + res = list(parse_htaccess(HTACCESS_1)) |
| 28 | + assert res == PARSED_HTACCESS_1 |
| 29 | + |
| 30 | +@mark.parametrize('a,b,expected', [ |
| 31 | + ('a', 'b', 'a'), |
| 32 | + ('b', 'a', 'a'), |
| 33 | + ('aa', 'a', 'a'), |
| 34 | + ('a-a', 'aaa', 'aaa'), |
| 35 | + ('2-10', '10-2', '2-10'), |
| 36 | + ('p-1', '1-1', 'p-1'), |
| 37 | +]) |
| 38 | +def test_choose(a, b, expected): |
| 39 | + res = choose(a, b) |
| 40 | + assert res == expected |
| 41 | + |
| 42 | + |
| 43 | +# def test_load_redirects(): |
| 44 | +# expected = { |
| 45 | +# 'home': 'https://www.fluentpython.com/', |
| 46 | +# 'ora': 'https://www.oreilly.com/.../9781492056348/' |
| 47 | +# } |
| 48 | +# redirects, _ = load_redirects(PARSED_HTACCESS_1) |
| 49 | +# assert redirects == expected |
0 commit comments