13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
14 # details. |
14 # details. |
15 # |
15 # |
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 """cubicweb.web.views.basecontrollers unit tests |
18 """cubicweb.web.views.basecontrollers unit tests""" |
19 |
|
20 """ |
|
21 |
19 |
22 from logilab.common.testlib import unittest_main, mock_object |
20 from logilab.common.testlib import unittest_main, mock_object |
23 |
21 |
24 from cubicweb import Binary, NoSelectableObject, ValidationError |
22 from cubicweb import Binary, NoSelectableObject, ValidationError |
25 from cubicweb.view import STRICT_DOCTYPE |
23 from cubicweb.view import STRICT_DOCTYPE |
26 from cubicweb.devtools.testlib import CubicWebTC |
24 from cubicweb.devtools.testlib import CubicWebTC |
|
25 from cubicweb.utils import json_dumps |
27 from cubicweb.uilib import rql_for_eid |
26 from cubicweb.uilib import rql_for_eid |
28 from cubicweb.web import INTERNAL_FIELD_VALUE, Redirect, RequestError, json |
27 from cubicweb.web import INTERNAL_FIELD_VALUE, Redirect, RequestError |
29 from cubicweb.entities.authobjs import CWUser |
28 from cubicweb.entities.authobjs import CWUser |
30 from cubicweb.web.views.autoform import get_pending_inserts, get_pending_deletes |
29 from cubicweb.web.views.autoform import get_pending_inserts, get_pending_deletes |
31 u = unicode |
30 u = unicode |
32 |
31 |
33 def req_form(user): |
32 def req_form(user): |
126 e = self.execute('Any X WHERE X eid %(x)s', {'x': user.eid}).get_entity(0, 0) |
125 e = self.execute('Any X WHERE X eid %(x)s', {'x': user.eid}).get_entity(0, 0) |
127 self.assertEquals(e.login, user.login) |
126 self.assertEquals(e.login, user.login) |
128 self.assertEquals(e.firstname, u'Th\xe9nault') |
127 self.assertEquals(e.firstname, u'Th\xe9nault') |
129 self.assertEquals(e.surname, u'Sylvain') |
128 self.assertEquals(e.surname, u'Sylvain') |
130 self.assertEquals([g.eid for g in e.in_group], groupeids) |
129 self.assertEquals([g.eid for g in e.in_group], groupeids) |
131 self.assertEquals(e.state, 'activated') |
130 self.assertEquals(e.cw_adapt_to('IWorkflowable').state, 'activated') |
132 |
131 |
133 |
132 |
134 def test_create_multiple_linked(self): |
133 def test_create_multiple_linked(self): |
135 gueid = self.execute('CWGroup G WHERE G name "users"')[0][0] |
134 gueid = self.execute('CWGroup G WHERE G name "users"')[0][0] |
136 req = self.request() |
135 req = self.request() |
560 |
559 |
561 # def test_json_exec(self): |
560 # def test_json_exec(self): |
562 # rql = 'Any T,N WHERE T is Tag, T name N' |
561 # rql = 'Any T,N WHERE T is Tag, T name N' |
563 # ctrl = self.ctrl(self.request(mode='json', rql=rql, pageid='123')) |
562 # ctrl = self.ctrl(self.request(mode='json', rql=rql, pageid='123')) |
564 # self.assertEquals(ctrl.publish(), |
563 # self.assertEquals(ctrl.publish(), |
565 # json.dumps(self.execute(rql).rows)) |
564 # json_dumps(self.execute(rql).rows)) |
566 |
565 |
567 def test_remote_add_existing_tag(self): |
566 def test_remote_add_existing_tag(self): |
568 self.remote_call('tag_entity', self.john.eid, ['python']) |
567 self.remote_call('tag_entity', self.john.eid, ['python']) |
569 self.assertUnorderedIterableEquals( |
568 self.assertUnorderedIterableEquals( |
570 [tname for tname, in self.execute('Any N WHERE T is Tag, T name N')], |
569 [tname for tname, in self.execute('Any N WHERE T is Tag, T name N')], |
641 |
640 |
642 |
641 |
643 # silly tests |
642 # silly tests |
644 def test_external_resource(self): |
643 def test_external_resource(self): |
645 self.assertEquals(self.remote_call('external_resource', 'RSS_LOGO')[0], |
644 self.assertEquals(self.remote_call('external_resource', 'RSS_LOGO')[0], |
646 json.dumps(self.request().external_resource('RSS_LOGO'))) |
645 json_dumps(self.config.uiprops['RSS_LOGO'])) |
647 def test_i18n(self): |
646 def test_i18n(self): |
648 self.assertEquals(self.remote_call('i18n', ['bimboom'])[0], |
647 self.assertEquals(self.remote_call('i18n', ['bimboom'])[0], |
649 json.dumps(['bimboom'])) |
648 json_dumps(['bimboom'])) |
650 |
649 |
651 def test_format_date(self): |
650 def test_format_date(self): |
652 self.assertEquals(self.remote_call('format_date', '2007-01-01 12:00:00')[0], |
651 self.assertEquals(self.remote_call('format_date', '2007-01-01 12:00:00')[0], |
653 json.dumps('2007/01/01')) |
652 json_dumps('2007/01/01')) |
654 |
653 |
655 |
654 |
656 |
655 |
657 |
656 |
658 if __name__ == '__main__': |
657 if __name__ == '__main__': |