author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Sun, 17 Oct 2010 10:04:45 +0200 | |
changeset 6524 | eca20b012104 |
parent 6438 | abae10f81a85 |
child 7053 | 0673419b3066 |
permissions | -rw-r--r-- |
6438
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
1 |
# copyright 2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
3 |
# |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
4 |
# This file is part of CubicWeb. |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
5 |
# |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
9 |
# any later version. |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
10 |
# |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
14 |
# details. |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
15 |
# |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
18 |
"""unittest for cubicweb.devtools.httptest module""" |
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
19 |
|
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
20 |
import httplib |
5654
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
21 |
|
6438
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
22 |
from cubicweb.devtools.httptest import CubicWebServerTC, CubicWebServerConfig |
5654
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
23 |
|
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
24 |
|
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
25 |
class TwistedCWAnonTC(CubicWebServerTC): |
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
26 |
|
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
27 |
def test_response(self): |
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
28 |
try: |
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
29 |
response = self.web_get() |
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
30 |
except httplib.NotConnected, ex: |
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
31 |
self.fail("Can't connection to test server: %s" % ex) |
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
32 |
|
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
33 |
def test_response_anon(self): |
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
34 |
response = self.web_get() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
35 |
self.assertEqual(response.status, httplib.OK) |
5654
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
36 |
|
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
37 |
def test_base_url(self): |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
38 |
if self.config['base-url'] not in self.web_get().read(): |
5654
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
39 |
self.fail('no mention of base url in retrieved page') |
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
40 |
|
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
41 |
|
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
42 |
class TwistedCWIdentTC(CubicWebServerTC): |
6438
abae10f81a85
[js test] cleanup, move anonymous_logged handling to the test class (easier to control there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6424
diff
changeset
|
43 |
anonymous_logged = False |
5654
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
44 |
|
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
45 |
def test_response_denied(self): |
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
46 |
response = self.web_get() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
47 |
self.assertEqual(response.status, httplib.FORBIDDEN) |
5654
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
48 |
|
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
49 |
def test_login(self): |
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
50 |
response = self.web_get() |
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
51 |
if response.status != httplib.FORBIDDEN: |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
52 |
self.skipTest('Already authenticated') |
5654
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
53 |
# login |
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
54 |
self.web_login(self.admlogin, self.admpassword) |
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
55 |
response = self.web_get() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
56 |
self.assertEqual(response.status, httplib.OK, response.body) |
5654
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
57 |
# logout |
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
58 |
self.web_logout() |
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
59 |
response = self.web_get() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
60 |
self.assertEqual(response.status, httplib.FORBIDDEN, response.body) |
5654
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
61 |
|
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
62 |
|
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
63 |
|
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
64 |
|
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
65 |
if __name__ == '__main__': |
6424
f443a2b8a5c7
[devtools] refactor http server initialization in a much saner way
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
66 |
from logilab.common.testlib import unittest_main |
5654
8bb34548be86
[web test] Add a CubicWebServerTC class to run test with a cw web serveur available.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff
changeset
|
67 |
unittest_main() |