|
16 | 16 | from django.conf.urls import include
|
17 | 17 | from django.db import models
|
18 | 18 | from django.urls import re_path
|
| 19 | +from django.utils.functional import lazystr |
19 | 20 | from rest_framework import generics, serializers
|
20 | 21 |
|
21 | 22 | from drf_spectacular.openapi import AutoSchema
|
22 | 23 | from drf_spectacular.plumbing import (
|
23 | 24 | analyze_named_regex_pattern, build_basic_type, build_choice_field, detype_pattern,
|
24 |
| - follow_field_source, force_instance, get_list_serializer, is_field, is_serializer, |
25 |
| - resolve_type_hint, safe_ref, |
| 25 | + follow_field_source, force_instance, get_list_serializer, get_relative_url, is_field, |
| 26 | + is_serializer, resolve_type_hint, safe_ref, set_query_parameters, |
26 | 27 | )
|
27 | 28 | from drf_spectacular.validation import validate_schema
|
28 | 29 | from tests import generate_schema
|
@@ -437,3 +438,13 @@ def test_safe_ref():
|
437 | 438 | schema = safe_ref(schema)
|
438 | 439 | assert schema == {'$ref': '#/components/schemas/Foo'}
|
439 | 440 | assert safe_ref(schema) == safe_ref(schema)
|
| 441 | + |
| 442 | + |
| 443 | +def test_url_tooling_with_lazy_url(): |
| 444 | + some_url = "http://api.example.org/accounts/" |
| 445 | + |
| 446 | + assert get_relative_url(some_url) == "/accounts/" |
| 447 | + assert set_query_parameters(some_url, foo=123) == some_url + "?foo=123" |
| 448 | + |
| 449 | + assert get_relative_url(lazystr(some_url)) == "/accounts/" |
| 450 | + assert set_query_parameters(lazystr(some_url), foo=123) == some_url + "?foo=123" |
0 commit comments