author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 26 Sep 2011 19:09:12 +0200 | |
branch | stable |
changeset 7867 | 0abed94a9859 |
parent 7071 | db7608cb32bc |
child 8695 | 358d8bed9626 |
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 |
|
7053
0673419b3066
[test] Improve tagging and error message of TwistedCWIdentTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6438
diff
changeset
|
22 |
from logilab.common.testlib import Tags |
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
|
23 |
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
|
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 |
|
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 |
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
|
27 |
|
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 |
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
|
29 |
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
|
30 |
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
|
31 |
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
|
32 |
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
|
33 |
|
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 |
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
|
35 |
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
|
36 |
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
|
37 |
|
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
|
38 |
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
|
39 |
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
|
40 |
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
|
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 |
|
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
|
43 |
class TwistedCWIdentTC(CubicWebServerTC): |
7053
0673419b3066
[test] Improve tagging and error message of TwistedCWIdentTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6438
diff
changeset
|
44 |
|
7071
db7608cb32bc
[devtools] fix anonymous user handling in test classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7053
diff
changeset
|
45 |
anonymous_allowed = False |
7053
0673419b3066
[test] Improve tagging and error message of TwistedCWIdentTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6438
diff
changeset
|
46 |
tags = CubicWebServerTC.tags | Tags(('auth',)) |
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
|
47 |
|
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 |
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
|
49 |
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
|
50 |
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
|
51 |
|
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
|
52 |
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
|
53 |
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
|
54 |
if response.status != httplib.FORBIDDEN: |
7053
0673419b3066
[test] Improve tagging and error message of TwistedCWIdentTC
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6438
diff
changeset
|
55 |
self.skipTest('Already authenticated, "test_response_denied" must have failed') |
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
|
56 |
# 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
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
# 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
|
61 |
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
|
62 |
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
|
63 |
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
|
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 |
|
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
|
66 |
|
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 |
|
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
|
68 |
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
|
69 |
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
|
70 |
unittest_main() |