"Fossies" - the Fresh Open Source Software Archive

Member "http-prompt-2.1.0/tests/test_completer.py" (5 Mar 2021, 4524 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 # -*- coding: utf-8 -*-
    2 from __future__ import unicode_literals
    3 
    4 import six
    5 import unittest
    6 
    7 from prompt_toolkit.document import Document
    8 
    9 from http_prompt.completer import HttpPromptCompleter
   10 from http_prompt.context import Context
   11 
   12 
   13 class TestCompleter(unittest.TestCase):
   14 
   15     def setUp(self):
   16         self.context = Context('http://localhost', spec={
   17             'paths': {
   18                 '/users': {},
   19                 '/users/{username}': {},
   20                 '/users/{username}/events': {},
   21                 '/users/{username}/orgs': {},
   22                 '/orgs': {},
   23                 '/orgs/{org}': {},
   24                 '/orgs/{org}/events': {},
   25                 '/orgs/{org}/members': {}
   26             }
   27         })
   28         self.completer = HttpPromptCompleter(self.context)
   29         self.completer_event = None
   30 
   31     def get_completions(self, command):
   32         if not isinstance(command, six.text_type):
   33             command = six.u(command)
   34         position = len(command)
   35         completions = self.completer.get_completions(
   36             Document(text=command, cursor_position=position),
   37             self.completer_event)
   38         return [c.text for c in completions]
   39 
   40     def test_header_name(self):
   41         result = self.get_completions('ctype')
   42         self.assertEqual(result[0], 'Content-Type')
   43 
   44     def test_header_value(self):
   45         result = self.get_completions('Content-Type:json')
   46         self.assertEqual(result[0], 'application/json')
   47 
   48     def test_verify_option(self):
   49         result = self.get_completions('--vfy')
   50         self.assertEqual(result[0], '--verify')
   51 
   52     def test_preview_then_action(self):
   53         result = self.get_completions('httpie po')
   54         self.assertEqual(result[0], 'post')
   55 
   56     def test_rm_body_param(self):
   57         self.context.body_params['my_name'] = 'dont_care'
   58         result = self.get_completions('rm -b ')
   59         self.assertEqual(result[0], 'my_name')
   60 
   61     def test_rm_body_json_param(self):
   62         self.context.body_json_params['number'] = 2
   63         result = self.get_completions('rm -b ')
   64         self.assertEqual(result[0], 'number')
   65 
   66     def test_rm_querystring_param(self):
   67         self.context.querystring_params['my_name'] = 'dont_care'
   68         result = self.get_completions('rm -q ')
   69         self.assertEqual(result[0], 'my_name')
   70 
   71     def test_rm_header(self):
   72         self.context.headers['Accept'] = 'dont_care'
   73         result = self.get_completions('rm -h ')
   74         self.assertEqual(result[0], 'Accept')
   75 
   76     def test_rm_option(self):
   77         self.context.options['--form'] = None
   78         result = self.get_completions('rm -o ')
   79         self.assertEqual(result[0], '--form')
   80 
   81     def test_querystring_with_chinese(self):
   82         result = self.get_completions('name==王')
   83         self.assertFalse(result)
   84 
   85     def test_header_with_spanish(self):
   86         result = self.get_completions('X-Custom-Header:Jesú')
   87         self.assertFalse(result)
   88 
   89     def test_options_method(self):
   90         result = self.get_completions('opt')
   91         self.assertEqual(result[0], 'options')
   92 
   93     def test_ls_no_path(self):
   94         result = self.get_completions('ls ')
   95         self.assertEqual(result, ['orgs', 'users'])
   96 
   97     def test_ls_no_path_substring(self):
   98         result = self.get_completions('ls o')
   99         self.assertEqual(result, ['orgs'])
  100 
  101     def test_ls_absolute_path(self):
  102         result = self.get_completions('ls /users/1/')
  103         self.assertEqual(result, ['events', 'orgs'])
  104 
  105     def test_ls_absolute_path_substring(self):
  106         result = self.get_completions('ls /users/1/e')
  107         self.assertEqual(result, ['events'])
  108 
  109     def test_ls_relative_path(self):
  110         self.context.url = 'http://localhost/orgs'
  111         result = self.get_completions('ls 1/')
  112         self.assertEqual(result, ['events', 'members'])
  113 
  114     def test_cd_no_path(self):
  115         result = self.get_completions('cd ')
  116         self.assertEqual(result, ['orgs', 'users'])
  117 
  118     def test_cd_no_path_substring(self):
  119         result = self.get_completions('cd o')
  120         self.assertEqual(result, ['orgs'])
  121 
  122     def test_cd_absolute_path(self):
  123         result = self.get_completions('cd /users/1/')
  124         self.assertEqual(result, ['events', 'orgs'])
  125 
  126     def test_cd_absolute_path_substring(self):
  127         result = self.get_completions('cd /users/1/e')
  128         self.assertEqual(result, ['events'])
  129 
  130     def test_cd_relative_path(self):
  131         self.context.url = 'http://localhost/orgs'
  132         result = self.get_completions('cd 1/')
  133         self.assertEqual(result, ['events', 'members'])