Mercurial > p > roundup > code
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 4877:2ba982dcdf2c | 4878:f6e76a03b502 |
|---|---|
| 23 from roundup.hyperdb import String, Password, Link, Multilink, Date, \ | 23 from roundup.hyperdb import String, Password, Link, Multilink, Date, \ |
| 24 Interval, DatabaseError, Boolean, Number, Node | 24 Interval, DatabaseError, Boolean, Number, Node |
| 25 from roundup.mailer import Mailer | 25 from roundup.mailer import Mailer |
| 26 from roundup import date, password, init, instance, configuration, \ | 26 from roundup import date, password, init, instance, configuration, \ |
| 27 roundupdb, i18n | 27 roundupdb, i18n |
| 28 from roundup.cgi.templating import HTMLItem | |
| 28 | 29 |
| 29 from mocknull import MockNull | 30 from mocknull import MockNull |
| 30 | 31 |
| 31 config = configuration.CoreConfig() | 32 config = configuration.CoreConfig() |
| 32 config.DATABASE = "db" | 33 config.DATABASE = "db" |
| 2426 nodeid = n.supervisor | 2427 nodeid = n.supervisor |
| 2427 self.db.clearCache() | 2428 self.db.clearCache() |
| 2428 ae (result, ['4', '5', '6', '7', '8', '1', '2', '3']) | 2429 ae (result, ['4', '5', '6', '7', '8', '1', '2', '3']) |
| 2429 | 2430 |
| 2430 | 2431 |
| 2431 class ClassicInitTest(unittest.TestCase): | 2432 class ClassicInitBase(unittest.TestCase): |
| 2432 count = 0 | 2433 count = 0 |
| 2433 db = None | 2434 db = None |
| 2434 | 2435 |
| 2435 def setUp(self): | 2436 def setUp(self): |
| 2436 ClassicInitTest.count = ClassicInitTest.count + 1 | 2437 ClassicInitBase.count = ClassicInitBase.count + 1 |
| 2437 self.dirname = '_test_init_%s'%self.count | 2438 self.dirname = '_test_init_%s'%self.count |
| 2438 try: | 2439 try: |
| 2439 shutil.rmtree(self.dirname) | 2440 shutil.rmtree(self.dirname) |
| 2440 except OSError, error: | 2441 except OSError, error: |
| 2441 if error.errno not in (errno.ENOENT, errno.ESRCH): raise | 2442 if error.errno not in (errno.ENOENT, errno.ESRCH): raise |
| 2442 | 2443 |
| 2444 def tearDown(self): | |
| 2445 if self.db is not None: | |
| 2446 self.db.close() | |
| 2447 try: | |
| 2448 shutil.rmtree(self.dirname) | |
| 2449 except OSError, error: | |
| 2450 if error.errno not in (errno.ENOENT, errno.ESRCH): raise | |
| 2451 | |
| 2452 class ClassicInitTest(ClassicInitBase): | |
| 2443 def testCreation(self): | 2453 def testCreation(self): |
| 2444 ae = self.assertEqual | 2454 ae = self.assertEqual |
| 2445 | 2455 |
| 2446 # set up and open a tracker | 2456 # set up and open a tracker |
| 2447 tracker = setupTracker(self.dirname, self.backend) | 2457 tracker = setupTracker(self.dirname, self.backend) |
| 2465 l = db.file.list() | 2475 l = db.file.list() |
| 2466 ae(l, []) | 2476 ae(l, []) |
| 2467 l = db.issue.list() | 2477 l = db.issue.list() |
| 2468 ae(l, []) | 2478 ae(l, []) |
| 2469 | 2479 |
| 2470 def tearDown(self): | 2480 |
| 2471 if self.db is not None: | 2481 class ConcurrentDBTest(ClassicInitBase): |
| 2472 self.db.close() | |
| 2473 try: | |
| 2474 shutil.rmtree(self.dirname) | |
| 2475 except OSError, error: | |
| 2476 if error.errno not in (errno.ENOENT, errno.ESRCH): raise | |
| 2477 | |
| 2478 class ConcurrentDBTest(ClassicInitTest): | |
| 2479 def testConcurrency(self): | 2482 def testConcurrency(self): |
| 2480 # The idea here is a read-modify-update cycle in the presence of | 2483 # The idea here is a read-modify-update cycle in the presence of |
| 2481 # a cache that has to be properly handled. The same applies if | 2484 # a cache that has to be properly handled. The same applies if |
| 2482 # we extend a String or otherwise modify something that depends | 2485 # we extend a String or otherwise modify something that depends |
| 2483 # on the previous value. | 2486 # on the previous value. |
| 2504 db2.commit() | 2507 db2.commit() |
| 2505 db2.clearCache() | 2508 db2.clearCache() |
| 2506 self.assertEqual(db2.priority.get(prio, 'order'), 3.0) | 2509 self.assertEqual(db2.priority.get(prio, 'order'), 3.0) |
| 2507 db2.close() | 2510 db2.close() |
| 2508 | 2511 |
| 2512 class HTMLItemTest(ClassicInitBase): | |
| 2513 class Request : | |
| 2514 """ Fake html request """ | |
| 2515 rfile = None | |
| 2516 def start_response (self, a, b) : | |
| 2517 pass | |
| 2518 # end def start_response | |
| 2519 # end class Request | |
| 2520 | |
| 2521 def setUp(self): | |
| 2522 super(HTMLItemTest, self).setUp() | |
| 2523 self.tracker = tracker = setupTracker(self.dirname, self.backend) | |
| 2524 db = self.db = tracker.open('admin') | |
| 2525 req = self.Request() | |
| 2526 env = dict (PATH_INFO='', REQUEST_METHOD='GET', QUERY_STRING='') | |
| 2527 self.client = self.tracker.Client(self.tracker, req, env, None) | |
| 2528 self.client.db = db | |
| 2529 self.client.language = None | |
| 2530 self.client.userid = db.getuid() | |
| 2531 self.client.classname = 'issue' | |
| 2532 user = {'username': 'worker5', 'realname': 'Worker', 'roles': 'User'} | |
| 2533 u = self.db.user.create(**user) | |
| 2534 u_m = self.db.msg.create(author = u, content = 'bla' | |
| 2535 , date = date.Date ('2006-01-01')) | |
| 2536 issue = {'title': 'ts1', 'status': '2', 'assignedto': '3', | |
| 2537 'priority': '3', 'messages' : [u_m], 'nosy' : ['3']} | |
| 2538 self.db.issue.create(**issue) | |
| 2539 | |
| 2540 def testHTMLItemAttributes(self): | |
| 2541 issue = HTMLItem(self.client, 'issue', '1') | |
| 2542 ae = self.assertEqual | |
| 2543 ae(issue.title.plain(),'ts1') | |
| 2544 ae(issue ['title'].plain(),'ts1') | |
| 2545 ae(issue.status.plain(),'deferred') | |
| 2546 ae(issue ['status'].plain(),'deferred') | |
| 2547 ae(issue.assignedto.plain(),'worker5') | |
| 2548 ae(issue ['assignedto'].plain(),'worker5') | |
| 2549 ae(issue.priority.plain(),'bug') | |
| 2550 ae(issue ['priority'].plain(),'bug') | |
| 2551 ae(issue.messages.plain(),'1') | |
| 2552 ae(issue ['messages'].plain(),'1') | |
| 2553 ae(issue.nosy.plain(),'worker5') | |
| 2554 ae(issue ['nosy'].plain(),'worker5') | |
| 2555 ae(len(issue.messages),1) | |
| 2556 ae(len(issue ['messages']),1) | |
| 2557 ae(len(issue.nosy),1) | |
| 2558 ae(len(issue ['nosy']),1) | |
| 2559 | |
| 2560 def testHTMLItemDereference(self): | |
| 2561 issue = HTMLItem(self.client, 'issue', '1') | |
| 2562 ae = self.assertEqual | |
| 2563 ae(str(issue.priority.name),'bug') | |
| 2564 ae(str(issue.priority['name']),'bug') | |
| 2565 ae(str(issue ['priority']['name']),'bug') | |
| 2566 ae(str(issue ['priority'].name),'bug') | |
| 2567 ae(str(issue.assignedto.username),'worker5') | |
| 2568 ae(str(issue.assignedto['username']),'worker5') | |
| 2569 ae(str(issue ['assignedto']['username']),'worker5') | |
| 2570 ae(str(issue ['assignedto'].username),'worker5') | |
| 2571 for n in issue.nosy: | |
| 2572 ae(n.username.plain(),'worker5') | |
| 2573 ae(n['username'].plain(),'worker5') | |
| 2574 for n in issue.messages: | |
| 2575 ae(n.author.username.plain(),'worker5') | |
| 2576 ae(n.author['username'].plain(),'worker5') | |
| 2577 ae(n['author'].username.plain(),'worker5') | |
| 2578 ae(n['author']['username'].plain(),'worker5') | |
| 2579 | |
| 2509 | 2580 |
| 2510 # vim: set et sts=4 sw=4 : | 2581 # vim: set et sts=4 sw=4 : |
