Skip to content

Commit

Permalink
Added argument parsing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkbrzt committed Mar 4, 2012
1 parent f5d5ec2 commit 2195280
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -34,7 +34,7 @@ Will issue the following request:

{"name": "John", "email": "john@example.org"}

You can pass other types then just strings using the `field:=value` notation. It allows you to set arbitrary JSON to the data fields:
You can pass other types than just strings using the `field:=value` notation. It allows you to set arbitrary JSON to the data fields:

http PUT httpie.org/pies bool:=true list:=[1,2,3] 'object:={"a": "b", "c": "d"}'

Expand Down
40 changes: 39 additions & 1 deletion tests.py
@@ -1,6 +1,8 @@
import unittest
import argparse
from StringIO import StringIO
from httpie import __main__
from httpie import cli


TERMINAL_COLOR_END = '\x1b[39m'
Expand All @@ -17,7 +19,43 @@ def http(*args, **kwargs):
return stdout.getvalue()


# TODO: moar!
class TestItemParsing(unittest.TestCase):

def setUp(self):
self.kv = cli.KeyValueType(
cli.SEP_HEADERS,
cli.SEP_DATA,
cli.SEP_DATA_RAW_JSON
)

def test_invalid_items(self):
items = ['no-separator']
for item in items:
with self.assertRaises(argparse.ArgumentTypeError):
self.kv(item)

def test_valid_items(self):
headers, data = cli.parse_items([
self.kv('string=value'),
self.kv('header:value'),
self.kv('list:=["a", 1, {}, false]'),
self.kv('obj:={"a": "b"}'),
self.kv('eh:'),
self.kv('ed='),
self.kv('bool:=true'),
])
self.assertDictEqual(headers, {
'header': 'value',
'eh': ''
})
self.assertDictEqual(data, {
"ed": "",
"string": "value",
"bool": True,
"list": ["a", 1, {}, False],
"obj": {"a": "b"}
})


class TestHTTPie(unittest.TestCase):

Expand Down

0 comments on commit 2195280

Please sign in to comment.