summaryrefslogtreecommitdiff
path: root/tests/multi_option_constants_test.py
blob: 3f5ed0b63852415bf9ca643e6a577f6da9de695c (plain)
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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vi:ts=4:et

import sys
import pycurl
import unittest

from . import util

class MultiOptionConstantsTest(unittest.TestCase):
    def setUp(self):
        super(MultiOptionConstantsTest, self).setUp()

        self.m = pycurl.CurlMulti()

    def tearDown(self):
        super(MultiOptionConstantsTest, self).tearDown()

        self.m.close()

    def test_option_constant_on_pycurl(self):
        assert hasattr(pycurl, 'M_PIPELINING')

    def test_option_constant_on_curlmulti(self):
        assert hasattr(self.m, 'M_PIPELINING')

    @util.min_libcurl(7, 43, 0)
    def test_pipe_constants(self):
        self.m.setopt(self.m.M_PIPELINING, self.m.PIPE_NOTHING)
        self.m.setopt(self.m.M_PIPELINING, self.m.PIPE_HTTP1)
        self.m.setopt(self.m.M_PIPELINING, self.m.PIPE_MULTIPLEX)

    @util.min_libcurl(7, 30, 0)
    def test_multi_pipeline_opts(self):
        assert hasattr(pycurl, 'M_MAX_HOST_CONNECTIONS')
        assert hasattr(pycurl, 'M_MAX_PIPELINE_LENGTH')
        assert hasattr(pycurl, 'M_CONTENT_LENGTH_PENALTY_SIZE')
        assert hasattr(pycurl, 'M_CHUNK_LENGTH_PENALTY_SIZE')
        assert hasattr(pycurl, 'M_MAX_TOTAL_CONNECTIONS')
        self.m.setopt(pycurl.M_MAX_HOST_CONNECTIONS, 2)
        self.m.setopt(pycurl.M_MAX_PIPELINE_LENGTH, 2)
        self.m.setopt(pycurl.M_CONTENT_LENGTH_PENALTY_SIZE, 2)
        self.m.setopt(pycurl.M_CHUNK_LENGTH_PENALTY_SIZE, 2)
        self.m.setopt(pycurl.M_MAX_TOTAL_CONNECTIONS, 2)

    @util.min_libcurl(7, 30, 0)
    def test_multi_pipelining_site_bl(self):
        self.check_multi_charpp_option(self.m.M_PIPELINING_SITE_BL)

    @util.min_libcurl(7, 30, 0)
    def test_multi_pipelining_server_bl(self):
        self.check_multi_charpp_option(self.m.M_PIPELINING_SERVER_BL)

    def check_multi_charpp_option(self, option):
        input = [util.b('test1'), util.b('test2')]
        self.m.setopt(option, input)
        input = [util.u('test1'), util.u('test2')]
        self.m.setopt(option, input)
        self.m.setopt(option, [])
        input = (util.b('test1'), util.b('test2'))
        self.m.setopt(option, input)
        input = (util.u('test1'), util.u('test2'))
        self.m.setopt(option, input)
        self.m.setopt(option, ())
        self.m.setopt(option, None)

        try:
            self.m.setopt(option, 1)
            self.fail('expected to raise')
        except TypeError:
            exc = sys.exc_info()[1]
            assert 'integers are not supported for this option' in str(exc)

    def test_multi_callback_opts(self):
        def callback(*args, **kwargs):
            pass
        self.m.setopt(pycurl.M_SOCKETFUNCTION, callback)
        self.m.setopt(pycurl.M_TIMERFUNCTION, callback)
        self.m.setopt(pycurl.M_SOCKETFUNCTION, None)
        self.m.setopt(pycurl.M_TIMERFUNCTION, None)

    def test_multi_unsetopt_unsupported(self):
        try:
            self.m.setopt(pycurl.M_MAXCONNECTS, None)
            self.fail('expected to raise')
        except TypeError:
            exc = sys.exc_info()[1]
            assert 'unsetting is not supported for this option' in str(exc)