Ejemplo n.º 1
0
def test_rsrreverser_reverse_some_params_and_options():
    reverser = RSRReverser('/test[/{param1}]/{param2}[/{param3}]/{param4}')
    params = {
        'param2': 'some',
        'param3': 'options',
    }
    reverser.reverse(params)
def test_rsrreverser_prune_options_some():
    reverser = RSRReverser('/test[/{option1}][/{option2}][/{option3}]')
    params = {
        'option2': 'some',
    }
    pruned_route = '/test/{option2}'
    assert reverser.prune_options(params) == pruned_route
def test_rsrreverser_substitute_parameters_some_params():
    reverser = RSRReverser('/test/{param1}/{param2}/{param3}')
    params = {
        'param2': 'lucky_number_2',
    }
    sub_route = '/test/{param1}/lucky_number_2/{param3}'
    assert reverser.substitute_parameters(params) == sub_route
Ejemplo n.º 4
0
def test_rsrreverser_reverse_some_params():
    reverser = RSRReverser('/test/{param1}/{param2}/{param3}')
    params = {
        'param1': 'epic',
        'param2': 'fail',
    }
    reverser.reverse(params)
def test_rsrreverser_substitute_parameters_custom():
    reverser = RSRReverser('/test/{param}/<param>', param_bounds='<>')
    params = {
        'param': 'fake_out',
    }
    reversed_url = '/test/{param}/fake_out'
    assert reverser.substitute_parameters(params) == reversed_url
Ejemplo n.º 6
0
def test_rsrreverer_reverse_plain():
    route = '/test/plain/route'
    reverser = RSRReverser(route)
    params = {
        'param1': 'test',
        'param2': 'no_sub',
    }
    assert reverser.reverse(params) == route
Ejemplo n.º 7
0
def test_rsrreverser_reverse_some_options():
    reverser = RSRReverser('/test[/{param1}][/{param2}][/{param3}]')
    params = {
        'param2': 'some',
        'param3': 'options',
    }
    reversed_url = '/test/some/options'
    assert reverser.reverse(params) == reversed_url
def test_rsrreverser_prune_options_nested_incomplete():
    reverser = RSRReverser('/test[/{option1}[/{option2}]][/{option3}]')
    params = {
        'option1': 'incomplete_nest',
        'option3': 'prune',
    }
    pruned_route = '/test/{option1}/{option3}'
    assert reverser.prune_options(params) == pruned_route
def test_rsrreverser_prune_options_nested_no_parent():
    reverser = RSRReverser('/test[/{option1}[/{option2}]][/{option3}]')
    params = {
        'option2': 'no_parent_nest',
        'option3': 'prune',
    }
    pruned_route = '/test/{option3}'
    assert reverser.prune_options(params) == pruned_route
def test_rsrreverser_prune_options_invalid():
    reverser = RSRReverser('/test[/{_o1}][/{o2;}][/{o^3}]')
    params = {
        '_o1': 'invalid',
        'o2;': 'but',
        'o^3': 'subs',
    }
    pruned_route = '/test/{_o1}/{o2;}/{o^3}'
    assert reverser.prune_options(params) == pruned_route
Ejemplo n.º 11
0
def test_rsrreverser_reverse_invalid_option():
    reverser = RSRReverser('/test[/{_p1}][/{p2;}][/{p^3}]')
    params = {
        '_p1': 'invalid',
        'p2;': 'but',
        'p^3': 'subs'
    }
    reversed_url = '/test/invalid/but/subs'
    assert reverser.reverse(params) == reversed_url
Ejemplo n.º 12
0
def test_rsrreverser_reverse_unsafe():
    reverser = RSRReverser('/test/{param1}/{param2}/{param3}')
    params = {
        'param1': '#$%^',
        'param2': 'unsafe_',
        'param3': ';unsafe'
    }
    reversed_url = '/test/#$%^/unsafe_/;unsafe'
    assert reverser.reverse(params) == reversed_url
Ejemplo n.º 13
0
def test_rsrreverser_reverse_full_options():
    reverser = RSRReverser('/test[/{param1}][/{param2}][/{param3}]')
    params = {
        'param1': 'options',
        'param2': 'are',
        'param3': 'fun',
    }
    reversed_url = '/test/options/are/fun'
    assert reverser.reverse(params) == reversed_url
def test_rsrreverser_prune_options_full():
    reverser = RSRReverser('/test[/{option1}][/{option2}][/{option3}]')
    params = {
        'option1': 'options',
        'option2': 'are',
        'option3': 'fun',
    }
    pruned_route = '/test/{option1}/{option2}/{option3}'
    assert reverser.prune_options(params) == pruned_route
Ejemplo n.º 15
0
def test_rsrreverser_reverse_nested_option_no_parent():
    route = '/test[/{param1}[/{param2}]]/sep[/{param3}[/{param4}]]'
    reverser = RSRReverser(route)
    params = {
        'param2': 'some',
        'param4': 'nested_options',
    }
    reversed_url = '/test/sep'
    assert reverser.reverse(params) == reversed_url
