def test_with_one_non_comment_notification(self): # Given a single non-comment notification, a single batch is # generated. notification = FakeNotification(False) self.assertEquals( [[notification]], list(notification_batches([notification])))
def test_notifications_for_different_owners(self): # Batches are grouped by owner. notifications = [ FakeNotification(owner=number) for number in range(5)] expected = [[notification] for notification in notifications] observed = list(notification_batches(notifications)) self.assertEquals(expected, observed)
def test_with_two_notifications_comment_last(self): # Given two similar notifications, one a comment, one not, and the # comment last, a single batch is generated. notification1 = FakeNotification(False) notification2 = FakeNotification(True) notifications = [notification1, notification2] self.assertEquals( [[notification1, notification2]], list(notification_batches(notifications)))
def test_with_three_notifications_comment_in_middle(self): # Given three similar notifications, one a comment, two not, and the # comment in the middle, one batch is generated. notification1 = FakeNotification(False) notification2 = FakeNotification(True) notification3 = FakeNotification(False) notifications = [notification1, notification2, notification3] self.assertEquals( [[notification1, notification2, notification3]], list(notification_batches(notifications)))
def test_notifications_with_mixed_bugs_owners_and_comments(self): # Batches are grouped by bug, owner and comments. notifications = [ FakeNotification(is_comment=False, bug=1, owner=1), FakeNotification(is_comment=False, bug=1, owner=1), FakeNotification(is_comment=True, bug=1, owner=1), FakeNotification(is_comment=False, bug=1, owner=2), ] expected = [notifications[0:3], notifications[3:4]] observed = list(notification_batches(notifications)) self.assertEquals(expected, observed)
def test_notifications_with_mixed_bugs_and_owners_2(self): # Batches are grouped by bug and owner. notifications = [ FakeNotification(bug=1, owner=1), FakeNotification(bug=1, owner=1), FakeNotification(bug=2, owner=2), FakeNotification(bug=2, owner=2), ] expected = [notifications[0:2], notifications[2:4]] observed = list(notification_batches(notifications)) self.assertEquals(expected, observed)
def test_with_more_notifications(self): # Given four similar notifications - non-comment, comment, # non-comment, comment - two batches are generated. The first three # notifications are in the first batch. notification1 = FakeNotification(False) notification2 = FakeNotification(True) notification3 = FakeNotification(False) notification4 = FakeNotification(True) notifications = [ notification1, notification2, notification3, notification4, ] self.assertEquals( [[notification1, notification2, notification3], [notification4]], list(notification_batches(notifications)))
def test_notifications_for_same_owner(self): # Batches are grouped by owner. notifications = [FakeNotification(owner=1) for number in range(5)] observed = list(notification_batches(notifications)) self.assertEquals([notifications], observed)
def test_with_nothing(self): # Nothing is generated if an empty list is passed in. self.assertEquals([], list(notification_batches([])))