devtools/test/unittest_httptest.py
author Julien Jehannet <julien.jehannet@logilab.fr>
Fri, 08 Oct 2010 15:28:51 +0200
branchstable
changeset 6424 f443a2b8a5c7
parent 6340 470d8e828fda
child 6438 abae10f81a85
permissions -rw-r--r--
[devtools] refactor http server initialization in a much saner way Use a new ApptestConfiguration to group server paramater. Fix base-url mangling between main site and data ressources.

import httplib

from cubicweb.devtools.httptest import CubicWebServerTC
from cubicweb.devtools.httptest import CubicWebServerConfig


class TwistedCWAnonTC(CubicWebServerTC):

    def test_response(self):
        try:
            response = self.web_get()
        except httplib.NotConnected, ex:
            self.fail("Can't connection to test server: %s" % ex)

    def test_response_anon(self):
        response = self.web_get()
        self.assertEqual(response.status, httplib.OK)

    def test_base_url(self):
        if self.config['base-url'] not in self.web_get().read():
            self.fail('no mention of base url in retrieved page')


class TwistedCWIdentTC(CubicWebServerTC):

    def setUp(self):
        CubicWebServerConfig.anonymous_logged = False
        CubicWebServerTC.setUp(self)

    def test_response_denied(self):
        response = self.web_get()
        self.assertEqual(response.status, httplib.FORBIDDEN)

    def test_login(self):
        response = self.web_get()
        if response.status != httplib.FORBIDDEN:
             self.skipTest('Already authenticated')
        # login
        self.web_login(self.admlogin, self.admpassword)
        response = self.web_get()
        self.assertEqual(response.status, httplib.OK, response.body)
        # logout
        self.web_logout()
        response = self.web_get()
        self.assertEqual(response.status, httplib.FORBIDDEN, response.body)




if __name__ == '__main__':
    from logilab.common.testlib import unittest_main
    unittest_main()