def test_cleanup_quits_webdrivers(self):
        "Tests that clean up is performed on webdrivers created by WebdriverManger"
        config_reader = mock(ConfigReader)
        when(config_reader).get(
            WebDriverManager.SHUTDOWN_HOOK_CONFIG, True).thenReturn(True)
        when(config_reader).get(
            WebDriverManager.REUSE_BROWSER, True).thenReturn(False)
        when(config_reader).get(
            WebDriverManager.REUSE_BROWSER, True).thenReturn(False)
        when(config_reader).get(
            WebDriverManager.ENABLE_THREADING_SUPPORT, False).thenReturn(True)

        webdriver_mock1 = mock(WebDriver)
        webdriverfactory_mock = mock(WebDriverFactory)
        when(webdriverfactory_mock).create_webdriver(
            testname=None).thenReturn(webdriver_mock1)

        webdriver_provider = WebDriverManager(webdriver_factory=webdriverfactory_mock,
                                              config=config_reader)

        # Spawn thread to check if driver is unique per thread.
        driver = webdriver_provider.get_driver()
        del webdriver_provider

        # verify decontructor cleans up the webdriver.
        verify(driver).quit()
 def test_onlyTakeCommentsFromIssueForByFilter(self):
     toTracker = mock()
     aTestItemFilter = mock()
     syncCommentsFor = TrackerSyncBy.syncingItem(aTestItemFilter.calledWith)
     when(toTracker).items(None).thenRaise(StopIteration)
     syncCommentsFor(None, toTracker)
     verify(aTestItemFilter).calledWith(None)
def test_CanRetrieveDevicesListFiltered():
    pertinoSdk, _, response = setupSdk()
    json = {"devices": [{"ipv4Address": "123.456.789.10", "hostName": "host", "id": 1234}]}
    when(response).json().thenReturn(json)
    closure = mock()
    pertinoSdk.listDevicesIn({"id":1}, closure.function)
    verify(closure).function(json["devices"][0])
 def test_doNotAddCommentsWhenItemNotFound(self):
     toTracker = mock()
     item = mock()
     syncCommentsFor = TrackerSyncBy.syncingItem()
     when(toTracker).items(None).thenRaise(StopIteration)
     syncCommentsFor(item, toTracker)
     verify(toTracker, never).update(item)
 def test_onlyTakeCommentsFromIssueForByFilter(self):
     toTracker = mock()
     aTestItemFilter = mock()
     syncCommentsFor = TrackerSyncBy.syncingItem(aTestItemFilter.calledWith)
     when(toTracker).items(None).thenRaise(StopIteration)
     syncCommentsFor(None, toTracker)
     verify(aTestItemFilter).calledWith(None)
Esempio n. 6
0
 def test_whenJiraIdIsZeroNameIsNone(self):
     jiraStatus = mock()
     mapObject = mock()
     when(jiraStatus).status().thenReturn("")
     status = TrackerItemStatus(jiraStatus, mapObject)
     verify(mapObject, never).translateStatusTo(any(), any())
     self.assertEqual(status.jira(), None)
 def test_doNotAddItemWhenNoItemToAdd(self):
     toTracker = mock()
     fromTracker = mock()
     when(fromTracker).items(any()).thenReturn([])
     syncByAddingItems = TrackerSyncBy.addingItemsOfType(None)
     syncByAddingItems(fromTracker, toTracker)
     verify(toTracker, never).update()
 def test_user_can_login_with_password(self):
     cli = mock()
     user = User("username", "password", cli)
     when(cli).compareReceivedAgainst(any(),any(), indexOfSuccessfulResult=any()).thenReturn(0).thenReturn(1)
     user.login()
     verify(cli).send("su username")
     verify(cli).send("password")
 def test_doNotAddItemWhenNoItemToAdd(self):
     toTracker = mock()
     fromTracker = mock()
     when(fromTracker).items(any()).thenReturn([])
     syncByAddingItems = TrackerSyncBy.addingItemsOfType(None)
     syncByAddingItems(fromTracker, toTracker)
     verify(toTracker, never).update()
 def testFeedback(self):
     bmlToIpaaca = BMLRealizerToIpaacaAdapter()
     ipaacaToBML = IpaacaToBMLRealizerAdapter(self.mockRealizerPort)
     bmlToIpaaca.addListeners(self.mockFeedbackListener);
     ipaacaToBML.feedback("bmlfeedback");
     time.sleep(0.05)
     verify(self.mockFeedbackListener).feedback("bmlfeedback");    
 def test_filterIsSentWhenSpecified(self):
     jira = JiraTracker()
     jiraInstance = self.getMockFor(jira)
     forFilter = "blah"
     self.setMocksForGettingItems(jiraInstance)
     self.assertRaises(StopIteration, next, jira._getItems(forFilter)) 
     verify(jiraInstance.service).getIssuesFromJqlSearch(any(),forFilter,any())
