summaryrefslogtreecommitdiffstats
path: root/tests/QtNetwork/basic_auth_test.py
blob: bc41d65c8ff9bc7c5fa0a282cf2c3f1ed9a08524 (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
import unittest

from PySide.QtCore import *
from PySide.QtNetwork import *

from helper import UsesQCoreApplication
from httpd import TestServer

class testAuthenticationSignal(UsesQCoreApplication):

    def setUp(self):
        super(testAuthenticationSignal, self).setUp()
        self.httpd = TestServer(secure=True)
        self.httpd.start()
        self._resultOk = False

    def tearDown(self):
        if self.httpd:
            self.httpd.shutdown()
            del self.httpd
        super(testAuthenticationSignal, self).tearDown()

    def goAway(self):
        self.httpd.shutdown()
        self.app.quit()
        self.httpd = None

    def onAuthRequest(self, hostname, port, auth):
        self.assert_(isinstance(auth, QAuthenticator))
        self._resultOk = True
        self.goAway()

    def testwaitSignal(self):
        http = QHttp('127.0.0.1', self.httpd.port())
        http.connect(SIGNAL("authenticationRequired(const QString&, quint16, QAuthenticator*)"), self.onAuthRequest)
        path = QUrl.toPercentEncoding("/index.html", "!$&'()*+,;=:@/")
        data = http.get(str(path))
        self.app.exec_()
        self.assert_(self._resultOk)

    def testwaitSignal2(self):
        http = QHttp('127.0.0.1', self.httpd.port())
        # Using new signal slot syntax causes a segfault
        http.authenticationRequired.connect(self.onAuthRequest)
        path = QUrl.toPercentEncoding("/index.html", "!$&'()*+,;=:@/")
        data = http.get(str(path))
        self.app.exec_()
        self.assert_(self._resultOk)

if __name__ == '__main__':
    unittest.main()