1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vi:ts=4:et
from . import localhost
import pycurl
import pytest
import unittest
from . import appmanager
from . import util
setup_module, teardown_module = appmanager.setup(('app', 8380))
class SetoptTest(unittest.TestCase):
def setUp(self):
self.curl = util.DefaultCurl()
def tearDown(self):
self.curl.close()
def test_boolean_value(self):
# expect no exceptions raised
self.curl.setopt(pycurl.VERBOSE, True)
def test_integer_value(self):
# expect no exceptions raised
self.curl.setopt(pycurl.VERBOSE, 1)
def test_string_value_for_integer_option(self):
with pytest.raises(TypeError):
self.curl.setopt(pycurl.VERBOSE, "Hello, world!")
def test_string_value(self):
# expect no exceptions raised
self.curl.setopt(pycurl.URL, 'http://hello.world')
def test_integer_value_for_string_option(self):
with pytest.raises(TypeError):
self.curl.setopt(pycurl.URL, 1)
def test_float_value_for_integer_option(self):
with pytest.raises(TypeError):
self.curl.setopt(pycurl.VERBOSE, 1.0)
def test_httpheader_list(self):
self.curl.setopt(self.curl.HTTPHEADER, ['Accept:'])
def test_httpheader_tuple(self):
self.curl.setopt(self.curl.HTTPHEADER, ('Accept:',))
def test_httpheader_unicode(self):
self.curl.setopt(self.curl.HTTPHEADER, (util.u('Accept:'),))
def test_unset_httpheader(self):
self.curl.setopt(self.curl.HTTPHEADER, ('x-test: foo',))
self.curl.setopt(self.curl.URL, 'http://%s:8380/header?h=x-test' % localhost)
io = util.BytesIO()
self.curl.setopt(self.curl.WRITEDATA, io)
self.curl.perform()
self.assertEqual(util.b('foo'), io.getvalue())
self.curl.unsetopt(self.curl.HTTPHEADER)
io = util.BytesIO()
self.curl.setopt(self.curl.WRITEDATA, io)
self.curl.perform()
self.assertEqual(util.b(''), io.getvalue())
def test_set_httpheader_none(self):
self.curl.setopt(self.curl.HTTPHEADER, ('x-test: foo',))
self.curl.setopt(self.curl.URL, 'http://%s:8380/header?h=x-test' % localhost)
io = util.BytesIO()
self.curl.setopt(self.curl.WRITEDATA, io)
self.curl.perform()
self.assertEqual(util.b('foo'), io.getvalue())
self.curl.setopt(self.curl.HTTPHEADER, None)
io = util.BytesIO()
self.curl.setopt(self.curl.WRITEDATA, io)
self.curl.perform()
self.assertEqual(util.b(''), io.getvalue())
@util.min_libcurl(7, 37, 0)
def test_proxyheader_list(self):
self.curl.setopt(self.curl.PROXYHEADER, ['Accept:'])
@util.min_libcurl(7, 37, 0)
def test_proxyheader_tuple(self):
self.curl.setopt(self.curl.PROXYHEADER, ('Accept:',))
@util.min_libcurl(7, 37, 0)
def test_proxyheader_unicode(self):
self.curl.setopt(self.curl.PROXYHEADER, (util.u('Accept:'),))
@util.min_libcurl(7, 37, 0)
def test_unset_proxyheader(self):
self.curl.unsetopt(self.curl.PROXYHEADER)
@util.min_libcurl(7, 37, 0)
def test_set_proxyheader_none(self):
self.curl.setopt(self.curl.PROXYHEADER, None)
def test_unset_encoding(self):
self.curl.unsetopt(self.curl.ENCODING)
# github issue #405
def test_large_options(self):
self.curl.setopt(self.curl.INFILESIZE, 3333858173)
self.curl.setopt(self.curl.MAX_RECV_SPEED_LARGE, 3333858173)
self.curl.setopt(self.curl.MAX_SEND_SPEED_LARGE, 3333858173)
self.curl.setopt(self.curl.MAXFILESIZE, 3333858173)
self.curl.setopt(self.curl.POSTFIELDSIZE, 3333858173)
self.curl.setopt(self.curl.RESUME_FROM, 3333858173)
|