def test_CanRetrieveOrganizationListFiltered():
    pertinoSdk, _, response = setupSdk()
    json = {"orgs": [{"name": "organization", "id": 1234}]}
    when(response).json().thenReturn(json)
    closure = mock()
    pertinoSdk.listOrgs(closure=closure.function)
    verify(closure).function(json["orgs"][0])
Esempio n. 13
0
    def test_cleanup_quits_webdrivers(self):
        "Tests that clean up is performed on webdrivers created by WebdriverManger"
        config_reader = mock(ConfigReader)
        when(config_reader).get(WebDriverManager.SHUTDOWN_HOOK_CONFIG,
                                True).thenReturn(True)
        when(config_reader).get(WebDriverManager.REUSE_BROWSER,
                                True).thenReturn(False)
        when(config_reader).get(WebDriverManager.REUSE_BROWSER,
                                True).thenReturn(False)
        when(config_reader).get(WebDriverManager.ENABLE_THREADING_SUPPORT,
                                False).thenReturn(True)

        webdriver_mock1 = mock(WebDriver)
        webdriverfactory_mock = mock(WebDriverFactory)
        when(webdriverfactory_mock).create_webdriver(
            testname=None).thenReturn(webdriver_mock1)

        webdriver_provider = WebDriverManager(
            webdriver_factory=webdriverfactory_mock, config=config_reader)

        # Spawn thread to check if driver is unique per thread.
        driver = webdriver_provider.get_driver()
        del webdriver_provider

        # verify decontructor cleans up the webdriver.
        verify(driver).quit()
 def testFeedbackOtherCharacter(self):
     bmlToIpaaca = BMLRealizerToIpaacaAdapter("Fred")
     ipaacaToBML = IpaacaToBMLRealizerAdapter(self.mockRealizerPort,"Wilma")
     bmlToIpaaca.addListeners(self.mockFeedbackListener);
     ipaacaToBML.feedback("bmlfeedback");
     time.sleep(0.05)
     verify(self.mockFeedbackListener,times=0).feedback("bmlfeedback"); 
Esempio n. 15
0
 def test_whenSeedingWithPivotalStatus(self):
     pivotalStatus = "Started"
     mapObject = mock()
     status = TrackerItemStatus(pivotalStatus, apiObject=mapObject)
     status.jira()
     verify(mapObject).translateStatusTo('jira', pivotalStatus)
     self.assertEqual(status.pivotal(), pivotalStatus) 
 def test_noDeletionsWhenNoItems(self):
     tracker = self.makeValidTracker()
     trackerInstance = self.trackerInstance_
     when(trackerInstance).GetStories(any()).thenReturn([])
     tracker.deleteAllItems()
     verify(trackerInstance, never).DeleteStory(any())
     pass
Esempio n. 17
0
 def test_mode_exited(self):
     cli = self.makeCli()
     when(cli).compareReceivedAgainst(any(),any()).thenReturn(0)
     testMode = Mode(cli)
     testMode.exit()
     verify(cli).exitMode(testMode)
     verify(cli).send("exit")
 def test_doNotSyncIfItemIsLessUpToDate(self):
     toTracker, itemToSyncTo, itemToSyncFrom, syncCommentsFor = self.setupSync()
     when(itemToSyncTo).updatedAt().thenReturn(1)
     when(itemToSyncFrom).updatedAt().thenReturn(0)
     when(itemToSyncTo).canBeSyncedWith(itemToSyncFrom).thenReturn(True)
     syncCommentsFor(itemToSyncFrom, toTracker)
     verify(toTracker, never).update(itemToSyncTo)
