def test_doNotOverwriteWithUnknownOwner(self):
     item = JiraTrackerItem()
     withAssignee = "assignee"
     load = self.create_loader(JiraTrackerItem.withOwner)
     load(item, withAssignee)
     item.withOwner(JiraUser(None))
     self.assertEqual(withAssignee, item.owner().jira())
 def test_changingDescriptionChangesJiraTicketDescription(self):
     item = JiraTrackerItem()
     description = "New"
     returnedItem = item.withDescription(description)
     self.assertEqual(item.underlying().description(), description)
     self.assertEqual(returnedItem, item)
     pass
 def test_changingSummaryChangesJiraTicketSummary(self):
     item = JiraTrackerItem()
     summary = "New"
     returnedItem = item.withSummary(summary)
     self.assertEqual(item.underlying().summary(), summary)
     self.assertEqual(returnedItem, item)
     pass
 def test_doNotOverwriteWithUnknownReporter(self):
     item = JiraTrackerItem()
     withReporter = "reporter"
     load = self.create_loader(JiraTrackerItem.withRequestor)
     load(item, withReporter)
     item.withRequestor(JiraUser(None))
     self.assertEqual(withReporter, item.requestor().jira())
 def test_canAddExistingCommentToIssue(self):
     item = JiraTrackerItem()
     existingComment = {'created':datetime.now(), 'author':"lwoydziak", 'body':"Comment 1"}
     item.addComment(existingComment, "existing")
     comments = item.comments('new')
     existingComments = item.comments()
     self.assertEqual(comments, [])
     self.assertEqual(existingComments[0], existingComment)
 def test_canOverwriteKnownAssignee(self):
     item = JiraTrackerItem()
     withAssignee = "assignee"
     load = self.create_loader(JiraTrackerItem.withOwner)
     load(item, withAssignee)
     random = "me"
     item.withOwner(JiraUser(random))
     self.assertEqual(random, item.owner().jira())
 def test_canGetUpdatedAtDateTime(self):
     testTicket = JiraTicket()
     date = datetime.now()
     testTicket.details_.updated = date
     timezone = UTC()
     item = JiraTrackerItem(testTicket, timezone)
     self.assertEqual(date, item.updatedAt())
     self.assertEqual(None, item.updatedAt().tzinfo)
 def test_canAddNewCommentToIssue(self):
     item = JiraTrackerItem()
     newComment = "Comments work now"
     item.addComment(newComment)
     comments = item.comments('new')
     existingComments = item.comments()
     self.assertEqual(comments[0], newComment)
     self.assertEqual(existingComments, [])
 def test_canOverwriteKnownReporter(self):
     item = JiraTrackerItem()
     withReporter = "reporter"
     load = self.create_loader(JiraTrackerItem.withRequestor)
     load(item, withReporter)
     random = mock()
     when(random).jira().thenReturn("blah")
     item.withRequestor(random)
     self.assertEqual(random, item.requestor())
 def test_canGetStatusWhenAddedViaUnderlying(self):
     PivotalToJiraStatusMap().addMapping(jira="Closed", pivotal="Accepted") 
     jiraStatus = JiraStatus(6, "Closed")
     PivotalToJiraStatusMap().insert(jiraStatus)
     testTicket = JiraTicket()
     testTicket.setStatus(jiraStatus.id)
     item = JiraTrackerItem(testTicket)
     self.assertEqual(item.status().jira(), [jiraStatus.name])
     PivotalToJiraStatusMap().reset()
 def test_canCopyItemSpecificDataToAnotherItem(self):
     modified = mock()
     testIssue = self.testIssue()
     testIssueUrl = "http://www.jira.com/browse/TEST-12345"
     source = JiraTrackerItem(testIssue)
     source.withJiraUrl(testIssueUrl)
     source.copyTypeSpecificDataTo(modified)
     verify(modified).withJiraKey(testIssue.key)
     verify(modified).withJiraUrl(testIssueUrl)
