mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
utils.path_with_added_args() improvements
* Now covered by unit tests * Preserves original order * Can handle multiple args of the same name, e.g. ?bar=1&bar=2
This commit is contained in:
parent
1c815207cc
commit
70ff615f1b
3 changed files with 29 additions and 9 deletions
|
|
@ -6,6 +6,7 @@ from datasette import utils
|
|||
import json
|
||||
import os
|
||||
import pytest
|
||||
from sanic.request import Request
|
||||
import sqlite3
|
||||
import tempfile
|
||||
from unittest.mock import patch
|
||||
|
|
@ -22,6 +23,25 @@ def test_urlsafe_components(path, expected):
|
|||
assert expected == utils.urlsafe_components(path)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('path,added_args,expected', [
|
||||
('/foo', {'bar': 1}, '/foo?bar=1'),
|
||||
('/foo?bar=1', {'baz': 2}, '/foo?bar=1&baz=2'),
|
||||
('/foo?bar=1&bar=2', {'baz': 3}, '/foo?bar=1&bar=2&baz=3'),
|
||||
('/foo?bar=1', {'bar': None}, '/foo'),
|
||||
# Test order is preserved
|
||||
('/?_facet=prim_state&_facet=area_name', {
|
||||
'prim_state': 'GA'
|
||||
}, '/?_facet=prim_state&_facet=area_name&prim_state=GA'),
|
||||
])
|
||||
def test_path_with_added_args(path, added_args, expected):
|
||||
request = Request(
|
||||
path.encode('utf8'),
|
||||
{}, '1.1', 'GET', None
|
||||
)
|
||||
actual = utils.path_with_added_args(request, added_args)
|
||||
assert expected == actual
|
||||
|
||||
|
||||
@pytest.mark.parametrize('row,pks,expected_path', [
|
||||
({'A': 'foo', 'B': 'bar'}, ['A', 'B'], 'foo,bar'),
|
||||
({'A': 'f,o', 'B': 'bar'}, ['A', 'B'], 'f%2Co,bar'),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue