11from pytest import mark
22
3- from shortener import parse_htaccess , choose
3+ from shortener import parse_htaccess , choose , load_redirects
44
55
66HTACCESS_1 = """
1313# duplicate targets
1414RedirectTemp /1-20 https://www.fluentpython.com/
1515RedirectTemp /ora https://www.oreilly.com/.../9781492056348/
16-
16+ RedirectTemp /2-10 http://example.com/
17+ RedirectTemp /10-2 http://example.com/
1718"""
1819
1920PARSED_HTACCESS_1 = [
2021 ('book' , 'https://www.oreilly.com/.../9781492056348/' ),
2122 ('home' , 'https://www.fluentpython.com/' ),
2223 ('1-20' , 'https://www.fluentpython.com/' ),
2324 ('ora' , 'https://www.oreilly.com/.../9781492056348/' ),
25+ ('2-10' , 'http://example.com/' ),
26+ ('10-2' , 'http://example.com/' ),
2427 ]
2528
2629def test_parse_htaccess ():
@@ -40,10 +43,24 @@ def test_choose(a, b, expected):
4043 assert res == expected
4144
4245
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
46+ def test_load_redirects ():
47+ expected = {
48+ 'home' : 'https://www.fluentpython.com/' ,
49+ '1-20' : 'https://www.fluentpython.com/' ,
50+ '2-10' : 'http://example.com/' ,
51+ '10-2' : 'http://example.com/' ,
52+ 'book' : 'https://www.oreilly.com/.../9781492056348/' ,
53+ 'ora' : 'https://www.oreilly.com/.../9781492056348/' ,
54+ }
55+ redirects , _ = load_redirects (PARSED_HTACCESS_1 )
56+ assert redirects == expected
57+
58+
59+ def test_load_redirect_targets ():
60+ expected = {
61+ 'https://www.fluentpython.com/' : 'home' ,
62+ 'https://www.oreilly.com/.../9781492056348/' : 'ora' ,
63+ 'http://example.com/' : '2-10' ,
64+ }
65+ _ , targets = load_redirects (PARSED_HTACCESS_1 )
66+ assert targets == expected
0 commit comments