Esempio n. 19
0
    def test_get_children_watcher(self):
        watcher = mock()
        z = pookeeper.allocate(self.hosts)

        z.create('/pookie', CREATOR_ALL_ACL, Persistent(), data=_random_data())
        z.get_children('/pookie', watcher=watcher)

        z.create('/pookie/bear', CREATOR_ALL_ACL, Persistent(), data=_random_data())
        z.get_children('/pookie', watcher=watcher)

        z.set_data('/pookie', _random_data())
        z.set_data('/pookie/bear', _random_data())

        # One is for when we do and the other is for when we don't chroot
        z.get_children('/pookie', watcher=watcher)
        z.get_children('/pookie/bear', watcher=watcher)

        z.delete('/pookie/bear')
        z.delete('/pookie')

        z.close()

        mockito.verify(watcher, times=2).children_changed('/pookie')
        mockito.verify(watcher).node_deleted('/pookie/bear')
        verifyNoMoreInteractions(watcher)
 def test_doNotAddCommentsWhenItemNotFound(self):
     toTracker = mock()
     item = mock()
     syncCommentsFor = TrackerSyncBy.syncingItem()
     when(toTracker).items(None).thenRaise(StopIteration)
     syncCommentsFor(item, toTracker)
     verify(toTracker, never).update(item) 
Esempio n. 21
0
def test_CanRetrieveOrganizationListFiltered():
    pertinoSdk, _, response = setupSdk()
    json = {"orgs": [{"name": "organization", "id": 1234}]}
    when(response).json().thenReturn(json)
    closure = mock()
    pertinoSdk.listOrgs(closure=closure.function)
    verify(closure).function(json["orgs"][0])
 def test_retryWhenTryingToGetStoriesAndException(self):
     tracker = self.makeValidTracker()
     trackerInstance = self.trackerInstance_
     when(trackerInstance).GetStories(any()).thenRaise(Exception("")).thenReturn([Story(),Story()])
     when(trackerInstance).GetComments(any()).thenReturn([])
     next(tracker.items())
     verify(trackerInstance, times=2).GetStories(any())
Esempio n. 23
0
 def testFeedbackCharacter(self):
     bmlToIpaaca = BMLRealizerToIpaacaAdapter("Fred")
     ipaacaToBML = IpaacaToBMLRealizerAdapter(self.mockRealizerPort, "Fred")
     bmlToIpaaca.addListeners(self.mockFeedbackListener)
     ipaacaToBML.feedback("bmlfeedback")
     time.sleep(0.05)
     verify(self.mockFeedbackListener).feedback("bmlfeedback")
 def test_noDeletionsWhenNoItems(self):
     tracker = self.makeValidTracker()
     trackerInstance = self.trackerInstance_
     when(trackerInstance).GetStories(any()).thenReturn([])
     tracker.deleteAllItems()
     verify(trackerInstance, never).DeleteStory(any())
     pass
 def test_canUpdateStatus(self):
     statusId = "Match"
     action = TestAction(5,statusId)
     jira, jiraInstance, itemId, trackerItem, status = self.setupStatus()
     when(status).jira().thenReturn(statusId)
     when(jiraInstance.service).getAvailableActions(any(), any()).thenReturn([action,])
     jira._ticketWithUpdatedStatusFrom(trackerItem)
     verify(jiraInstance.service).progressWorkflowAction(self.auth_, itemId, action.id, any())
 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_filterIsSentWhenSpecified(self):
     tracker = self.makeValidTracker()
     trackerInstance = self.trackerInstance_
     forFilter = "blah"
     when(trackerInstance).GetStories(any()).thenReturn([])
     when(trackerInstance).GetComments(any()).thenReturn([])
     self.assertRaises(StopIteration, next, tracker.items(forFilter))
     verify(trackerInstance).GetStories(forFilter)
 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 test_retryWhenTryingToGetStoriesAndException(self):
     tracker = self.makeValidTracker()
     trackerInstance = self.trackerInstance_
     when(trackerInstance).GetStories(any()).thenRaise(
         Exception("")).thenReturn([Story(), Story()])
     when(trackerInstance).GetComments(any()).thenReturn([])
     next(tracker.items())
     verify(trackerInstance, times=2).GetStories(any())
 def test_dontDeleteNotAddedItem(self):
     tracker = self.makeValidTracker()
     trackerInstance = self.trackerInstance_
     pivotalTrackerItem = mock()
     when(pivotalTrackerItem).Id().thenReturn(None)
     tracker.delete(pivotalTrackerItem)
     verify(trackerInstance, never).DeleteStory(any())
     pass
 def test_noDeletionsWhenNoItems(self):
     jira = JiraTracker()
     jiraInstance = self.getMockFor(jira)
     jira.selectProject(["",""])
     self.setMocksForGettingItems(jiraInstance)
     jira.deleteAllItems()
     verify(jiraInstance.service, never).deleteIssue(any(), any())
     pass
