|
1 # -*- coding: utf-8 -*- |
|
2 # copyright 2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
4 # |
|
5 # This file is part of CubicWeb. |
|
6 # |
|
7 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
8 # terms of the GNU Lesser General Public License as published by the Free |
|
9 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
10 # any later version. |
|
11 # |
|
12 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
|
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
14 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
15 # details. |
|
16 # |
|
17 # You should have received a copy of the GNU Lesser General Public License along |
|
18 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
19 |
|
20 from cubicweb.devtools.testlib import CubicWebTC |
|
21 |
|
22 |
|
23 class CSVExportViewsTC(CubicWebTC): |
|
24 |
|
25 def test_csvexport(self): |
|
26 with self.admin_access.web_request() as req: |
|
27 rset = req.execute('Any GN,COUNT(X) GROUPBY GN ORDERBY GN ' |
|
28 'WHERE X in_group G, G name GN') |
|
29 data = self.view('csvexport', rset, req=req) |
|
30 self.assertEqual(req.headers_out.getRawHeaders('content-type'), |
|
31 ['text/comma-separated-values;charset=UTF-8']) |
|
32 expected_data = "String;COUNT(CWUser)\nguests;1\nmanagers;1" |
|
33 self.assertMultiLineEqual(expected_data, data) |
|
34 |
|
35 def test_csvexport_on_empty_rset(self): |
|
36 """Should return the CSV header. |
|
37 """ |
|
38 with self.admin_access.web_request() as req: |
|
39 rset = req.execute('Any GN,COUNT(X) GROUPBY GN ORDERBY GN ' |
|
40 'WHERE X in_group G, G name GN, X login "Miles"') |
|
41 data = self.view('csvexport', rset, req=req) |
|
42 self.assertEqual(req.headers_out.getRawHeaders('content-type'), |
|
43 ['text/comma-separated-values;charset=UTF-8']) |
|
44 expected_data = "String;COUNT(CWUser)" |
|
45 self.assertMultiLineEqual(expected_data, data) |
|
46 |
|
47 |
|
48 if __name__ == '__main__': |
|
49 from logilab.common.testlib import unittest_main |
|
50 unittest_main() |