Skip to content

Commit

Permalink
Fix create_django_urls for build correct regex pattern (#174)
Browse files Browse the repository at this point in the history
* Fix create_django_urls for build correct regex pattern

* Change change log. Increment version

* Wrap long strint to parentheses

Co-authored-by: Maxim Luzin <Lumax.rus@gmail.com>
  • Loading branch information
maximluzin and maximluzin authored Oct 6, 2020
1 parent 31781e4 commit e444690
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.1.1] - 2020-10-06

### Fixed
- Fix building a django url pattern for methods with multiple parameters in url_path

## [4.1.0] - 2020-07-15

### New features
Expand Down
15 changes: 15 additions & 0 deletions tests/winter_django/test_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from tests.controllers.controller_with_path_parameters import ControllerWithPathParameters
from winter_django import create_django_urls


def test_create_django_urls():
expected_url_pattern = (
'^controller_with_path_parameters/(?P<param1>[^/]+)/(?P<param2>\\d+)/'
'(?P<param3>((one)|(two)))/(?P<param4>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/'
'(?P<param5>((1)|(2)))/$'
)

urls = create_django_urls(ControllerWithPathParameters)

assert len(urls) == 1
assert urls[0].pattern.regex.pattern == expected_url_pattern
2 changes: 1 addition & 1 deletion winter/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '4.1.0'
__version__ = '4.1.1'
2 changes: 1 addition & 1 deletion winter_django/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def create_django_urls(controller_class: Type) -> List:
for url_path, routes in _group_routes_by_url_path(component.methods):
django_view = _create_django_view(controller_class, component, routes)
winter_url_path = f'^{url_path}$'
methods = (route.method for route in routes)
methods = [route.method for route in routes]
django_url_path = rewrite_uritemplate_with_regexps(winter_url_path, methods)
for route in routes:
django_urls.append(url(django_url_path, django_view, name=route.method.full_name))
Expand Down

0 comments on commit e444690

Please sign in to comment.