992
997
self.assertEquals(
993
998
"- foo<br />+ bar &<>",
994
999
BugActivityItem(bug.activity[-1]).change_details)
1002
class TestBugTaskBatchedCommentsAndActivityView(TestCaseWithFactory):
1003
"""Tests for the BugTaskBatchedCommentsAndActivityView class."""
1005
layer = LaunchpadFunctionalLayer
1007
def _makeNoisyBug(self, comments_only=False):
1008
"""Create and return a bug with a lot of comments and activity."""
1009
bug = self.factory.makeBug(
1010
date_created=datetime.now(UTC) - timedelta(days=30))
1011
with person_logged_in(bug.owner):
1012
if not comments_only:
1014
task = self.factory.makeBugTask(bug=bug)
1015
change = BugTaskStatusChange(
1016
task, datetime.now(UTC), task.product.owner, 'status',
1017
BugTaskStatus.NEW, BugTaskStatus.TRIAGED)
1018
bug.addChange(change)
1019
for i in range (10):
1020
msg = self.factory.makeMessage(
1021
owner=bug.owner, content="Message %i." % i,
1022
datecreated=datetime.now(UTC) - timedelta(days=20-i))
1023
bug.linkMessage(msg, user=bug.owner)
1026
def test_offset(self):
1027
# BugTaskBatchedCommentsAndActivityView.offset returns the
1028
# current offset being used to select a batch of bug comments
1029
# and activity. If one is not specified, the view's
1030
# visible_initial_comments count will be returned (so that
1031
# comments already shown on the page won't appear twice).
1032
bug_task = self.factory.makeBugTask()
1033
view = create_initialized_view(bug_task, '+batched-comments')
1034
self.assertEqual(view.visible_initial_comments, view.offset)
1035
view = create_initialized_view(
1036
bug_task, '+batched-comments', form={'offset': 100})
1037
self.assertEqual(100, view.offset)
1039
def test_batch_size(self):
1040
# BugTaskBatchedCommentsAndActivityView.batch_size returns the
1041
# current batch_size being used to select a batch of bug comments
1042
# and activity or the default configured batch size if one has
1043
# not been specified.
1044
bug_task = self.factory.makeBugTask()
1045
view = create_initialized_view(bug_task, '+batched-comments')
1047
config.malone.comments_list_default_batch_size,
1049
view = create_initialized_view(
1050
bug_task, '+batched-comments', form={'batch_size': 20})
1051
self.assertEqual(20, view.batch_size)
1053
def test_event_groups_only_returns_batch_size_results(self):
1054
# BugTaskBatchedCommentsAndActivityView._event_groups will
1055
# return only batch_size results.
1056
bug = self._makeNoisyBug()
1057
view = create_initialized_view(
1058
bug.default_bugtask, '+batched-comments',
1059
form={'batch_size': 10})
1060
self.assertEqual(10, len([group for group in view._event_groups]))
1062
def test_activity_and_comments_matches_unbatched_version(self):
1063
# BugTaskBatchedCommentsAndActivityView extends BugTaskView in
1064
# order to add the batching logic and reduce rendering
1065
# overheads. The results of activity_and_comments is the same
1067
# We create a bug with comments only so that we can test the
1068
# contents of activity_and_comments properly. Trying to test it
1069
# with multiply different datatypes is fragile at best.
1070
bug = self._makeNoisyBug(comments_only=True)
1071
# We create a batched view with an offset of 0 so that all the
1072
# comments are returned.
1073
batched_view = create_initialized_view(
1074
bug.default_bugtask, '+batched-comments',
1076
unbatched_view = create_initialized_view(
1077
bug.default_bugtask, '+index')
1079
len(unbatched_view.activity_and_comments),
1080
len(batched_view.activity_and_comments))
1081
for i in range(len(unbatched_view.activity_and_comments)):
1082
unbatched_item = unbatched_view.activity_and_comments[i]
1083
batched_item = batched_view.activity_and_comments[i]
1085
unbatched_item['comment'].text_for_display,
1086
batched_item['comment'].text_for_display)