Merge pull request #120 from python-hyper/bug/99 · python-hyper/uritemplate@06689ac · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Commit 06689ac

Browse files
authored
Merge pull request #120 from python-hyper/bug/99
Add new uritemplate-test testcases
2 parents a56e9ae + 9a3307e commit 06689ac

File tree

8 files changed

+318
-152
lines changed

8 files changed

+318
-152
lines changed

tests/fixtures/LICENSE

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
Copyright 2011- The Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.

tests/fixtures/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
These test are borrowed from https://github.com/uri-templates/uritemplate-test
2-
at commit: fdd5d611a849b922c2ff40fc3997fd265dd14c02
1+
32
URI Template Tests
43
==================
54

65
This is a set of tests for implementations of
7-
[RFC6570](http://tools.ietf.org/html/rfc6570) - URI Template. It is designed
6+
[RFC6570](https://datatracker.ietf.org/doc/html/rfc6570) - URI Template. It is designed
87
to be reused by any implementation, to improve interoperability and
98
implementation quality.
109

tests/fixtures/extended-tests.json

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,8 @@
2828
"testcases":[
2929

3030
[ "{/id*}" , "/person" ],
31-
[ "{/id*}{?fields,first_name,last.name,token}" , [
32-
"/person?fields=id,name,picture&first_name=John&last.name=Doe&token=12345",
33-
"/person?fields=id,picture,name&first_name=John&last.name=Doe&token=12345",
34-
"/person?fields=picture,name,id&first_name=John&last.name=Doe&token=12345",
35-
"/person?fields=picture,id,name&first_name=John&last.name=Doe&token=12345",
36-
"/person?fields=name,picture,id&first_name=John&last.name=Doe&token=12345",
37-
"/person?fields=name,id,picture&first_name=John&last.name=Doe&token=12345"]
38-
],
39-
["/search.{format}{?q,geocode,lang,locale,page,result_type}",
40-
[ "/search.json?q=URI%20Templates&geocode=37.76,-122.427&lang=en&page=5",
41-
"/search.json?q=URI%20Templates&geocode=-122.427,37.76&lang=en&page=5"]
42-
],
31+
[ "{/id*}{?fields,first_name,last.name,token}","/person?fields=id,name,picture&first_name=John&last.name=Doe&token=12345"],
32+
["/search.{format}{?q,geocode,lang,locale,page,result_type}","/search.json?q=URI%20Templates&geocode=37.76,-122.427&lang=en&page=5"],
4333
["/test{/Some%20Thing}", "/test/foo" ],
4434
["/set{?number}", "/set?number=6"],
4535
["/loc{?long,lat}" , "/loc?long=37.76&lat=-122.427"],
@@ -67,21 +57,8 @@
6757
},
6858
"testcases":[
6959

70-
[ "{/id*}" , ["/person/albums","/albums/person"] ],
71-
[ "{/id*}{?fields,token}" , [
72-
"/person/albums?fields=id,name,picture&token=12345",
73-
"/person/albums?fields=id,picture,name&token=12345",
74-
"/person/albums?fields=picture,name,id&token=12345",
75-
"/person/albums?fields=picture,id,name&token=12345",
76-
"/person/albums?fields=name,picture,id&token=12345",
77-
"/person/albums?fields=name,id,picture&token=12345",
78-
"/albums/person?fields=id,name,picture&token=12345",
79-
"/albums/person?fields=id,picture,name&token=12345",
80-
"/albums/person?fields=picture,name,id&token=12345",
81-
"/albums/person?fields=picture,id,name&token=12345",
82-
"/albums/person?fields=name,picture,id&token=12345",
83-
"/albums/person?fields=name,id,picture&token=12345"]
84-
]
60+
[ "{/id*}" , "/person/albums" ],
61+
[ "{/id*}{?fields,token}" , "/person/albums?fields=id,name,picture&token=12345" ]
8562
]
8663
},
8764
"Additional Examples 3: Empty Variables":{
@@ -114,5 +91,59 @@
11491
[ "{?1337*}", "?1337=leet&1337=as&1337=it&1337=can&1337=be"],
11592
[ "{?german*}", [ "?11=elf&12=zw%C3%B6lf", "?12=zw%C3%B6lf&11=elf"] ]
11693
]
94+
},
95+
"Additional Examples 5: Explode Combinations":{
96+
"variables" : {
97+
"id" : "admin",
98+
"token" : "12345",
99+
"tab" : "overview",
100+
"keys" : {
101+
"key1": "val1",
102+
"key2": "val2"
103+
}
104+
},
105+
"testcases":[
106+
[ "{?id,token,keys*}", [
107+
"?id=admin&token=12345&key1=val1&key2=val2",
108+
"?id=admin&token=12345&key2=val2&key1=val1"]
109+
],
110+
[ "{/id}{?token,keys*}", [
111+
"/admin?token=12345&key1=val1&key2=val2",
112+
"/admin?token=12345&key2=val2&key1=val1"]
113+
],
114+
[ "{?id,token}{&keys*}", [
115+
"?id=admin&token=12345&key1=val1&key2=val2",
116+
"?id=admin&token=12345&key2=val2&key1=val1"]
117+
],
118+
[ "/user{/id}{?token,tab}{&keys*}", [
119+
"/user/admin?token=12345&tab=overview&key1=val1&key2=val2",
120+
"/user/admin?token=12345&tab=overview&key2=val2&key1=val1"]
121+
]
122+
]
123+
},
124+
"Additional Examples 6: Reserved Expansion":{
125+
"variables" : {
126+
"id" : "admin%2F",
127+
"not_pct" : "%foo",
128+
"list" : ["red%25", "%2Fgreen", "blue "],
129+
"keys" : {
130+
"key1": "val1%2F",
131+
"key2": "val2%2F"
132+
}
133+
},
134+
"testcases": [
135+
["{+id}", "admin%2F"],
136+
["{#id}", "#admin%2F"],
137+
["{id}", "admin%252F"],
138+
["{+not_pct}", "%25foo"],
139+
["{#not_pct}", "#%25foo"],
140+
["{not_pct}", "%25foo"],
141+
["{+list}", "red%25,%2Fgreen,blue%20"],
142+
["{#list}", "#red%25,%2Fgreen,blue%20"],
143+
["{list}", "red%2525,%252Fgreen,blue%20"],
144+
["{+keys}", "key1,val1%2F,key2,val2%2F"],
145+
["{#keys}", "#key1,val1%2F,key2,val2%2F"],
146+
["{keys}", "key1,val1%252F,key2,val2%252F"]
147+
]
117148
}
118149
}

