def test_escape_longsep(self): headers, data, files, params = input.parse_items([ self.key_value_type('bob\\:==foo'), ]) self.assertDictEqual(params, { 'bob:': 'foo', })
def test_valid_items(self): headers, data, files, params = input.parse_items([ self.key_value_type('string=value'), self.key_value_type('header:value'), self.key_value_type('list:=["a", 1, {}, false]'), self.key_value_type('obj:={"a": "b"}'), self.key_value_type('eh:'), self.key_value_type('ed='), self.key_value_type('bool:=true'), self.key_value_type('test-file@%s' % FILE_PATH_ARG), self.key_value_type('query==value'), ]) self.assertDictEqual(headers, {'header': 'value', 'eh': ''}) self.assertDictEqual( data, { "ed": "", "string": "value", "bool": True, "list": ["a", 1, {}, False], "obj": { "a": "b" }, }) self.assertDictEqual(params, { 'query': 'value', }) self.assertIn('test-file', files)
def test_valid_items(self): headers, data, files, params = input.parse_items([ self.key_value_type('string=value'), self.key_value_type('header:value'), self.key_value_type('list:=["a", 1, {}, false]'), self.key_value_type('obj:={"a": "b"}'), self.key_value_type('eh:'), self.key_value_type('ed='), self.key_value_type('bool:=true'), self.key_value_type('test-file@%s' % FILE_PATH_ARG), self.key_value_type('query==value'), ]) self.assertDictEqual(headers, { 'header': 'value', 'eh': '' }) self.assertDictEqual(data, { "ed": "", "string": "value", "bool": True, "list": ["a", 1, {}, False], "obj": {"a": "b"}, }) self.assertDictEqual(params, { 'query': 'value', }) self.assertIn('test-file', files)
def test_multiple_text_fields_with_same_field_name(self): items = input.parse_items( [self.key_value('text_field=a'), self.key_value('text_field=b')], data_class=DataDict) assert items.data['text_field'] == ['a', 'b'] assert list(items.data.items()) == [ ('text_field', 'a'), ('text_field', 'b'), ]
def test_multiple_text_fields_with_same_field_name(self): items = input.parse_items( [self.key_value('text_field=a'), self.key_value('text_field=b')], data_class=DataDict ) assert items.data['text_field'] == ['a', 'b'] assert list(items.data.items()) == [ ('text_field', 'a'), ('text_field', 'b'), ]
def test_valid_items(self): items = input.parse_items([ self.key_value('string=value'), self.key_value('Header:value'), self.key_value('Unset-Header:'), self.key_value('Empty-Header;'), self.key_value('list:=["a", 1, {}, false]'), self.key_value('obj:={"a": "b"}'), self.key_value('ed='), self.key_value('bool:=true'), self.key_value('file@' + FILE_PATH_ARG), self.key_value('query==value'), self.key_value('string-embed=@' + FILE_PATH_ARG), self.key_value('raw-json-embed:=@' + JSON_FILE_PATH_ARG), ]) # Parsed headers # `requests.structures.CaseInsensitiveDict` => `dict` headers = dict(items.headers._store.values()) assert headers == { 'Header': 'value', 'Unset-Header': None, 'Empty-Header': '' } # Parsed data raw_json_embed = items.data.pop('raw-json-embed') assert raw_json_embed == json.loads(JSON_FILE_CONTENT) items.data['string-embed'] = items.data['string-embed'].strip() assert dict(items.data) == { "ed": "", "string": "value", "bool": True, "list": ["a", 1, {}, False], "obj": { "a": "b" }, "string-embed": FILE_CONTENT, } # Parsed query string parameters assert items.params == {'query': 'value'} # Parsed file fields assert 'file' in items.files assert (items.files['file'][1].read().strip().decode('utf8') == FILE_CONTENT)
def test_valid_items(self): headers, data, files, params = input.parse_items([ self.key_value_type('string=value'), self.key_value_type('header:value'), self.key_value_type('list:=["a", 1, {}, false]'), self.key_value_type('obj:={"a": "b"}'), self.key_value_type('eh:'), self.key_value_type('ed='), self.key_value_type('bool:=true'), self.key_value_type('file@' + FILE_PATH_ARG), self.key_value_type('query==value'), self.key_value_type('string-embed=@' + FILE_PATH_ARG), self.key_value_type('raw-json-embed:=@' + JSON_FILE_PATH_ARG), ]) # Parsed headers # `requests.structures.CaseInsensitiveDict` => `dict` headers = dict(headers._store.values()) self.assertDictEqual(headers, { 'header': 'value', 'eh': '' }) # Parsed data raw_json_embed = data.pop('raw-json-embed') self.assertDictEqual(raw_json_embed, json.loads( JSON_FILE_CONTENT.decode('utf8'))) data['string-embed'] = data['string-embed'].strip() self.assertDictEqual(dict(data), { "ed": "", "string": "value", "bool": True, "list": ["a", 1, {}, False], "obj": {"a": "b"}, "string-embed": FILE_CONTENT, }) # Parsed query string parameters self.assertDictEqual(params, { 'query': 'value', }) # Parsed file fields self.assertIn('file', files) self.assertEqual(files['file'][1].read().strip().decode('utf8'), FILE_CONTENT)
def test_valid_items(self): headers, data, files, params = input.parse_items([ self.key_value_type('string=value'), self.key_value_type('header:value'), self.key_value_type('list:=["a", 1, {}, false]'), self.key_value_type('obj:={"a": "b"}'), self.key_value_type('eh:'), self.key_value_type('ed='), self.key_value_type('bool:=true'), self.key_value_type('file@' + FILE_PATH_ARG), self.key_value_type('query==value'), self.key_value_type('string-embed=@' + FILE_PATH_ARG), self.key_value_type('raw-json-embed:=@' + JSON_FILE_PATH_ARG), ]) # Parsed headers # `requests.structures.CaseInsensitiveDict` => `dict` headers = dict(headers._store.values()) self.assertDictEqual(headers, {'header': 'value', 'eh': ''}) # Parsed data raw_json_embed = data.pop('raw-json-embed') self.assertDictEqual(raw_json_embed, json.loads(JSON_FILE_CONTENT.decode('utf8'))) data['string-embed'] = data['string-embed'].strip() self.assertDictEqual( dict(data), { "ed": "", "string": "value", "bool": True, "list": ["a", 1, {}, False], "obj": { "a": "b" }, "string-embed": FILE_CONTENT, }) # Parsed query string parameters self.assertDictEqual(params, { 'query': 'value', }) # Parsed file fields self.assertIn('file', files) self.assertEqual(files['file'][1].read().strip().decode('utf8'), FILE_CONTENT)
def test_valid_items(self): items = input.parse_items([ self.key_value('string=value'), self.key_value('Header:value'), self.key_value('Unset-Header:'), self.key_value('Empty-Header;'), self.key_value('list:=["a", 1, {}, false]'), self.key_value('obj:={"a": "b"}'), self.key_value('ed='), self.key_value('bool:=true'), self.key_value('file@' + FILE_PATH_ARG), self.key_value('query==value'), self.key_value('string-embed=@' + FILE_PATH_ARG), self.key_value('raw-json-embed:=@' + JSON_FILE_PATH_ARG), ]) # Parsed headers # `requests.structures.CaseInsensitiveDict` => `dict` headers = dict(items.headers._store.values()) assert headers == { 'Header': 'value', 'Unset-Header': None, 'Empty-Header': '' } # Parsed data raw_json_embed = items.data.pop('raw-json-embed') assert raw_json_embed == json.loads(JSON_FILE_CONTENT) items.data['string-embed'] = items.data['string-embed'].strip() assert dict(items.data) == { "ed": "", "string": "value", "bool": True, "list": ["a", 1, {}, False], "obj": {"a": "b"}, "string-embed": FILE_CONTENT, } # Parsed query string parameters assert items.params == {'query': 'value'} # Parsed file fields assert 'file' in items.files assert (items.files['file'][1].read().strip(). decode('utf8') == FILE_CONTENT)
def test_escape_separator(self): items = input.parse_items( [ # headers self.key_value(r"foo\:bar:baz"), self.key_value(r"jack\@jill:hill"), # data self.key_value(r"baz\=bar=foo"), # files self.key_value(r"bar\@baz@%s" % FILE_PATH_ARG), ] ) # `requests.structures.CaseInsensitiveDict` => `dict` headers = dict(items.headers._store.values()) assert headers == {"foo:bar": "baz", "jack@jill": "hill"} assert items.data == {"baz=bar": "foo"} assert "bar@baz" in items.files
def test_escape(self): headers, data, files, params = input.parse_items([ # headers self.key_value_type('foo\\:bar:baz'), self.key_value_type('jack\\@jill:hill'), # data self.key_value_type('baz\\=bar=foo'), # files self.key_value_type('bar\\@baz@%s' % FILE_PATH_ARG) ]) self.assertDictEqual(headers, { 'foo:bar': 'baz', 'jack@jill': 'hill', }) self.assertDictEqual(data, { 'baz=bar': 'foo', }) self.assertIn('bar@baz', files)
def test_escape(self): headers, data, files, params = input.parse_items([ # headers self.key_value_type('foo\\:bar:baz'), self.key_value_type('jack\\@jill:hill'), # data self.key_value_type('baz\\=bar=foo'), # files self.key_value_type('bar\\@baz@%s' % FILE_PATH_ARG) ]) # `requests.structures.CaseInsensitiveDict` => `dict` headers = dict(headers._store.values()) assert headers == { 'foo:bar': 'baz', 'jack@jill': 'hill', } assert data == {'baz=bar': 'foo'} assert 'bar@baz' in files
def test_valid_items(self): items = input.parse_items( [ self.key_value("string=value"), self.key_value("header:value"), self.key_value('list:=["a", 1, {}, false]'), self.key_value('obj:={"a": "b"}'), self.key_value("eh:"), self.key_value("ed="), self.key_value("bool:=true"), self.key_value("file@" + FILE_PATH_ARG), self.key_value("query==value"), self.key_value("string-embed=@" + FILE_PATH_ARG), self.key_value("raw-json-embed:=@" + JSON_FILE_PATH_ARG), ] ) # Parsed headers # `requests.structures.CaseInsensitiveDict` => `dict` headers = dict(items.headers._store.values()) assert headers == {"header": "value", "eh": ""} # Parsed data raw_json_embed = items.data.pop("raw-json-embed") assert raw_json_embed == json.loads(JSON_FILE_CONTENT) items.data["string-embed"] = items.data["string-embed"].strip() assert dict(items.data) == { "ed": "", "string": "value", "bool": True, "list": ["a", 1, {}, False], "obj": {"a": "b"}, "string-embed": FILE_CONTENT, } # Parsed query string parameters assert items.params == {"query": "value"} # Parsed file fields assert "file" in items.files assert items.files["file"][1].read().strip().decode("utf8") == FILE_CONTENT
def test_escape_separator(self): items = input.parse_items([ # headers self.key_value(r'foo\:bar:baz'), self.key_value(r'jack\@jill:hill'), # data self.key_value(r'baz\=bar=foo'), # files self.key_value(r'bar\@baz@%s' % FILE_PATH_ARG), ]) # `requests.structures.CaseInsensitiveDict` => `dict` headers = dict(items.headers._store.values()) assert headers == { 'foo:bar': 'baz', 'jack@jill': 'hill', } assert items.data == {'baz=bar': 'foo'} assert 'bar@baz' in items.files
def test_escape_longsep(self): headers, data, files, params = input.parse_items([ self.key_value_type('bob\\:==foo'), ]) assert params == {'bob:': 'foo'}
def test_escape_longsep(self): items = input.parse_items([ self.key_value(r'bob\:==foo'), ]) assert items.params == {'bob:': 'foo'}
def test_multiple_file_fields_with_same_field_name(self): items = input.parse_items([ self.key_value('file_field@' + FILE_PATH_ARG), self.key_value('file_field@' + FILE_PATH_ARG), ]) assert len(items.files['file_field']) == 2
def test_multiple_text_fields_with_same_field_name(self): items = input.parse_items([self.key_value("text_field=a"), self.key_value("text_field=b")], data_class=DataDict) assert items.data["text_field"] == ["a", "b"] assert list(items.data.items()) == [("text_field", "a"), ("text_field", "b")]
def test_escape_longsep(self): items = input.parse_items([self.key_value(r"bob\:==foo")]) assert items.params == {"bob:": "foo"}