Index: appengine/monorail/tracker/test/tablecell_test.py |
diff --git a/appengine/monorail/tracker/test/tablecell_test.py b/appengine/monorail/tracker/test/tablecell_test.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..31617d05c9a7710e1898d6a7913d7d13976fcc22 |
--- /dev/null |
+++ b/appengine/monorail/tracker/test/tablecell_test.py |
@@ -0,0 +1,290 @@ |
+# Copyright 2016 The Chromium Authors. All rights reserved. |
+# Use of this source code is govered by a BSD-style |
+# license that can be found in the LICENSE file or at |
+# https://developers.google.com/open-source/licenses/bsd |
+ |
+"""Unit tests for issuelist module.""" |
+ |
+import unittest |
+ |
+from framework import framework_constants |
+from framework import table_view_helpers |
+from proto import tracker_pb2 |
+from testing import fake |
+from tracker import tablecell |
+ |
+ |
+class DisplayNameMock(object): |
+ |
+ def __init__(self, name): |
+ self.display_name = name |
+ |
+ |
+def MakeTestIssue(local_id, issue_id, summary): |
+ issue = tracker_pb2.Issue() |
+ issue.local_id = local_id |
+ issue.issue_id = issue_id |
+ issue.summary = summary |
+ return issue |
+ |
+ |
+class TableCellUnitTest(unittest.TestCase): |
+ |
+ USERS_BY_ID = { |
+ 23456: DisplayNameMock('Jason'), |
+ 34567: DisplayNameMock('Nathan'), |
+ } |
+ |
+ def setUp(self): |
+ self.issue1 = MakeTestIssue( |
+ local_id=1, issue_id=100001, summary='One') |
+ self.issue2 = MakeTestIssue( |
+ local_id=2, issue_id=100002, summary='Two') |
+ self.issue3 = MakeTestIssue( |
+ local_id=3, issue_id=100003, summary='Three') |
+ |
+ def testTableCellID(self): |
+ cell = tablecell.TableCellID( |
+ MakeTestIssue(4, 4, 'Four'), None, self.USERS_BY_ID, [], {}, {}, |
+ 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ID) |
+ # Note that the ID itself is accessed from the row, not the cell. |
+ |
+ def testTableCellOwner(self): |
+ test_issue = MakeTestIssue(4, 4, 'Four') |
+ test_issue.owner_id=23456 |
+ |
+ cell = tablecell.TableCellOwner( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ATTR) |
+ self.assertEqual(cell.values[0].item, 'Jason') |
+ |
+ def testTableCellOwnerNoOwner(self): |
+ test_issue = MakeTestIssue(4, 4, 'Four') |
+ test_issue.owner_id=framework_constants.NO_USER_SPECIFIED |
+ |
+ cell = tablecell.TableCellOwner( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ATTR) |
+ self.assertEqual(cell.values, []) |
+ |
+ def testTableCellReporter(self): |
+ test_issue = MakeTestIssue(4, 4, 'Four') |
+ test_issue.reporter_id=34567 |
+ |
+ cell = tablecell.TableCellReporter( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ATTR) |
+ self.assertEqual(cell.values[0].item, 'Nathan') |
+ |
+ def testTableCellCc(self): |
+ test_issue = MakeTestIssue(4, 4, 'Four') |
+ test_issue.cc_ids = [23456, 34567] |
+ |
+ cell = tablecell.TableCellCc( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ATTR) |
+ self.assertEqual(cell.values[0].item, 'Jason') |
+ self.assertEqual(cell.values[1].item, 'Nathan') |
+ |
+ def testTableCellCcNoCcs(self): |
+ cell = tablecell.TableCellCc( |
+ MakeTestIssue(4, 4, 'Four'), |
+ None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ATTR) |
+ self.assertEqual(cell.values, []) |
+ |
+ def testTableCellAttachmentsNone(self): |
+ cell = tablecell.TableCellAttachments( |
+ MakeTestIssue(4, 4, 'Four'), |
+ None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ATTR) |
+ self.assertEqual(cell.values[0].item, 0) |
+ |
+ def testTableCellAttachments(self): |
+ test_issue = MakeTestIssue(4, 4, 'Four') |
+ test_issue.attachment_count = 2 |
+ |
+ cell = tablecell.TableCellAttachments( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ATTR) |
+ self.assertEqual(cell.values[0].item, 2) |
+ |
+ def testTableCellOpened(self): |
+ test_issue = MakeTestIssue(4, 4, 'Four') |
+ test_issue.opened_timestamp = 1200000000 |
+ |
+ cell = tablecell.TableCellOpened( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_UNFILTERABLE) |
+ self.assertEqual(cell.values[0].item, 'Jan 2008') |
+ |
+ def testTableCellClosed(self): |
+ test_issue = MakeTestIssue(4, 4, 'Four') |
+ test_issue.closed_timestamp = None |
+ |
+ cell = tablecell.TableCellClosed( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_UNFILTERABLE) |
+ self.assertEqual(cell.values, []) |
+ |
+ test_issue.closed_timestamp = 1200000000 |
+ cell = tablecell.TableCellClosed( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_UNFILTERABLE) |
+ self.assertEqual(cell.values[0].item, 'Jan 2008') |
+ |
+ def testTableCellModified(self): |
+ test_issue = MakeTestIssue(4, 4, 'Four') |
+ test_issue.modified_timestamp = None |
+ |
+ cell = tablecell.TableCellModified( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_UNFILTERABLE) |
+ self.assertEqual(cell.values, []) |
+ |
+ test_issue.modified_timestamp = 1200000000 |
+ cell = tablecell.TableCellModified( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_UNFILTERABLE) |
+ self.assertEqual(cell.values[0].item, 'Jan 2008') |
+ |
+ def testTableCellBlockedOn(self): |
+ test_issue = MakeTestIssue(4, 4, 'Four') |
+ test_issue.blocked_on_iids = [ |
+ self.issue1.issue_id, self.issue2.issue_id, self.issue3.issue_id] |
+ |
+ cell = tablecell.TableCellBlockedOn( |
+ test_issue, |
+ None, self.USERS_BY_ID, [], {}, |
+ {self.issue1.issue_id: self.issue1, self.issue2.issue_id: self.issue2, |
+ self.issue3.issue_id: self.issue3}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ATTR) |
+ self.assertEqual(cell.values[0].item, '1') |
+ self.assertEqual(cell.values[1].item, '2') |
+ self.assertEqual(cell.values[2].item, '3') |
+ |
+ def testTableCellBlockedOnNone(self): |
+ cell = tablecell.TableCellBlockedOn( |
+ MakeTestIssue(4, 4, 'Four'), |
+ None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ATTR) |
+ self.assertEqual(cell.values, []) |
+ |
+ def testTableCellBlocking(self): |
+ test_issue = MakeTestIssue(4, 4, 'Four') |
+ test_issue.blocking_iids = [ |
+ self.issue1.issue_id, self.issue2.issue_id, self.issue3.issue_id] |
+ |
+ cell = tablecell.TableCellBlocking( |
+ test_issue, |
+ None, self.USERS_BY_ID, [], {}, |
+ {self.issue1.issue_id: self.issue1, self.issue2.issue_id: self.issue2, |
+ self.issue3.issue_id: self.issue3}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ATTR) |
+ self.assertEqual(cell.values[0].item, '1') |
+ self.assertEqual(cell.values[1].item, '2') |
+ self.assertEqual(cell.values[2].item, '3') |
+ |
+ def testTableCellBlockingNone(self): |
+ cell = tablecell.TableCellBlocking( |
+ MakeTestIssue(4, 4, 'Four'), |
+ None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ATTR) |
+ self.assertEqual(cell.values, []) |
+ |
+ def testTableCellBlocked(self): |
+ test_issue = MakeTestIssue(4, 4, 'Four') |
+ test_issue.blocked_on_iids = [1, 2, 3] |
+ |
+ cell = tablecell.TableCellBlocked( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ATTR) |
+ self.assertEqual(cell.values[0].item, 'Yes') |
+ |
+ def testTableCellBlockedNotBlocked(self): |
+ cell = tablecell.TableCellBlocked( |
+ MakeTestIssue(4, 4, 'Four'), |
+ None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ATTR) |
+ self.assertEqual(cell.values[0].item, 'No') |
+ |
+ def testTableCellMergedInto(self): |
+ test_issue = MakeTestIssue(4, 4, 'Four') |
+ test_issue.merged_into = self.issue3.issue_id |
+ |
+ cell = tablecell.TableCellMergedInto( |
+ test_issue, None, self.USERS_BY_ID, [], {}, |
+ {self.issue3.issue_id: self.issue3}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ATTR) |
+ self.assertEqual(cell.values[0].item, '3') |
+ |
+ def testTableCellMergedIntoNotMerged(self): |
+ cell = tablecell.TableCellMergedInto( |
+ MakeTestIssue(4, 4, 'Four'), |
+ None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ATTR) |
+ self.assertEqual(cell.values, []) |
+ |
+ |
+class TableCellCSVTest(unittest.TestCase): |
+ |
+ USERS_BY_ID = { |
+ 23456: DisplayNameMock('Jason'), |
+ 34567: DisplayNameMock('Nathan'), |
+ } |
+ |
+ def testTableCellOpenedTimestamp(self): |
+ test_issue = MakeTestIssue(4, 4, 'Four') |
+ test_issue.opened_timestamp = 1200000000 |
+ |
+ cell = tablecell.TableCellOpenedTimestamp( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_UNFILTERABLE) |
+ self.assertEqual(cell.values[0].item, 1200000000) |
+ |
+ def testTableCellClosedTimestamp(self): |
+ test_issue = MakeTestIssue(4, 4, 'Four') |
+ test_issue.closed_timestamp = None |
+ |
+ cell = tablecell.TableCellClosedTimestamp( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_UNFILTERABLE) |
+ self.assertEqual(cell.values[0].item, 0) |
+ |
+ test_issue.closed_timestamp = 1200000000 |
+ cell = tablecell.TableCellClosedTimestamp( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_UNFILTERABLE) |
+ self.assertEqual(cell.values[0].item, 1200000000) |
+ |
+ def testTableCellModifiedTimestamp(self): |
+ test_issue = MakeTestIssue(4, 4, 'Four') |
+ test_issue.modified_timestamp = 0 |
+ |
+ cell = tablecell.TableCellModifiedTimestamp( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_UNFILTERABLE) |
+ self.assertEqual(cell.values[0].item, 0) |
+ |
+ test_issue.modified_timestamp = 1200000000 |
+ cell = tablecell.TableCellModifiedTimestamp( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_UNFILTERABLE) |
+ self.assertEqual(cell.values[0].item, 1200000000) |
+ |
+ def testTableCellAllLabels(self): |
+ labels = ['A', 'B', 'C', 'D-E', 'F-G'] |
+ derived_labels = ['W', 'X', 'Y-Z'] |
+ |
+ test_issue = MakeTestIssue(4, 4, 'Four') |
+ test_issue.labels = labels |
+ test_issue.derived_labels = derived_labels |
+ |
+ cell = tablecell.TableCellAllLabels( |
+ test_issue, None, self.USERS_BY_ID, [], {}, {}, 'fake config') |
+ self.assertEqual(cell.type, table_view_helpers.CELL_TYPE_ATTR) |
+ self.assertEqual([v.item for v in cell.values], labels + derived_labels) |
+ |
+if __name__ == '__main__': |
+ unittest.main() |