Mercurial > p > roundup > code
diff test/db_test_base.py @ 4878:f6e76a03b502
HTML* classes for cgi are now all new-style
Add regression test for old behaviour: Lookup of a value of a
HTMLProperty was possibly via getitem -- for old-style classes this
worked because __getattr__ returned the __getitem__ of a newly created
HTMLItem object, this does no longer work for new-style classes as these
look up special method only on the class not the instance.
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Sat, 29 Mar 2014 10:52:20 +0100 |
| parents | 74b24b14071a |
| children | 302c967d710c |
line wrap: on
line diff
--- a/test/db_test_base.py Fri Mar 28 16:47:36 2014 +0100 +++ b/test/db_test_base.py Sat Mar 29 10:52:20 2014 +0100 @@ -25,6 +25,7 @@ from roundup.mailer import Mailer from roundup import date, password, init, instance, configuration, \ roundupdb, i18n +from roundup.cgi.templating import HTMLItem from mocknull import MockNull @@ -2428,18 +2429,27 @@ ae (result, ['4', '5', '6', '7', '8', '1', '2', '3']) -class ClassicInitTest(unittest.TestCase): +class ClassicInitBase(unittest.TestCase): count = 0 db = None def setUp(self): - ClassicInitTest.count = ClassicInitTest.count + 1 + ClassicInitBase.count = ClassicInitBase.count + 1 self.dirname = '_test_init_%s'%self.count try: shutil.rmtree(self.dirname) except OSError, error: if error.errno not in (errno.ENOENT, errno.ESRCH): raise + def tearDown(self): + if self.db is not None: + self.db.close() + try: + shutil.rmtree(self.dirname) + except OSError, error: + if error.errno not in (errno.ENOENT, errno.ESRCH): raise + +class ClassicInitTest(ClassicInitBase): def testCreation(self): ae = self.assertEqual @@ -2467,15 +2477,8 @@ l = db.issue.list() ae(l, []) - def tearDown(self): - if self.db is not None: - self.db.close() - try: - shutil.rmtree(self.dirname) - except OSError, error: - if error.errno not in (errno.ENOENT, errno.ESRCH): raise -class ConcurrentDBTest(ClassicInitTest): +class ConcurrentDBTest(ClassicInitBase): def testConcurrency(self): # The idea here is a read-modify-update cycle in the presence of # a cache that has to be properly handled. The same applies if @@ -2506,5 +2509,73 @@ self.assertEqual(db2.priority.get(prio, 'order'), 3.0) db2.close() +class HTMLItemTest(ClassicInitBase): + class Request : + """ Fake html request """ + rfile = None + def start_response (self, a, b) : + pass + # end def start_response + # end class Request + + def setUp(self): + super(HTMLItemTest, self).setUp() + self.tracker = tracker = setupTracker(self.dirname, self.backend) + db = self.db = tracker.open('admin') + req = self.Request() + env = dict (PATH_INFO='', REQUEST_METHOD='GET', QUERY_STRING='') + self.client = self.tracker.Client(self.tracker, req, env, None) + self.client.db = db + self.client.language = None + self.client.userid = db.getuid() + self.client.classname = 'issue' + user = {'username': 'worker5', 'realname': 'Worker', 'roles': 'User'} + u = self.db.user.create(**user) + u_m = self.db.msg.create(author = u, content = 'bla' + , date = date.Date ('2006-01-01')) + issue = {'title': 'ts1', 'status': '2', 'assignedto': '3', + 'priority': '3', 'messages' : [u_m], 'nosy' : ['3']} + self.db.issue.create(**issue) + + def testHTMLItemAttributes(self): + issue = HTMLItem(self.client, 'issue', '1') + ae = self.assertEqual + ae(issue.title.plain(),'ts1') + ae(issue ['title'].plain(),'ts1') + ae(issue.status.plain(),'deferred') + ae(issue ['status'].plain(),'deferred') + ae(issue.assignedto.plain(),'worker5') + ae(issue ['assignedto'].plain(),'worker5') + ae(issue.priority.plain(),'bug') + ae(issue ['priority'].plain(),'bug') + ae(issue.messages.plain(),'1') + ae(issue ['messages'].plain(),'1') + ae(issue.nosy.plain(),'worker5') + ae(issue ['nosy'].plain(),'worker5') + ae(len(issue.messages),1) + ae(len(issue ['messages']),1) + ae(len(issue.nosy),1) + ae(len(issue ['nosy']),1) + + def testHTMLItemDereference(self): + issue = HTMLItem(self.client, 'issue', '1') + ae = self.assertEqual + ae(str(issue.priority.name),'bug') + ae(str(issue.priority['name']),'bug') + ae(str(issue ['priority']['name']),'bug') + ae(str(issue ['priority'].name),'bug') + ae(str(issue.assignedto.username),'worker5') + ae(str(issue.assignedto['username']),'worker5') + ae(str(issue ['assignedto']['username']),'worker5') + ae(str(issue ['assignedto'].username),'worker5') + for n in issue.nosy: + ae(n.username.plain(),'worker5') + ae(n['username'].plain(),'worker5') + for n in issue.messages: + ae(n.author.username.plain(),'worker5') + ae(n.author['username'].plain(),'worker5') + ae(n['author'].username.plain(),'worker5') + ae(n['author']['username'].plain(),'worker5') + # vim: set et sts=4 sw=4 :