Esempio n. 32
0
def test_CanRetrieveOrganizationListUnfiltered():
    pertinoSdk, requests, response = setupSdk()
    json = {"orgs": [{"name": "organization", "id": 1234}]}
    when(response).json().thenReturn(json)
    assert pertinoSdk.listOrgs() == json["orgs"]
    verify(requests).get(
        'http://api.labs.pertino.com:5000/api/v0-alpha/orgs?user_key=993e79924d5b6346fe62a5cf62183bc5',
        auth=('a', 'b'))
 def test_doNotSyncIfItemIsLessUpToDate(self):
     toTracker, itemToSyncTo, itemToSyncFrom, syncCommentsFor = self.setupSync(
     )
     when(itemToSyncTo).updatedAt().thenReturn(1)
     when(itemToSyncFrom).updatedAt().thenReturn(0)
     when(itemToSyncTo).canBeSyncedWith(itemToSyncFrom).thenReturn(True)
     syncCommentsFor(itemToSyncFrom, toTracker)
     verify(toTracker, never).update(itemToSyncTo)
 def test_dontDeleteNotAddedItem(self):
     tracker = self.makeValidTracker()
     trackerInstance = self.trackerInstance_
     pivotalTrackerItem = mock()
     when(pivotalTrackerItem).Id().thenReturn(None)
     tracker.delete(pivotalTrackerItem)
     verify(trackerInstance, never).DeleteStory(any())
     pass
 def test_filterIsSentWhenSpecified(self):
     tracker = self.makeValidTracker()
     trackerInstance = self.trackerInstance_
     forFilter = "blah"
     when(trackerInstance).GetStories(any()).thenReturn([])
     when(trackerInstance).GetComments(any()).thenReturn([])
     self.assertRaises(StopIteration, next, tracker.items(forFilter)) 
     verify(trackerInstance).GetStories(forFilter)
 def test_whenDoingPivotalOperationAuthenticationIsIncluded(self):
     tracker = self.makeTestTracker()
     pivotalApiObject = self.apiObject_
     password = "******"
     authentication = mock()
     when(pivotalApiObject).HostedTrackerAuth(any(),any()).thenReturn(authentication)
     tracker.withCredential(password)
     verify(pivotalApiObject).Tracker(any(), authentication)
 def test_authSentWhenGettingBugs(self):
     jira = JiraTracker()
     jiraInstance = self.getMockFor(jira)
     self.setMocksForGettingItems(jiraInstance)
     itemIterator = jira._getItems()
     self.assertRaises(StopIteration, next, itemIterator)
     verify(jiraInstance.service).getIssuesFromJqlSearch(self.auth_, any(), any())
     pass
 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 test_handleWhenNoCommentsAreReturned(self):
     jira = JiraTracker()
     jiraInstance = self.getMockFor(jira)
     ticket = mock()
     key = "12345"
     when(ticket).Id().thenReturn(key)
     when(jiraInstance.service).getComments(any(),any()).thenReturn(None)
     jira.addCommentsTo(ticket)
     verify(jiraInstance.service,times=0).addComment(any(), any(), any())
 def test_trackerCanDeleteItem(self):
     tracker = self.makeValidTracker()
     trackerInstance = self.trackerInstance_
     pivotalTrackerItem = mock()
     storyId = 1234
     when(pivotalTrackerItem).Id().thenReturn(storyId)
     tracker.delete(pivotalTrackerItem)
     verify(trackerInstance).DeleteStory(storyId)
     pass
