equal
deleted
inserted
replaced
1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
16 # You should have received a copy of the GNU Lesser General Public License along |
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/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 |
18 |
19 from json import loads |
19 from json import loads |
20 from os.path import join |
20 from os.path import join |
|
21 import tempfile |
21 |
22 |
22 try: |
23 try: |
23 import requests |
24 import requests |
24 assert [int(n) for n in requests.__version__.split('.', 2)][:2] >= [1, 2] |
25 assert [int(n) for n in requests.__version__.split('.', 2)][:2] >= [1, 2] |
25 except (ImportError, AssertionError): |
26 except (ImportError, AssertionError): |
62 self.skipTest('Python ``requests`` module is not available') |
63 self.skipTest('Python ``requests`` module is not available') |
63 super(FileUploadTC, self).setUp() |
64 super(FileUploadTC, self).setUp() |
64 |
65 |
65 @property |
66 @property |
66 def _post_url(self): |
67 def _post_url(self): |
67 return self.request().build_url('ajax', fname='fileupload') |
68 with self.admin_access.web_request() as req: |
|
69 return req.build_url('ajax', fname='fileupload') |
68 |
70 |
69 def _fobject(self, fname): |
71 def _fobject(self, fname): |
70 return open(join(self.datadir, fname), 'rb') |
72 return open(join(self.datadir, fname), 'rb') |
71 |
73 |
72 def _fcontent(self, fname): |
74 def _fcontent(self, fname): |
90 'files': [['schema.py', self._fcontent('schema.py')], |
92 'files': [['schema.py', self._fcontent('schema.py')], |
91 ['views.py', self._fcontent('views.py')]],} |
93 ['views.py', self._fcontent('views.py')]],} |
92 self.assertEqual(webreq.status_code, 200) |
94 self.assertEqual(webreq.status_code, 200) |
93 self.assertDictEqual(expect, loads(webreq.content)) |
95 self.assertDictEqual(expect, loads(webreq.content)) |
94 |
96 |
|
97 |
95 class LanguageTC(CubicWebServerTC): |
98 class LanguageTC(CubicWebServerTC): |
96 |
99 |
97 def test_language_neg(self): |
100 def test_language_neg(self): |
98 headers = {'Accept-Language': 'fr'} |
101 headers = {'Accept-Language': 'fr'} |
99 webreq = self.web_request(headers=headers) |
102 webreq = self.web_request(headers=headers) |
113 self.web_login() |
116 self.web_login() |
114 webreq = self.web_request('/%d' % admin_eid) |
117 webreq = self.web_request('/%d' % admin_eid) |
115 self.assertEqual(webreq.status, 200) |
118 self.assertEqual(webreq.status, 200) |
116 |
119 |
117 |
120 |
|
121 class LogQueriesTC(CubicWebServerTC): |
|
122 @classmethod |
|
123 def init_config(cls, config): |
|
124 super(LogQueriesTC, cls).init_config(config) |
|
125 cls.logfile = tempfile.NamedTemporaryFile() |
|
126 config.global_set_option('query-log-file', cls.logfile.name) |
|
127 |
|
128 def test_log_queries(self): |
|
129 self.web_request() |
|
130 self.assertTrue(self.logfile.read()) |
|
131 |
|
132 @classmethod |
|
133 def tearDownClass(cls): |
|
134 cls.logfile.close() |
|
135 |
|
136 |
118 if __name__ == '__main__': |
137 if __name__ == '__main__': |
119 unittest_main() |
138 unittest_main() |