"Fossies" - the Fresh Open Source Software Archive

Member "http-prompt-2.1.0/tests/context/test_transform.py" (5 Mar 2021, 4738 Bytes) of package /linux/www/http-prompt-2.1.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 from http_prompt.context import Context
    2 from http_prompt.context import transform as t
    3 
    4 
    5 def test_extract_args_for_httpie_main_get():
    6     c = Context('http://localhost/things')
    7     c.headers.update({
    8         'Authorization': 'ApiKey 1234',
    9         'Accept': 'text/html'
   10     })
   11     c.querystring_params.update({
   12         'page': '2',
   13         'limit': '10'
   14     })
   15 
   16     args = t.extract_args_for_httpie_main(c, method='get')
   17     assert args == ['GET', 'http://localhost/things', 'limit==10', 'page==2',
   18                     'Accept:text/html', 'Authorization:ApiKey 1234']
   19 
   20 
   21 def test_extract_args_for_httpie_main_post():
   22     c = Context('http://localhost/things')
   23     c.headers.update({
   24         'Authorization': 'ApiKey 1234',
   25         'Accept': 'text/html'
   26     })
   27     c.options.update({
   28         '--verify': 'no',
   29         '--form': None
   30     })
   31     c.body_params.update({
   32         'full name': 'Jane Doe',
   33         'email': 'jane@example.com'
   34     })
   35 
   36     args = t.extract_args_for_httpie_main(c, method='post')
   37     assert args == ['--form', '--verify', 'no',
   38                     'POST', 'http://localhost/things',
   39                     'email=jane@example.com', 'full name=Jane Doe',
   40                     'Accept:text/html', 'Authorization:ApiKey 1234']
   41 
   42 
   43 def test_extract_raw_json_args_for_httpie_main_post():
   44     c = Context('http://localhost/things')
   45     c.body_json_params.update({
   46         'enabled': True,
   47         'items': ['foo', 'bar'],
   48         'object': {
   49             'id': 10,
   50             'name': 'test'
   51         }
   52     })
   53 
   54     args = t.extract_args_for_httpie_main(c, method='post')
   55     assert args == ['POST', 'http://localhost/things',
   56                     'enabled:=true', 'items:=["foo", "bar"]',
   57                     'object:={"id": 10, "name": "test"}']
   58 
   59 
   60 def test_format_to_httpie_get():
   61     c = Context('http://localhost/things')
   62     c.headers.update({
   63         'Authorization': 'ApiKey 1234',
   64         'Accept': 'text/html'
   65     })
   66     c.querystring_params.update({
   67         'page': '2',
   68         'limit': '10',
   69         'name': ['alice', 'bob bob']
   70     })
   71 
   72     output = t.format_to_httpie(c, method='get')
   73     assert output == ("http GET http://localhost/things "
   74                       "limit==10 name==alice 'name==bob bob' page==2 "
   75                       "Accept:text/html 'Authorization:ApiKey 1234'\n")
   76 
   77 
   78 def test_format_to_httpie_post():
   79     c = Context('http://localhost/things')
   80     c.headers.update({
   81         'Authorization': 'ApiKey 1234',
   82         'Accept': 'text/html'
   83     })
   84     c.options.update({
   85         '--verify': 'no',
   86         '--form': None
   87     })
   88     c.body_params.update({
   89         'full name': 'Jane Doe',
   90         'email': 'jane@example.com'
   91     })
   92 
   93     output = t.format_to_httpie(c, method='post')
   94     assert output == ("http --form --verify=no POST http://localhost/things "
   95                       "email=jane@example.com 'full name=Jane Doe' "
   96                       "Accept:text/html 'Authorization:ApiKey 1234'\n")
   97 
   98 
   99 def test_format_to_http_prompt_1():
  100     c = Context('http://localhost/things')
  101     c.headers.update({
  102         'Authorization': 'ApiKey 1234',
  103         'Accept': 'text/html'
  104     })
  105     c.querystring_params.update({
  106         'page': '2',
  107         'limit': '10'
  108     })
  109 
  110     output = t.format_to_http_prompt(c)
  111     assert output == ("cd http://localhost/things\n"
  112                       "limit==10\n"
  113                       "page==2\n"
  114                       "Accept:text/html\n"
  115                       "'Authorization:ApiKey 1234'\n")
  116 
  117 
  118 def test_format_to_http_prompt_2():
  119     c = Context('http://localhost/things')
  120     c.headers.update({
  121         'Authorization': 'ApiKey 1234',
  122         'Accept': 'text/html'
  123     })
  124     c.options.update({
  125         '--verify': 'no',
  126         '--form': None
  127     })
  128     c.body_params.update({
  129         'full name': 'Jane Doe',
  130         'email': 'jane@example.com'
  131     })
  132 
  133     output = t.format_to_http_prompt(c)
  134     assert output == ("--form\n"
  135                       "--verify=no\n"
  136                       "cd http://localhost/things\n"
  137                       "email=jane@example.com\n"
  138                       "'full name=Jane Doe'\n"
  139                       "Accept:text/html\n"
  140                       "'Authorization:ApiKey 1234'\n")
  141 
  142 
  143 def test_format_raw_json_string_to_http_prompt():
  144     c = Context('http://localhost/things')
  145     c.body_json_params.update({
  146         'bar': 'baz',
  147     })
  148 
  149     output = t.format_to_http_prompt(c)
  150     assert output == ("cd http://localhost/things\n"
  151                       "bar:='\"baz\"'\n")
  152 
  153 
  154 def test_extract_httpie_options():
  155     c = Context('http://localhost')
  156     c.options.update({
  157         '--verify': 'no',
  158         '--form': None
  159     })
  160 
  161     output = t._extract_httpie_options(c, excluded_keys=['--form'])
  162     assert output == ['--verify', 'no']