1 # copyright 2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
3 # |
|
4 # This file is part of CubicWeb. |
|
5 # |
|
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
7 # terms of the GNU Lesser General Public License as published by the Free |
|
8 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
9 # any later version. |
|
10 # |
|
11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
14 # details. |
|
15 # |
|
16 # You should have received a copy of the GNU Lesser General Public License along |
|
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
18 """unittest for cubicweb.devtools.httptest module""" |
|
19 |
|
20 from six.moves import http_client |
|
21 |
|
22 from logilab.common.testlib import Tags |
|
23 from cubicweb.devtools.httptest import CubicWebServerTC |
|
24 |
|
25 |
|
26 class TwistedCWAnonTC(CubicWebServerTC): |
|
27 |
|
28 def test_response(self): |
|
29 try: |
|
30 response = self.web_get() |
|
31 except http_client.NotConnected as ex: |
|
32 self.fail("Can't connection to test server: %s" % ex) |
|
33 |
|
34 def test_response_anon(self): |
|
35 response = self.web_get() |
|
36 self.assertEqual(response.status, http_client.OK) |
|
37 |
|
38 def test_base_url(self): |
|
39 if self.config['base-url'] not in self.web_get().read(): |
|
40 self.fail('no mention of base url in retrieved page') |
|
41 |
|
42 |
|
43 class TwistedCWIdentTC(CubicWebServerTC): |
|
44 test_db_id = 'httptest-cwident' |
|
45 anonymous_allowed = False |
|
46 tags = CubicWebServerTC.tags | Tags(('auth',)) |
|
47 |
|
48 def test_response_denied(self): |
|
49 response = self.web_get() |
|
50 self.assertEqual(response.status, http_client.FORBIDDEN) |
|
51 |
|
52 def test_login(self): |
|
53 response = self.web_get() |
|
54 if response.status != http_client.FORBIDDEN: |
|
55 self.skipTest('Already authenticated, "test_response_denied" must have failed') |
|
56 # login |
|
57 self.web_login(self.admlogin, self.admpassword) |
|
58 response = self.web_get() |
|
59 self.assertEqual(response.status, http_client.OK, response.body) |
|
60 # logout |
|
61 self.web_logout() |
|
62 response = self.web_get() |
|
63 self.assertEqual(response.status, http_client.FORBIDDEN, response.body) |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 if __name__ == '__main__': |
|
69 from logilab.common.testlib import unittest_main |
|
70 unittest_main() |
|