1 | from django.contrib.admindocs.utils import replace_named_groups
|
---|
2 |
|
---|
3 | path_regex = r'entries/(?P<pk>[^/.]+)/relationships/(?P<related_field>\w+)'
|
---|
4 | expected_path = 'entries/<pk>/relationships/<related_field>'
|
---|
5 | path_regex_trailing = path_regex + '/'
|
---|
6 | expected_path_trailing = expected_path + '/'
|
---|
7 |
|
---|
8 | path_trailing = replace_named_groups(path_regex_trailing)
|
---|
9 | path = replace_named_groups(path_regex)
|
---|
10 |
|
---|
11 | print(' path:', path_regex)
|
---|
12 | print(' expected:', expected_path)
|
---|
13 | print(' got:', path)
|
---|
14 | print()
|
---|
15 | print('path_trailing:', path_regex_trailing)
|
---|
16 | print(' expected:', expected_path_trailing)
|
---|
17 | print(' got:', path_trailing)
|
---|
18 |
|
---|
19 | assert path_trailing == expected_path_trailing, "path with trailing slash didn't match expected"
|
---|
20 |
|
---|
21 | assert path == expected_path, "path without trailing slash didn't match expected"
|
---|
22 |
|
---|