tests/fixtures/spec-examples-by-section.json

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
{
2+
"2.1 Literals" :
3+
{
4+
"variables": {
5+
"count" : ["one", "two", "three"]
6+
},
7+
"testcases" : [
8+
["'{count}'", "'one,two,three'"]
9+
]
10+
},
211
"3.2.1 Variable Expansion" :
312
{
413
"variables": {
@@ -17,7 +26,7 @@
1726
"x" : "1024",
1827
"y" : "768",
1928
"empty" : "",
20-
"empty_keys" : [],
29+
"empty_keys" : {},
2130
"undef" : null
2231
},
2332
"testcases" : [
@@ -50,7 +59,7 @@
5059
"x" : "1024",
5160
"y" : "768",
5261
"empty" : "",
53-
"empty_keys" : [],
62+
"empty_keys" : {},
5463
"undef" : null
5564
},
5665
"testcases" : [
@@ -104,7 +113,7 @@
104113
"x" : "1024",
105114
"y" : "768",
106115
"empty" : "",
107-
"empty_keys" : [],
116+
"empty_keys" : {},
108117
"undef" : null
109118
},
110119
"testcases" : [
@@ -161,7 +170,7 @@
161170
"x" : "1024",
162171
"y" : "768",
163172
"empty" : "",
164-
"empty_keys" : [],
173+
"empty_keys" : {},
165174
"undef" : null
166175
},
167176
"testcases" : [
@@ -203,7 +212,7 @@
203212
"x" : "1024",
204213
"y" : "768",
205214
"empty" : "",
206-
"empty_keys" : [],
215+
"empty_keys" : {},
207216
"undef" : null
208217
},
209218
"testcases" : [
@@ -255,7 +264,7 @@
255264
"x" : "1024",
256265
"y" : "768",
257266
"empty" : "",
258-
"empty_keys" : [],
267+
"empty_keys" : {},
259268
"undef" : null
260269
},
261270
"testcases" : [
@@ -307,7 +316,7 @@
307316
"x" : "1024",
308317
"y" : "768",
309318
"empty" : "",
310-
"empty_keys" : [],
319+
"empty_keys" : {},
311320
"undef" : null
312321
},
313322
"testcases" : [
@@ -358,7 +367,7 @@
358367
"x" : "1024",
359368
"y" : "768",
360369
"empty" : "",
361-
"empty_keys" : [],
370+
"empty_keys" : {},
362371
"undef" : null
363372
},
364373
"testcases" : [
@@ -406,7 +415,7 @@
406415
"x" : "1024",
407416
"y" : "768",
408417
"empty" : "",
409-
"empty_keys" : [],
418+
"empty_keys" : {},
410419
"undef" : null
411420
},
412421
"testcases" : [

tests/fixtures/spec-examples.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"testcases" : [
1010
["{var}", "value"],
11+
["'{var}'", "'value'"],
1112
["{hello}", "Hello%20World%21"]
1213
]
1314
},

tests/test_from_fixtures.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,20 @@ def _get_test(
4444
) -> t.Tuple[ExampleVariables, ExampleTemplatesAndResults]:
4545
test = t.cast(ExampleWithVariables, self.examples.get(section, {}))
4646
return (
47-
t.cast(ExampleVariables, test.get("variables", {})),
48-
t.cast(ExampleTemplatesAndResults, test.get("testcases", [])),
47+
test.get("variables", {}),
48+
test.get("testcases", []),
4949
)
5050

5151
def _test(self, testname: str) -> None:
5252
variables, testcases = self._get_test(testname)
5353
for template, expected in testcases:
5454
expected_templates = expected_set(expected)
5555
expanded = uritemplate.expand(template, variables)
56-
assert expanded in expected_templates
56+
assert expanded in expected_templates, ( # nosec
57+
f"expanded {template!r} with {variables!r} "
58+
f"and got {expanded!r} but expected one of "
59+
f"{expected_templates!r}"
60+
)
5761

5862

5963
class TestSpecExamples(FixtureMixin):
@@ -134,3 +138,11 @@ def test_additional_examples_3(self) -> None:
134138
def test_additional_examples_4(self) -> None:
135139
"""Check Additional Examples 4."""
136140
self._test("Additional Examples 4: Numeric Keys")
141+
142+
def test_additional_examples_5(self) -> None:
143+
"""Check Additional Examples 5."""
144+
self._test("Additional Examples 5: Explode Combinations")
145+
146+
def test_additional_examples_6(self) -> None:
147+
"""Check Additional Examples 6."""
148+
self._test("Additional Examples 6: Reserved Expansion")

tests/test_uritemplate.py

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ def test_semi_path_expansion(self) -> None:
562562
self.assertEqual(
563563
v._semi_path_expansion("foo", None, False, False), None
564564
)
565-
t.variables[0].operator = "?"
565+
t.variables[0].operator = variable.Operator.form_style_query
566566
self.assertEqual(
567567
v._semi_path_expansion("foo", ["bar", "bogus"], True, False),
568568
"foo=bar&foo=bogus",
@@ -588,50 +588,6 @@ def test_no_mutate(self) -> None:
588588
self.assertEqual(args, {})
589589

590590

591-
class TestURIVariable(unittest.TestCase):
592-
def setUp(self) -> None:
593-
self.v = variable.URIVariable("{foo}")
594-
595-
def test_post_parse(self) -> None:
596-
v = self.v
597-
self.assertEqual(v.join_str, ",")
598-
self.assertEqual(v.operator, "")
599-
self.assertEqual(v.safe, "")
600-
self.assertEqual(v.start, "")
601-
602-
def test_post_parse_plus(self) -> None:
603-
v = self.v
604-
v.operator = "+"
605-
v.post_parse()
606-
self.assertEqual(v.join_str, ",")
607-
self.assertEqual(v.safe, variable.URIVariable.reserved)
608-
self.assertEqual(v.start, "")
609-
610-
def test_post_parse_octothorpe(self) -> None:
611-
v = self.v
612-
v.operator = "#"
613-
v.post_parse()
614-
self.assertEqual(v.join_str, ",")
615-
self.assertEqual(v.safe, variable.URIVariable.reserved)
616-
self.assertEqual(v.start, "#")
617-
618-
def test_post_parse_question(self) -> None:
619-
v = self.v
620-
v.operator = "?"
621-
v.post_parse()
622-
self.assertEqual(v.join_str, "&")
623-
self.assertEqual(v.safe, "")
624-
self.assertEqual(v.start, "?")
625-
626-
def test_post_parse_ampersand(self) -> None:
627-
v = self.v
628-
v.operator = "&"
629-
v.post_parse()
630-
self.assertEqual(v.join_str, "&")
631-
self.assertEqual(v.safe, "")
632-
self.assertEqual(v.start, "&")
633-
634-
635591
class TestVariableModule(unittest.TestCase):
636592
def test_is_list_of_tuples(self) -> None:
637593
a_list = [(1, 2), (3, 4)]

0 commit comments

Comments
 (0)

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.