Ejemplo n.º 16
0
def test_rsrreverser_reverse_full_params_and_options():
    reverser = RSRReverser('/test[/{param1}]/{param2}[/{param3}]')
    params = {
        'param1': 'options',
        'param2': 'and',
        'param3': 'params_are_fun',
    }
    reversed_url = '/test/options/and/params_are_fun'
    assert reverser.reverse(params) == reversed_url
def test_rsrreverser_substitute_parameters_url_matches():
    route = '/test/this/case'
    reverser = RSRReverser(route)
    params = {
        'test': '1',
        'this': '2',
        'case': '3',
    }
    assert reverser.substitute_parameters(params) == route
Ejemplo n.º 18
0
def test_rsrreverser_reverse_full_nested_options():
    reverser = RSRReverser('/test[/{param1}[/{param2}[/{param3}]]]')
    params = {
        'param1': 'nested',
        'param2': 'options',
        'param3': 'are_fun',
    }
    reversed_url = '/test/nested/options/are_fun'
    assert reverser.reverse(params) == reversed_url
Ejemplo n.º 19
0
def test_rsrreverser_reverse_full_params():
    reverser = RSRReverser('/test/{param1}/{param2}/{param3}')
    params = {
        'param1': 'params',
        'param2': 'are',
        'param3': 'fun',
    }
    reversed_url = '/test/params/are/fun'
    assert reverser.reverse(params) == reversed_url
Ejemplo n.º 20
0
def test_rsrreverser_reverse_nested_incomplete():
    route = '/test[/{param1}[/{param2}]]/sep[/{param3}[/{param4}]]'
    reverser = RSRReverser(route)
    params = {
        'param1': 'some',
        'param3': 'nested_options',
    }
    reversed_url = '/test/some/sep/nested_options'
    assert reverser.reverse(params) == reversed_url
def test_rsrreverser_substitute_parameters_superset_params():
    route = '/test/{param1}/{param2}/{param3}'
    reverser = RSRReverser(route)
    params = {
        'aparam1': 'veni',
        'param2s': 'vidi',
        '{param3}': 'vici',
    }
    assert reverser.substitute_parameters(params) == route
def test_rsrreverser_substitute_parameters_complex_matching_invalid():
    route = '/test/{param1:_digits}/{param2:t&}/{param3:#$*}'
    reverser = RSRReverser(route)
    params = {
        'param1': 'complex',
        'param2': 'types',
        'param3': 'sub',
    }
    assert reverser.substitute_parameters(params) == route
def test_rsrreverser_substitute_parameters_simple_matching_invalid():
    reverser = RSRReverser('/test/{_p1}/{p2;}/{p^3}')
    params = {
        '_p1': 'these',
        'p2;': 'are',
        'p^3': 'invalid_but_match',
    }
    sub_route = '/test/these/are/invalid_but_match'
    assert reverser.substitute_parameters(params) == sub_route
def test_rsrreverser_substitute_parameters_url_unsafe():
    reverser = RSRReverser('/test/{param1}/{param2}/{param3}')
    params = {
        'param1': '#$%^',
        'param2': '{param1[invalid!]}',
        'param3': '?q=;',
    }
    sub_route = '/test/#$%^/{param1[invalid!]}/?q=;'
    assert reverser.substitute_parameters(params) == sub_route
def test_rsrreverser_substitute_parameters_all_params():
    reverser = RSRReverser('/test/{param1}/{param2}/{param3}')
    params = {
        'param1': 'veni',
        'param2': 'vidi',
        'param3': 'vici',
    }
    sub_route = '/test/veni/vidi/vici'
    assert reverser.substitute_parameters(params) == sub_route
def test_rsrreverser_substitute_parameters_complex():
    reverser = RSRReverser('/test/{param1:digits}/{param2:type}/{param3:01}')
    params = {
        'param1': 'complex',
        'param2': 'types',
        'param3': 'sub',
    }
    sub_route = '/test/complex/types/sub'
    assert reverser.substitute_parameters(params) == sub_route
def test_rsrreverser_substitute_parameters_all_params_with_options():
    reverser = RSRReverser('/test/{param1}[/{param2}[/{param3}]]')
    params = {
        'param1': 'tests',
        'param2': 'are',
        'param3': 'fun',
    }
    sub_route = '/test/tests[/are[/fun]]'
    assert reverser.substitute_parameters(params) == sub_route
def test_rsrreverser_prune_options_unsafe():
    reverser = RSRReverser('/test[/{option1}][/{option2}][/{option3}]')
    params = {
        'param1': 'nothing',
        'param2': 'to',
        'param3': 'see',
        'param4': 'here',
    }
    pruned_route = '/test'
    assert reverser.prune_options(params) == pruned_route
def test_rsrreverser_prune_options_nested_custom():
    route = '/test</=option1;</=option2;</=option3;>>>'
    reverser = RSRReverser(route, option_bounds='<>', param_bounds='=;')
    params = {
        'option1': 'custom',
        'option2': 'bounds',
        'option3': 'are_fun',
    }
    pruned_route = '/test/=option1;/=option2;/=option3;'
    assert reverser.prune_options(params) == pruned_route
def test_rsrreverse_get_option_start_end():
    route = '/test[]'
    reverser = RSRReverser(route)
    pos = len(route) - 2
    assert reverser.get_option_start() == pos