38 } |
38 } |
39 |
39 |
40 class EditControllerTC(CubicWebTC): |
40 class EditControllerTC(CubicWebTC): |
41 def setUp(self): |
41 def setUp(self): |
42 CubicWebTC.setUp(self) |
42 CubicWebTC.setUp(self) |
43 self.failUnless('users' in self.schema.eschema('CWGroup').get_groups('read')) |
43 self.assertTrue('users' in self.schema.eschema('CWGroup').get_groups('read')) |
44 |
44 |
45 def tearDown(self): |
45 def tearDown(self): |
46 CubicWebTC.tearDown(self) |
46 CubicWebTC.tearDown(self) |
47 self.failUnless('users' in self.schema.eschema('CWGroup').get_groups('read')) |
47 self.assertTrue('users' in self.schema.eschema('CWGroup').get_groups('read')) |
48 |
48 |
49 def test_noparam_edit(self): |
49 def test_noparam_edit(self): |
50 """check behaviour of this controller without any form parameter |
50 """check behaviour of this controller without any form parameter |
51 """ |
51 """ |
52 with self.assertRaises(ValidationError) as cm: |
52 with self.assertRaises(ValidationError) as cm: |
105 'upassword-subject-confirm:'+eid: 'tournicoton', |
105 'upassword-subject-confirm:'+eid: 'tournicoton', |
106 } |
106 } |
107 path, params = self.expect_redirect_publish(req, 'edit') |
107 path, params = self.expect_redirect_publish(req, 'edit') |
108 cnx.commit() # commit to check we don't get late validation error for instance |
108 cnx.commit() # commit to check we don't get late validation error for instance |
109 self.assertEqual(path, 'cwuser/user') |
109 self.assertEqual(path, 'cwuser/user') |
110 self.failIf('vid' in params) |
110 self.assertFalse('vid' in params) |
111 |
111 |
112 def test_user_editing_itself_no_relation(self): |
112 def test_user_editing_itself_no_relation(self): |
113 """checking we can edit an entity without specifying some required |
113 """checking we can edit an entity without specifying some required |
114 relations (meaning no changes) |
114 relations (meaning no changes) |
115 """ |
115 """ |
306 '__redirectparams': 'toto=tutu&tata=titi', |
306 '__redirectparams': 'toto=tutu&tata=titi', |
307 '__form_id': 'edition', |
307 '__form_id': 'edition', |
308 '__action_apply': '', |
308 '__action_apply': '', |
309 } |
309 } |
310 path, params = self.expect_redirect_publish(req, 'edit') |
310 path, params = self.expect_redirect_publish(req, 'edit') |
311 self.failUnless(path.startswith('blogentry/')) |
311 self.assertTrue(path.startswith('blogentry/')) |
312 eid = path.split('/')[1] |
312 eid = path.split('/')[1] |
313 self.assertEqual(params['vid'], 'edition') |
313 self.assertEqual(params['vid'], 'edition') |
314 self.assertNotEqual(int(eid), 4012) |
314 self.assertNotEqual(int(eid), 4012) |
315 self.assertEqual(params['__redirectrql'], redirectrql) |
315 self.assertEqual(params['__redirectrql'], redirectrql) |
316 self.assertEqual(params['__redirectvid'], 'primary') |
316 self.assertEqual(params['__redirectvid'], 'primary') |
362 '__type:%s'%eid2: 'EmailAddress', |
362 '__type:%s'%eid2: 'EmailAddress', |
363 '__action_delete': ''} |
363 '__action_delete': ''} |
364 path, params = self.expect_redirect_publish(req, 'edit') |
364 path, params = self.expect_redirect_publish(req, 'edit') |
365 self.assertEqual(path, 'view') |
365 self.assertEqual(path, 'view') |
366 self.assertIn('_cwmsgid', params) |
366 self.assertIn('_cwmsgid', params) |
|
367 |
|
368 def test_simple_copy(self): |
|
369 req = self.request() |
|
370 blog = req.create_entity('Blog', title=u'my-blog') |
|
371 blogentry = req.create_entity('BlogEntry', title=u'entry1', |
|
372 content=u'content1', entry_of=blog) |
|
373 req = self.request() |
|
374 req.form = {'__maineid' : 'X', 'eid': 'X', |
|
375 '__cloned_eid:X': blogentry.eid, '__type:X': 'BlogEntry', |
|
376 '_cw_entity_fields:X': 'title-subject,content-subject', |
|
377 'title-subject:X': u'entry1-copy', |
|
378 'content-subject:X': u'content1', |
|
379 } |
|
380 self.expect_redirect_publish(req, 'edit') |
|
381 blogentry2 = req.find_one_entity('BlogEntry', title=u'entry1-copy') |
|
382 self.assertEqual(blogentry2.entry_of[0].eid, blog.eid) |
|
383 |
|
384 def test_skip_copy_for(self): |
|
385 req = self.request() |
|
386 blog = req.create_entity('Blog', title=u'my-blog') |
|
387 blogentry = req.create_entity('BlogEntry', title=u'entry1', |
|
388 content=u'content1', entry_of=blog) |
|
389 blogentry.__class__.cw_skip_copy_for = [('entry_of', 'subject')] |
|
390 try: |
|
391 req = self.request() |
|
392 req.form = {'__maineid' : 'X', 'eid': 'X', |
|
393 '__cloned_eid:X': blogentry.eid, '__type:X': 'BlogEntry', |
|
394 '_cw_entity_fields:X': 'title-subject,content-subject', |
|
395 'title-subject:X': u'entry1-copy', |
|
396 'content-subject:X': u'content1', |
|
397 } |
|
398 self.expect_redirect_publish(req, 'edit') |
|
399 blogentry2 = req.find_one_entity('BlogEntry', title=u'entry1-copy') |
|
400 # entry_of should not be copied |
|
401 self.assertEqual(len(blogentry2.entry_of), 0) |
|
402 finally: |
|
403 blogentry.__class__.cw_skip_copy_for = [] |
367 |
404 |
368 def test_nonregr_eetype_etype_editing(self): |
405 def test_nonregr_eetype_etype_editing(self): |
369 """non-regression test checking that a manager user can edit a CWEType entity |
406 """non-regression test checking that a manager user can edit a CWEType entity |
370 """ |
407 """ |
371 groupeids = sorted(eid for eid, in self.execute('CWGroup G WHERE G name in ("managers", "users")')) |
408 groupeids = sorted(eid for eid, in self.execute('CWGroup G WHERE G name in ("managers", "users")')) |
403 'eid': 'A', '__maineid' : 'A', |
440 'eid': 'A', '__maineid' : 'A', |
404 '__type:A': 'BlogEntry', '_cw_entity_fields:A': 'title-subject,content-subject', |
441 '__type:A': 'BlogEntry', '_cw_entity_fields:A': 'title-subject,content-subject', |
405 'title-subject:A': u'"13:03:40"', |
442 'title-subject:A': u'"13:03:40"', |
406 'content-subject:A': u'"13:03:43"',} |
443 'content-subject:A': u'"13:03:43"',} |
407 path, params = self.expect_redirect_publish(req, 'edit') |
444 path, params = self.expect_redirect_publish(req, 'edit') |
408 self.failUnless(path.startswith('blogentry/')) |
445 self.assertTrue(path.startswith('blogentry/')) |
409 eid = path.split('/')[1] |
446 eid = path.split('/')[1] |
410 e = self.execute('Any C, T WHERE C eid %(x)s, C content T', {'x': eid}).get_entity(0, 0) |
447 e = self.execute('Any C, T WHERE C eid %(x)s, C content T', {'x': eid}).get_entity(0, 0) |
411 self.assertEqual(e.title, '"13:03:40"') |
448 self.assertEqual(e.title, '"13:03:40"') |
412 self.assertEqual(e.content, '"13:03:43"') |
449 self.assertEqual(e.content, '"13:03:43"') |
413 |
450 |
539 pageid='123', fname='view') |
576 pageid='123', fname='view') |
540 ctrl = self.ctrl(req) |
577 ctrl = self.ctrl(req) |
541 rset = self.john.as_rset() |
578 rset = self.john.as_rset() |
542 rset.req = req |
579 rset.req = req |
543 source = ctrl.publish() |
580 source = ctrl.publish() |
544 self.failUnless(source.startswith('<?xml version="1.0"?>\n' + STRICT_DOCTYPE + |
581 self.assertTrue(source.startswith('<?xml version="1.0"?>\n' + STRICT_DOCTYPE + |
545 u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:cubicweb="http://www.logilab.org/2008/cubicweb">') |
582 u'<div xmlns="http://www.w3.org/1999/xhtml" xmlns:cubicweb="http://www.logilab.org/2008/cubicweb">') |
546 ) |
583 ) |
547 req.xhtml_browser = lambda: False |
584 req.xhtml_browser = lambda: False |
548 source = ctrl.publish() |
585 source = ctrl.publish() |
549 self.failUnless(source.startswith('<div>')) |
586 self.assertTrue(source.startswith('<div>')) |
550 |
587 |
551 # def test_json_exec(self): |
588 # def test_json_exec(self): |
552 # rql = 'Any T,N WHERE T is Tag, T name N' |
589 # rql = 'Any T,N WHERE T is Tag, T name N' |
553 # ctrl = self.ctrl(self.request(mode='json', rql=rql, pageid='123')) |
590 # ctrl = self.ctrl(self.request(mode='json', rql=rql, pageid='123')) |
554 # self.assertEqual(ctrl.publish(), |
591 # self.assertEqual(ctrl.publish(), |