1287
1288
layer = DatabaseFunctionalLayer
1289
server_listing = soupmatchers.Tag(
1290
'Server', 'em', text='Server-side mustache')
1292
1290
client_listing = soupmatchers.Tag(
1293
1291
'client-listing', True, attrs={'id': 'client-listing'})
1295
def makeView(self, bugtask=None):
1296
request = LaunchpadTestRequest()
1293
def makeView(self, bugtask=None, size=None, memo=None, orderby=None,
1295
"""Make a BugTaskSearchListingView.
1297
:param bugtask: The task to use for searching.
1298
:param size: The size of the batches. Required if forwards is False.
1299
:param memo: Batch identifier.
1300
:param orderby: The way to order the batch.
1301
:param forwards: If true, walk forwards from the memo. Else walk
1306
if size is not None:
1307
query_vars['batch'] = size
1308
if memo is not None:
1309
query_vars['memo'] = memo
1311
query_vars['start'] = memo
1313
query_vars['start'] = int(memo) - size
1315
query_vars['direction'] = 'backwards'
1316
query_string = urllib.urlencode(query_vars)
1317
request = LaunchpadTestRequest(
1318
QUERY_STRING=query_string, orderby=orderby)
1297
1319
if bugtask is None:
1298
1320
bugtask = self.factory.makeBugTask()
1299
1321
view = BugTaskSearchListingView(bugtask.target, request)
1327
1350
self.assertEqual(1, len(bugtasks))
1328
1351
self.assertEqual(item.model, bugtasks[0])
1353
def test_no_next_prev_for_single_batch(self):
1354
"""The IJSONRequestCache should contain data about ajacent batches.
1356
mustache_model should contain bugtasks, the BugTaskListingItem.model
1359
owner, item = make_bug_task_listing_item(self.factory)
1360
self.useContext(person_logged_in(owner))
1361
with self.dynamic_listings():
1362
view = self.makeView(item.bugtask)
1363
cache = IJSONRequestCache(view.request)
1364
self.assertIs(None, cache.objects.get('next'))
1365
self.assertIs(None, cache.objects.get('prev'))
1367
def test_next_for_multiple_batch(self):
1368
"""The IJSONRequestCache should contain data about the next batch.
1370
mustache_model should contain bugtasks, the BugTaskListingItem.model
1373
task = self.factory.makeBugTask()
1374
self.factory.makeBugTask(target=task.target)
1375
with self.dynamic_listings():
1376
view = self.makeView(task, size=1)
1377
cache = IJSONRequestCache(view.request)
1378
self.assertEqual({'memo': '1', 'start': 1}, cache.objects.get('next'))
1380
def test_prev_for_multiple_batch(self):
1381
"""The IJSONRequestCache should contain data about the next batch.
1383
mustache_model should contain bugtasks, the BugTaskListingItem.model
1386
task = self.factory.makeBugTask()
1387
task2 = self.factory.makeBugTask(target=task.target)
1388
with self.dynamic_listings():
1389
view = self.makeView(task2, size=1, memo=1)
1390
cache = IJSONRequestCache(view.request)
1391
self.assertEqual({'memo': '1', 'start': 0}, cache.objects.get('prev'))
1393
def test_default_order_by(self):
1394
"""order_by defaults to '-importance in JSONRequestCache"""
1395
task = self.factory.makeBugTask()
1396
with self.dynamic_listings():
1397
view = self.makeView(task)
1398
cache = IJSONRequestCache(view.request)
1399
self.assertEqual('-importance', cache.objects['order_by'])
1401
def test_order_by_importance(self):
1402
"""order_by follows query params in JSONRequestCache"""
1403
task = self.factory.makeBugTask()
1404
with self.dynamic_listings():
1405
view = self.makeView(task, orderby='importance')
1406
cache = IJSONRequestCache(view.request)
1407
self.assertEqual('importance', cache.objects['order_by'])
1409
def test_cache_has_all_batch_vars_defaults(self):
1410
"""Cache has all the needed variables.
1412
order_by, memo, start, forwards. These default to sane values.
1414
task = self.factory.makeBugTask()
1415
with self.dynamic_listings():
1416
view = self.makeView(task)
1417
cache = IJSONRequestCache(view.request)
1418
self.assertEqual('-importance', cache.objects['order_by'])
1419
self.assertIs(None, cache.objects['memo'])
1420
self.assertEqual(0, cache.objects['start'])
1421
self.assertTrue(cache.objects['forwards'])
1423
def test_cache_has_all_batch_vars_specified(self):
1424
"""Cache has all the needed variables.
1426
order_by, memo, start, forwards. These are calculated appropriately.
1428
task = self.factory.makeBugTask()
1429
with self.dynamic_listings():
1430
view = self.makeView(task, memo=1, forwards=False, size=1)
1431
cache = IJSONRequestCache(view.request)
1432
self.assertEqual('1', cache.objects['memo'])
1433
self.assertEqual(0, cache.objects['start'])
1434
self.assertFalse(cache.objects['forwards'])
1435
self.assertEqual(0, cache.objects['last_start'])
1330
1437
def getBugtaskBrowser(self):
1438
"""Return a browser for a new bugtask."""
1331
1439
bugtask = self.factory.makeBugTask()
1332
1440
with person_logged_in(bugtask.target.owner):
1333
1441
bugtask.target.official_malone = True
1353
1462
number_tag = self.getBugNumberTag(bug_task)
1354
1463
self.assertHTML(browser, number_tag, invert=True)
1355
1464
self.assertHTML(browser, self.client_listing, invert=True)
1356
self.assertHTML(browser, self.server_listing, invert=True)
1358
1466
def test_mustache_rendering(self):
1359
1467
"""If the flag is present, then all mustache features appear."""
1360
1468
with self.dynamic_listings():
1361
1469
bug_task, browser = self.getBugtaskBrowser()
1362
1470
bug_number = self.getBugNumberTag(bug_task)
1364
browser, self.client_listing, self.server_listing, bug_number)
1471
self.assertHTML(browser, self.client_listing, bug_number)
1367
1474
class TestBugTaskListingItem(TestCaseWithFactory):