def jiraItemFactory(project, summary, description):
    item = JiraTrackerItem().withSummary(summary).withDescription(description)
    item.underlying().details_.project = project
    item.underlying().details_.type = "2"
    testRemoteVersion = {"id" : "10000"}
    testRemoteComponent = {"id" : "10000"}
    item.underlying().details_.affectsVersions = [testRemoteVersion,]
    item.underlying().details_.components = [testRemoteComponent,]
    item.underlying().details_.priority = "3"
    return item
 def test_doNotOverwriteUnknownReporter(self):
     item = JiraTrackerItem()
     withReporter = "reporter"
     load = self.create_loader(JiraTrackerItem.withRequestor)
     load(item, withReporter)
     PivotalToJiraUserMap().reset()
     random = "me"
     item.withRequestor(JiraUser(random))
     self.assertNotEqual(random, item.requestor().jira())
     self.assertEqual(withReporter, item.requestor().jira())
 def test_canSeedWithTicket(self):
     testTicket = JiraTicket()
     summary = "Test Summary"
     testTicket.setSummary(summary)
     item = JiraTrackerItem(testTicket)
     self.assertEqual(item.summary(), summary)
     testIssue = RemoteIssue()
     description = "Test Description"
     testIssue.description = description
     item = JiraTrackerItem(testIssue)
     self.assertEqual(item.description(), description)
 def test_doNotOverwriteUnknownAssignee(self):
     PivotalToJiraUserMap().reset()
     item = JiraTrackerItem()
     withAssignee = "assignee"
     load = self.create_loader(JiraTrackerItem.withOwner)
     load(item, withAssignee)
     PivotalToJiraUserMap().reset()
     random = "me"
     item.withOwner(JiraUser(random))
     self.assertNotEqual(random, item.owner().jira())
     self.assertEqual(withAssignee, item.owner().jira())
 def test_canAddStatus(self):
     PivotalToJiraStatusMap().addMapping(jira="Closed", pivotal="Accepted")
     jiraStatus = JiraStatus(6, "Closed")
     PivotalToJiraStatusMap().insert(jiraStatus)
     item = JiraTrackerItem()
     statusId = 6
     ticket = JiraTicket()
     ticket.setStatus(statusId)
     status = TrackerItemStatus(ticket)
     item.withStatus(status)
     self.assertEqual(item.status(), status)
     self.assertEqual(item.piecesToUpdate(), [{'id':"status", 'values':['',]},])
     PivotalToJiraStatusMap().reset()
 def test_canChangeAssignee(self):
     item = JiraTrackerItem()        
     assignee = "me"
     item.withOwner(JiraUser(assignee))
     self.assertEqual(assignee, item.owner().jira())
     self.assertEqual(assignee, item.underlying().assignee())
     self.assertEqual(item.piecesToUpdate(), [{'id':"assignee" , 'values':[assignee,]}])
 def test_canChangeReporter(self):
     item = JiraTrackerItem()        
     requestor = mock()
     reporter = "me"
     when(requestor).jira().thenReturn(reporter).thenReturn(reporter)
     item.withRequestor(requestor)
     self.assertEqual(requestor, item.requestor())
     self.assertEqual(reporter, item.underlying().reporter())
     self.assertEqual(item.piecesToUpdate(), [{'id':"reporter" , 'values':[reporter,]}])
 def update(self, item):
     super(JiraTracker, self).update(item)
     print("Update Jira Ticket:")
     if item.Id() is None:
         print(item.asRemoteItem())
         issue = self.trackerInstance_.createIssue(self.authentication_, item.asRemoteItem())
     else:
         print(item.piecesToUpdate())
         issue = self.trackerInstance_.updateIssue(self.authentication_, item.Id(), item.piecesToUpdate())
     updatedItem = JiraTrackerItem(issue)
     if "status" in str(item.piecesToUpdate()):
         updatedItem.withStatus(item.status())
         updatedItem = JiraTrackerItem(self._ticketWithUpdatedStatusFrom(updatedItem))
     print(item.comments("new"))
     updatedItem.withComments(item.comments("new"))
     # to be fully complete updatedItem also needs exisiting comments - tbd
     return self.updateCommentsFor(updatedItem)
 def test_cannotSyncWithNoItem(self):
     item = JiraTrackerItem()
     self.assertFalse(item.canBeSyncedWith(None))
 def test_doNotAddDuplicateReporter(self):
     testTicket = mock()
     item = JiraTrackerItem(testTicket)
     item.withRequestor(JiraUser(testTicket.reporter)) 
     self.assertEqual(item.piecesToUpdate(), [])
 def test_descriptionAsPeicesToUpdateReturnedWhenItemIsUpdatedWithDescription(self):
     testIssue = self.testIssue()
     item = JiraTrackerItem(testIssue)
     description = "new value"
     item.withDescription(description)
     self.assertEqual(item.piecesToUpdate(), [{'id':"description" , 'values':[description,]}])
 def test_descriptionAsPiecesNotAddedWhenTryingToAddDuplicateDescription(self):
     testIssue = mock()
     item = JiraTrackerItem(testIssue)
     item.withDescription(testIssue.description)
     self.assertEqual(item.piecesToUpdate(), [])
 def test_summaryAsPeicesToUpdateReturnedWhenItemIsUpdatedWithSummary(self):
     testIssue = self.testIssue()
     item = JiraTrackerItem(testIssue)
     summary = "new value"
     item.withSummary(summary)
     self.assertEqual(item.piecesToUpdate(), [{'id':"summary" , 'values':[summary,]}])
 def test_summaryAsPiecesNotAddedWhenTryingToAddDuplicateSummary(self):
     testIssue = mock()
     item = JiraTrackerItem(testIssue)
     item.withSummary(testIssue.summary)
     self.assertEqual(item.piecesToUpdate(), [])
 def test_canGetItemAsRemoteItem(self):
     testIssue = self.testIssue()
     description = "Test Description"
     testIssue.description = description
     item = JiraTrackerItem(testIssue)
     self.assertEqual(item.asRemoteItem(), testIssue.__dict__)
 def test_jiraItemTypeIsBug(self):
     item = JiraTrackerItem()
     self.assertEqual("bug", item.type())
 def test_doNotAddDuplicateAssignee(self):
     testTicket = mock()
     item = JiraTrackerItem(testTicket)
     item.withOwner(JiraUser(testTicket.assignee)) 
     self.assertEqual(item.piecesToUpdate(), [])
 def test_statusAsPiecesNotAddedWhenTryingToAddDuplicateStatus(self):
     testIssue = mock()
     item = JiraTrackerItem(testIssue)
     duplicateStatus = item.status()
     item.withStatus(duplicateStatus)
     self.assertEqual(item.piecesToUpdate(), [])
 def test_settingJiraKeyDoesNotChangeUnderlying(self):
     testTicket = mock()
     item = JiraTrackerItem(testTicket)
     tryKey = "jiraKey"
     item.withJiraKey(tryKey)
     self.assertNotEqual(tryKey, item.jiraKey())