Esempio n. 41
0
 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 test_filterCombinedWithProjectJqlSentWhenSpecified(self):
     jira = JiraTracker()
     jiraInstance = self.getMockFor(jira)
     forFilter = "blah"
     jql = "1234" 
     jira.selectProject(["", jql])
     self.setMocksForGettingItems(jiraInstance)
     self.assertRaises(StopIteration, next, jira._getItems(forFilter)) 
     verify(jiraInstance.service).getIssuesFromJqlSearch(any(),jql + " and " + forFilter,any()) 
Esempio n. 43
0
 def test_when_the_queue_is_empty_it_waits_until_it_is_refilled(self):
     try:
         self.repeat(self.myScheduler.setPcbToCPU, 3)
         self.myScheduler.setPcbToCPU()
         verify(self.semaphore).wait()
     except Exception:
         pass
     else:
         self.fail("unsexpected exception")
Esempio n. 44
0
    def test_writes_single_value_all_args(self):
        values = [1, 2]
        when2(wm.write_query, "foo", ANY).thenReturn(True)

        wm.write_multiple_values("foo",
                                 values,
                                 measurement=["bar", "bar"],
                                 value_name=["my_val", "my_val"])
        verify(wm, 2).write_query("foo", any)
 def test_trackerCanDeleteItem(self):
     tracker = self.makeValidTracker()
     trackerInstance = self.trackerInstance_
     pivotalTrackerItem = mock()
     storyId = 1234
     when(pivotalTrackerItem).Id().thenReturn(storyId)
     tracker.delete(pivotalTrackerItem)
     verify(trackerInstance).DeleteStory(storyId)
     pass
def test_excutingWithPasswordUsesPassword():
    json = '{\
        "hostname" : "<ip>",\
        "username" : "root",\
        "password" : "password"\
    }'
    cliProcessingJson, UserObject, CliObject, cli, _ = setupCliProcessingJson(json, "password")
    cliProcessingJson.execute(UserObject.called, CliObject.called)
    verify(cli, atleast=1).loginSsh()
 def test_whenDoingPivotalOperationAuthenticationIsIncluded(self):
     tracker = self.makeTestTracker()
     pivotalApiObject = self.apiObject_
     password = "******"
     authentication = mock()
     when(pivotalApiObject).HostedTrackerAuth(
         any(), any()).thenReturn(authentication)
     tracker.withCredential(password)
     verify(pivotalApiObject).Tracker(any(), authentication)
 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 test_willUpdateStatusBecauseItIsSeperateStepForJira(self):
     jira, jiraInstance, itemId, trackerItem, status = self.setupStatus()
     statusId = "Match"
     action = TestAction(5,statusId)
     when(status).jira().thenReturn(statusId)
     when(trackerItem).piecesToUpdate().thenReturn("status")
     when(trackerItem).comments(any()).thenReturn([])
     when(jiraInstance.service).getAvailableActions(any(), any()).thenReturn([action,])
     jira.update(trackerItem)
     verify(jiraInstance.service).progressWorkflowAction(any(), any(), any(), any())
 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_trackerCanDeleteItem(self):
     jira = JiraTracker()
     jiraInstance = self.getMockFor(jira)
     jira.selectProject([])
     jiraTrackerItem = mock()
     itemId = 1234
     when(jiraTrackerItem).Id().thenReturn(itemId)
     jira.delete(jiraTrackerItem)
     verify(jiraInstance.service).deleteIssue(any(), itemId)
     pass