def test_doNotAddCommentsGreaterThan20000Characters(self): tracker = self.makeValidTracker() trackerInstance = self.trackerInstance_ testing = Testing() item = self.itemWithComments(testing) item.addComment(Testing.stringOfAsOfSize(20002)) tracker.updateCommentsFor(item) verify(trackerInstance, times=2).AddComment(any(), any())
def setupSync(self, syncDirection=ForwardSync): toTracker = mock() itemToSyncTo = mock() itemToSyncFrom = mock() syncCommentsFor = TrackerSyncBy.syncingItem(Direction=syncDirection) when(toTracker).items(None).thenReturn( Testing.MockIterator([itemToSyncTo])) return toTracker, itemToSyncTo, itemToSyncFrom, syncCommentsFor
def test_updateAddsNewComments(self): jira = JiraTracker() jiraInstance = self.getMockFor(jira) testing = Testing() item = self.itemWithComments(testing) jira.update(item) verify(jiraInstance.service, times=2).addComment(any(), any(), any()) pass
def test_20000PlusCharacterCommentsAreNotSyned(self): jira = self.jira_ pivotal = self.pivotal_ newJiraItem = jiraItemFactory(Env().get("jira", "project"), "test_20000PlusCharacterCommentsAreNotSyned", "blah") commentOnJira = TrackerItemComment(Testing.stringOfAsOfSize(20002)) newJiraItem.addComment(commentOnJira) self.syncNewItemToPivotal(newJiraItem, jira, pivotal) pivotalItem = next(pivotal.items()) self.assertEqual(len(pivotalItem.comments()), 0)
def test_rightItemReturnedWhenMoreThanOneItemReturnedForReverseSync(self): toTracker = mock() items = [mock(), mock(), mock()] when(toTracker).items(any()).thenReturn( Testing.MockIterator([items[1], items[2]])) when(items[1]).canBeSyncedWith(items[0]).thenReturn(False) when(items[2]).canBeSyncedWith(items[0]).thenReturn(True) forwardSync = ReverseSync(mock().function, items[0], toTracker, None) forwardSync.obtainItem() verify(items[2]).canBeSyncedWith(items[0])
def test_canAddCommentsToTicket(self): jira = JiraTracker() jiraInstance = self.getMockFor(jira) testing = Testing() item = self.itemWithComments(testing) jira.updateCommentsFor(item) inorder.verify(jiraInstance.service).login(any(),any()) inorder.verify(jiraInstance.service).addComment(self.auth_, testing.issue.key, {"body":testing.comment1.text()}) inorder.verify(jiraInstance.service).addComment(self.auth_, testing.issue.key, {"body":testing.comment2.text()}) pass
def test_commentsNotAddedIfItemIsNotTheSame(self): toTracker = mock() item = mock() otherItem = mock() syncCommentsFor = TrackerSyncBy.syncingItem() when(toTracker).items(None).thenReturn(Testing.MockIterator([item])) when(item).canBeSyncedWith(otherItem).thenReturn(False) syncCommentsFor(otherItem, toTracker) verify(item, never).syncWith(any()) verify(toTracker, never).update(item)
def test_20000PlusCharacterCommentsAreNotSyned(self): jira = self.jira_ pivotal = self.pivotal_ newJiraItem = jiraItemFactory( Env().get("jira", "project"), "test_20000PlusCharacterCommentsAreNotSyned", "blah") commentOnJira = TrackerItemComment(Testing.stringOfAsOfSize(20002)) newJiraItem.addComment(commentOnJira) self.syncNewItemToPivotal(newJiraItem, jira, pivotal) pivotalItem = next(pivotal.items()) self.assertEqual(len(pivotalItem.comments()), 0)
def test_updateAddsNewComments(self): tracker = self.makeValidTracker() trackerInstance = self.trackerInstance_ updatedStory = mock() testing = Testing() item = self.itemWithComments(testing) when(trackerInstance).UpdateStory(any()).thenReturn(updatedStory) when(updatedStory).GetName().thenReturn("") tracker.update(item) verify(trackerInstance, times=2).AddComment(any(), any()) pass
def test_canAddCommentsToStoryTicket(self): tracker = self.makeValidTracker() trackerInstance = self.trackerInstance_ testing = Testing() item = self.itemWithComments(testing) tracker.updateCommentsFor(item) inorder.verify(trackerInstance).AddComment(testing.issue.GetStoryId(), testing.comment1.text()) inorder.verify(trackerInstance).AddComment(testing.issue.GetStoryId(), testing.comment2.text()) pass
def test_doNotAddItemWhenItemInTracker(self): toTracker = mock() fromTracker = mock() detectedItem = mock() when(fromTracker).items(any()).thenReturn([detectedItem]) when(toTracker).items(any()).thenReturn( Testing.MockIterator([detectedItem])) when(detectedItem).canBeSyncedWith(detectedItem).thenReturn(True) syncByAddingItems = TrackerSyncBy.addingItemsOfType(None) syncByAddingItems(fromTracker, toTracker) verify(toTracker, never).update()
def test_reverseSyncGetsItemToSyncToFromCorrectTracker(self): toTracker, itemToSyncTo, itemToSyncFrom, syncCommentsFor = self.setupSync( ReverseSync) fromTracker = mock() when(fromTracker).items(None).thenReturn( Testing.MockIterator([itemToSyncFrom])) when(itemToSyncFrom).updatedAt().thenReturn(1) when(itemToSyncTo).updatedAt().thenReturn(0) when(itemToSyncTo).canBeSyncedWith(itemToSyncFrom).thenReturn(True) syncCommentsFor(itemToSyncFrom, toTracker, fromTracker) verify(itemToSyncFrom).syncWith(itemToSyncTo) verify(fromTracker).update(itemToSyncFrom)
def test_whenMultipleItemsMatchFilterAndItemsCanNotBeSyncedWithThenAddNewItem( self): toTracker = mock() fromTracker = mock() detectedItem = mock() when(fromTracker).items(any()).thenReturn([detectedItem]) when(toTracker).items(any()).thenReturn( Testing.MockIterator([detectedItem, detectedItem])) when(detectedItem).canBeSyncedWith(detectedItem).thenReturn( False).thenReturn(True) syncByAddingItems = TrackerSyncBy.addingItemsOfType(None) syncByAddingItems(fromTracker, toTracker) verify(toTracker, never).update()
def test_doNotAddUnnecessaryComments(self): toTracker = mock() item = mock() testFilter = mock() otherItem = mock() syncCommentsFor = TrackerSyncBy.syncingItem( FilteringOutCommentsFor=testFilter.calledWith) when(toTracker).items(None).thenReturn(Testing.MockIterator([item])) when(item).canBeSyncedWith(otherItem).thenReturn(True) when(item).updatedAt().thenReturn(0) when(otherItem).updatedAt().thenReturn(1) syncCommentsFor(otherItem, toTracker) verify(testFilter).calledWith(item)
def test_addCommentsAndUpdateIssue(self): toTracker = mock() itemToAddCommentsTo = mock() itemToGetCommentsFrom = mock() syncCommentsFor = TrackerSyncBy.syncingItem() when(toTracker).items(None).thenReturn( Testing.MockIterator([itemToAddCommentsTo])) when(itemToAddCommentsTo).canBeSyncedWith( itemToGetCommentsFrom).thenReturn(True) when(itemToAddCommentsTo).updatedAt().thenReturn(0) when(itemToGetCommentsFrom).updatedAt().thenReturn(1) syncCommentsFor(itemToGetCommentsFrom, toTracker) verify(itemToAddCommentsTo).syncWith(itemToGetCommentsFrom) verify(toTracker).update(itemToAddCommentsTo)
def test_filterFunctionIsUsed(self): toTracker = mock() fromTracker = mock() detectedItem = mock() filterValue = "filter" filterFunction = mock() when(fromTracker).items(any()).thenReturn([detectedItem]) when(toTracker).items(filterValue).thenReturn( Testing.MockIterator([detectedItem])) when(filterFunction).calledWith(detectedItem).thenReturn(filterValue) when(detectedItem).canBeSyncedWith(detectedItem).thenReturn(True) syncByAddingItems = TrackerSyncBy.addingItemsOfType( None, filterFunction.calledWith) syncByAddingItems(fromTracker, toTracker) verify(toTracker).items(filterValue)
def test_whenMultipleItemsMatchFilterAndItemCanBeSyncedWithThenDoNotAddNewItem( self): toTracker = mock() fromTracker = mock() detectedItem = mock() TrackerItemType = mock() itemToBeAdded = mock() when(fromTracker).items(any()).thenReturn([detectedItem]) when(toTracker).items(any()).thenReturn( Testing.MockIterator([detectedItem, detectedItem])) when(detectedItem).canBeSyncedWith(detectedItem).thenReturn(False) when(TrackerItemType).called().thenReturn(itemToBeAdded) when(toTracker).update(itemToBeAdded).thenReturn(itemToBeAdded) syncByAddingItems = TrackerSyncBy.addingItemsOfType( TrackerItemType.called) syncByAddingItems(fromTracker, toTracker) verify(toTracker, times=2).update(itemToBeAdded)