Exemplo n.º 1
0
    def test_authenticate_slides_ajax(self):
        """Test AJAX authentication."""
        url = self.urlbase + "ping" # regular GET
        view = MainWebView(None, url=url, hostname=self.hostname)

        class Finish(QtCore.QObject, unittest.TestCase):
            """Ajax ready callback"""
            @QtCore.Slot()
            def finish(self):
                status = view.page().mainFrame().toPlainText()
                self.assertEquals(status, '200')
                QT_APP.quit()

        def callback(reply):
            """HTML callback"""
            nm.finished[QtNetwork.QNetworkReply].disconnect(callback)
            view.page().mainFrame().addToJavaScriptWindowObject("finish", Finish())
            view.page().mainFrame().evaluateJavaScript("""
                var url = "%s";
                var xhr = new XMLHttpRequest();
                xhr.open("GET", url, false);
                xhr.onreadystatechange = function() {
                    if (xhr.readyState == 4) {
                        console.log("READY");
                        document.body.innerHTML = xhr.status;
                        finish.finish();
                    }
                };
                console.log("send ajax");
                xhr.send("");
                """ % (self.urlbase + "slides.json")) # ajax url

        nm = view.page().networkAccessManager()
        nm.finished[QtNetwork.QNetworkReply].connect(callback)
        QT_APP.exec_()
Exemplo n.º 2
0
 def _exec_request__return_cookies(self, url):
     # use test txt file to store cookies
     nm = MainNetworkAccessManager(cookie_path=self.cookiejar_file)
     self.assert_(nm)
     request = QtNetwork.QNetworkRequest(url=QtCore.QUrl(url))
     # execute an actual request to the server
     reply = nm.get(request)
     # QtApplication instance needs to be started for the request,
     # but ensure the execution is returned to the test
     nm.finished.connect(QT_APP.quit)
     QT_APP.exec_()
     jar = nm.cookieJar()
     return jar.allCookies()
Exemplo n.º 3
0
 def _exec_request__return_cookies(self, url):
     # use test txt file to store cookies
     nm = MainNetworkAccessManager(cookie_path=self.cookiejar_file)
     self.assert_(nm)
     request = QtNetwork.QNetworkRequest(url=QtCore.QUrl(url))
     # execute an actual request to the server
     reply = nm.get(request)
     # QtApplication instance needs to be started for the request,
     # but ensure the execution is returned to the test
     nm.finished.connect(QT_APP.quit)
     QT_APP.exec_()
     jar = nm.cookieJar()
     return jar.allCookies()
Exemplo n.º 4
0
    def test_authenticate_conductor(self):
        url = self.urlbase + "conductor"
        view = MainWebView(None, url=url, hostname=self.hostname)

        def callback(reply):
            nm.finished[QtNetwork.QNetworkReply].disconnect(callback)
            status = reply.attribute(QtNetwork.QNetworkRequest.HttpStatusCodeAttribute)
            self.assertEquals(status, 200)
            QT_APP.quit()

        nm = view.page().networkAccessManager()
        nm.finished[QtNetwork.QNetworkReply].connect(callback)
        QT_APP.exec_()
Exemplo n.º 5
0
    def test_authenticate_conductor(self):
        url = self.urlbase + "conductor"
        view = MainWebView(None, url=url, hostname=self.hostname)

        def callback(reply):
            nm.finished[QtNetwork.QNetworkReply].disconnect(callback)
            status = reply.attribute(
                QtNetwork.QNetworkRequest.HttpStatusCodeAttribute)
            self.assertEquals(status, 200)
            QT_APP.quit()

        nm = view.page().networkAccessManager()
        nm.finished[QtNetwork.QNetworkReply].connect(callback)
        QT_APP.exec_()
