MCPcopy
hub / github.com/httpie/cli / TestItemParsing

Class TestItemParsing

tests/test_cli.py:22–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20
21
22class TestItemParsing:
23 key_value_arg = KeyValueArgType(*constants.SEPARATOR_GROUP_ALL_ITEMS)
24
25 def test_invalid_items(self):
26 items = ['no-separator']
27 for item in items:
28 pytest.raises(argparse.ArgumentTypeError, self.key_value_arg, item)
29
30 def test_escape_separator(self):
31 items = RequestItems.from_args([
32 # headers
33 self.key_value_arg(r'foo\:bar:baz'),
34 self.key_value_arg(r'jack\@jill:hill'),
35
36 # data
37 self.key_value_arg(r'baz\=bar=foo'),
38
39 # files
40 self.key_value_arg(fr'bar\@baz@{FILE_PATH_ARG}'),
41 ])
42 # `HTTPHeadersDict` => `dict`
43 headers = dict(items.headers)
44
45 assert headers == {
46 'foo:bar': 'baz',
47 'jack@jill': 'hill',
48 }
49 assert items.data == {
50 'baz=bar': 'foo'
51 }
52 assert 'bar@baz' in items.files
53
54 @pytest.mark.parametrize('string, key, sep, value', [
55 ('path=c:\\windows', 'path', '=', 'c:\\windows'),
56 ('path=c:\\windows\\', 'path', '=', 'c:\\windows\\'),
57 ('path\\==c:\\windows', 'path=', '=', 'c:\\windows'),
58 ])
59 def test_backslash_before_non_special_character_does_not_escape(
60 self, string, key, sep, value
61 ):
62 expected = KeyValueArg(orig=string, key=key, sep=sep, value=value)
63 actual = self.key_value_arg(string)
64 assert actual == expected
65
66 def test_escape_longsep(self):
67 items = RequestItems.from_args([
68 self.key_value_arg(r'bob\:==foo'),
69 ])
70 assert items.params == {
71 'bob:': 'foo'
72 }
73
74 def test_valid_items(self):
75 items = RequestItems.from_args([
76 self.key_value_arg('string=value'),
77 self.key_value_arg('Header:value'),
78 self.key_value_arg('Unset-Header:'),
79 self.key_value_arg('Empty-Header;'),

Callers

nothing calls this directly

Calls 1

KeyValueArgTypeClass · 0.90

Tested by

no test coverage detected