示例#1
0
    def test_binary_data(self):
        requests = []

        def request_sniper(x):
            requests.append(deepcopy(x))

        with server(callback=request_sniper):
            self.assertFalse(
                cli(
                    '--method',
                    'POST',
                    '--header',
                    'Content-Type: application/json',
                    '--data-binary',
                    '@{}'.format(self.binary_datafile.name),
                    '127.0.0.1',
                    'host.name/',
                ))

        self.assertIn(b'POST', requests[0])
        # Magic number is the val_size + val
        self.assertIn(b'CONTENT_LENGTH\x02\x0013', requests[0])
        self.assertIn(b'CONTENT_TYPE', requests[0])
        self.assertIn(b'application/json', requests[0])
        self.assertIn(b'binary-fooooo', requests[0])
示例#2
0
    def test_post(self):
        requests = []

        def request_sniper(x):
            requests.append(deepcopy(x))

        with server(callback=request_sniper):
            self.assertFalse(
                cli('--method', 'POST', '--header',
                    'Content-Type: application/json',
                    r'''--data=\'{"foo":"bar"}\'''', '127.0.0.1',
                    'host.name/'))

        self.assertIn(b'POST', requests[0])
        # Magic number is the val_size + val
        self.assertIn(b'CONTENT_LENGTH\x02\x0017', requests[0])
        self.assertIn(b'CONTENT_TYPE', requests[0])
        self.assertIn(b'application/json', requests[0])
示例#3
0
 def test_headers(self):
     with server(callback=lambda x: self.assertIn(b'localhost', x)):
         self.assertFalse(cli('127.0.0.1:3030', '-H', 'Host: localhost'))
示例#4
0
    def test_file_socket(self):
        fname = '/tmp/unix-socket'

        with server(addr=fname, params=(socket.AF_UNIX, socket.SOCK_STREAM)):
            self.assertFalse(cli(fname))
示例#5
0
 def test_cli_nok(self):
     with server(status=300):
         self.assertTrue(cli('127.0.0.1:3030', '--timeout', '10'))
示例#6
0
 def test_cli(self):
     with server():
         self.assertFalse(cli('127.0.0.1', 'host.name/'))