Exemplo n.º 6
0
    def test_unauthorized(self):
        """Should unauthorize without proper session key."""
        url = self.urlbase + "conductor"
        # corrupt key
        f = open(self.authkey_file, 'w')
        f.write("XXXXXXXX")
        f.close()
        view = MainWebView(None, url=url, hostname=self.hostname)

        def callback(reply):
            status = reply.attribute(QtNetwork.QNetworkRequest.HttpStatusCodeAttribute)
            self.assertEquals(status, 401)
            QT_APP.quit()

        nm = view.page().networkAccessManager()
        nm.finished[QtNetwork.QNetworkReply].connect(callback)
        QT_APP.exec_()
Exemplo n.º 7
0
    def test_unauthorized(self):
        """Should unauthorize without proper session key."""
        url = self.urlbase + "conductor"
        # corrupt key
        f = open(self.authkey_file, 'w')
        f.write("XXXXXXXX")
        f.close()
        view = MainWebView(None, url=url, hostname=self.hostname)

        def callback(reply):
            status = reply.attribute(
                QtNetwork.QNetworkRequest.HttpStatusCodeAttribute)
            self.assertEquals(status, 401)
            QT_APP.quit()

        nm = view.page().networkAccessManager()
        nm.finished[QtNetwork.QNetworkReply].connect(callback)
        QT_APP.exec_()
Exemplo n.º 8
0
    def test_authenticate_slides_ajax(self):
        """Test AJAX authentication."""
        url = self.urlbase + "ping"  # regular GET
        view = MainWebView(None, url=url, hostname=self.hostname)

        class Finish(QtCore.QObject, unittest.TestCase):
            """Ajax ready callback"""
            @QtCore.Slot()
            def finish(self):
                status = view.page().mainFrame().toPlainText()
                self.assertEquals(status, '200')
                QT_APP.quit()

        def callback(reply):
            """HTML callback"""
            nm.finished[QtNetwork.QNetworkReply].disconnect(callback)
            view.page().mainFrame().addToJavaScriptWindowObject(
                "finish", Finish())
            view.page().mainFrame().evaluateJavaScript("""
                var url = "%s";
                var xhr = new XMLHttpRequest();
                xhr.open("GET", url, false);
                xhr.onreadystatechange = function() {
                    if (xhr.readyState == 4) {
                        console.log("READY");
                        document.body.innerHTML = xhr.status;
                        finish.finish();
                    }
                };
                console.log("send ajax");
                xhr.send("");
                """ % (self.urlbase + "slides.json"))  # ajax url

        nm = view.page().networkAccessManager()
        nm.finished[QtNetwork.QNetworkReply].connect(callback)
        QT_APP.exec_()
Exemplo n.º 9
0
 def callback(reply):
     status = reply.attribute(
         QtNetwork.QNetworkRequest.HttpStatusCodeAttribute)
     self.assertEquals(status, 401)
     QT_APP.quit()
Exemplo n.º 10
0
 def finish(self):
     status = view.page().mainFrame().toPlainText()
     self.assertEquals(status, '200')
     QT_APP.quit()
Exemplo n.º 11
0
 def callback(reply):
     nm.finished[QtNetwork.QNetworkReply].disconnect(callback)
     status = reply.attribute(
         QtNetwork.QNetworkRequest.HttpStatusCodeAttribute)
     self.assertEquals(status, 200)
     QT_APP.quit()
Exemplo n.º 12
0
 def callback(reply):
     nm.finished[QtNetwork.QNetworkReply].disconnect(callback)
     status = reply.attribute(QtNetwork.QNetworkRequest.HttpStatusCodeAttribute)
     self.assertEquals(status, 200)
     QT_APP.quit()
Exemplo n.º 13
0
 def callback(reply):
     status = reply.attribute(QtNetwork.QNetworkRequest.HttpStatusCodeAttribute)
     self.assertEquals(status, 401)
     QT_APP.quit()
Exemplo n.º 14
0
 def finish(self):
     status = view.page().mainFrame().toPlainText()
     self.assertEquals(status, '200')
     QT_APP.quit()