File: setopt_test.py

package info (click to toggle)
pycurl 7.45.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,752 kB
  • sloc: python: 8,663; ansic: 6,891; makefile: 202; sh: 183
file content (137 lines) | stat: -rw-r--r-- 4,602 bytes parent folder | download
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#! /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)

    def test_set_writefunction_none(self):
        self.curl.setopt(self.curl.WRITEFUNCTION, None)

    def test_set_headerfunction_none(self):
        self.curl.setopt(self.curl.HEADERFUNCTION, None)

    def test_set_readfunction_none(self):
        self.curl.setopt(self.curl.READFUNCTION, None)

    def test_set_progressfunction_none(self):
        self.curl.setopt(self.curl.PROGRESSFUNCTION, None)

    def test_set_xferinfofunction_none(self):
        self.curl.setopt(self.curl.XFERINFOFUNCTION, None)

    def test_set_debugfunction_none(self):
        self.curl.setopt(self.curl.DEBUGFUNCTION, None)

    def test_set_ioctlfunction_none(self):
        self.curl.setopt(self.curl.IOCTLFUNCTION, None)

    def test_set_seekfunction_none(self):
        self.curl.setopt(self.curl.SEEKFUNCTION, None)