Beispiel #1
0
    def search_issues() -> ResultList:
        result = ResultList()

        for x in range(0, 10, 1):
            temp_issue = Issue(None, None)
            temp_issue.key = 'Test-{}'.format(x)
            temp_issue.updated = '2014-01-01 00:00:01'
            result.append(temp_issue)

        return result
Beispiel #2
0
    def boards(self, startAt=0, maxResults=50, type=None, name=None, boardKeyOrId=None):
        """Get a list of board resources.

        :param startAt: The starting index of the returned boards. Base index: 0.
        :param maxResults: The maximum number of boards to return per page. Default: 50
        :param type: Filters results to boards of the specified type. Valid values: scrum, kanban.
        :param name: Filters results to boards that match or partially match the specified name.
        :rtype: ResultList[Board]

        When old GreenHopper private API is used, paging is not enabled and all parameters are ignored.
        """
        params = {}
        if type:
            params['type'] = type
        if name:
            params['name'] = name
        if boardKeyOrId:
            params['projectKeyOrId'] = boardKeyOrId

        if self._options['agile_rest_path'] == GreenHopperResource.GREENHOPPER_REST_PATH:
            # Old, private API did not support pagination, all records were present in response,
            #   and no parameters were supported.
            if startAt or maxResults or params:
                warnings.warn('Old private GreenHopper API is used, all parameters will be ignored.', Warning)

            r_json = self._get_json('rapidviews/list', base=self.AGILE_BASE_URL)
            boards = [Board(self._options, self._session, raw_boards_json) for raw_boards_json in r_json['views']]
            return ResultList(boards, 0, len(boards), len(boards), True)
        else:
            return self._fetch_pages(Board, 'values', 'board', startAt, maxResults, params, base=self.AGILE_BASE_URL)
    def getIssuesForUser(self, user):

        userDetails = UserDetails.UserDetails(self.jira)
        nameKey = userDetails.getNames(user=user)
        names = nameKey[0]
        key = nameKey[1]

        issues = []
        issueCount = 0
        issueTotal = 1

        while len(issues) < issueTotal:
            issueList = self.jira.search_issues(
                'worklogAuthor = ' + key + ' and worklogDate >= "' +
                str(self.workStartDate) + '" and worklogDate <= "' +
                str(self.workEndDate) + '"',
                fields="worklog,project",
                expand="worklog",
                startAt=str(len(issues)),
                maxResults=50)

            if len(issues) == 0:
                issues = issueList
            else:
                issues.extend(issueList)

            issueTotal = issueList.total

        issues = ResultList(issues, 0, len(issues), len(issues), True)

        return user, issues
    def test_update(self, jira_board_provider, jira_test_issues):
        """Tests the update of the jira packages"""

        jira_board_provider._jira = Mock()
        jira_board_provider.is_loaded = True
        jira_issue = [jira_test_issues]
        result_list = ResultList(jira_issue, _total=len(jira_issue))
        jira_board_provider._jira.search_issues.return_value = result_list
        jira_board_provider.load()

        packages = copy.deepcopy(jira_board_provider.get())

        # after loading our testing repo, we should have more than 0 packages
        assert len(packages) != 0

        test_key = list(packages.keys())[0]
        p = packages.get(test_key)  # type: Package
        p.catalog = None
        jira_board_provider.update(p)

        for key, package in jira_board_provider.get().items():
            # after changing the value of a not ignored package field the update
            # should be propagated and be represented in the new dictionary we
            # get from our munki provider
            assert is_exact_match(packages.get(key), package, ["state"])
Beispiel #5
0
 def accounts(self, skip_archived: bool = True) -> ResultList:
     """Retrieve accounts from the Tempo plugin."""
     r_json = self._get_json(f'account?skipArchived={skip_archived}',
                             base=self.TEMPO_ACCOUNTS_URL)
     accounts = [
         Account(self._options, self._session, raw_accounts_json)
         for raw_accounts_json in r_json
     ]
     return ResultList(accounts, 0, len(accounts), len(accounts), True)
    def test_load(self, jira_board_provider, jira_test_issues):
        """Tests if the loading of jira packages is working."""
        jira_board_provider._jira = Mock()
        jira_board_provider.is_loaded = True
        jira_issue = [jira_test_issues]
        result_list = ResultList(jira_issue, _total=len(jira_issue))
        jira_board_provider._jira.search_issues.return_value = result_list
        jira_board_provider.load()

        assert len(jira_board_provider.get()) != 0
Beispiel #7
0
 def quickfilters(self, board_id: int) -> ResultList:
     """Retrieve quickfilters defined for the board with `board_id`."""
     r_json = self._get_json(
         f'gadgets/rapidview/pool/quickfilters/{board_id}',
         base=self.GREENHOPPER_BASE_URL)
     filters = [
         QuickFilter(self._options, self._session, raw_quickfilters_json)
         for raw_quickfilters_json in r_json
     ]
     return ResultList(filters, 0, len(filters), len(filters), True)
Beispiel #8
0
def set_up_promoter(jira_board_provider, munki_repo_provider,
                    jira_test_issues):
    jira_board_provider._jira = Mock()
    jira_board_provider.is_loaded = True
    jira_issue = [jira_test_issues]
    result_list = ResultList(jira_issue, _total=len(jira_issue))
    jira_board_provider._jira.search_issues.return_value = result_list
    jira_board_provider.load()

    munki_repo_provider.load()
    munki_repo_provider._packages_dict = {
        # Load only munki package which equals the loaded jira issue
        k: v
        for k, v in munki_repo_provider.get().items() if "EN60.8.0" in k
    }

    return Promoter(munki_repo_provider.get(), jira_board_provider.get())
    def test_update_jira_from_repo(self, munki_repo_provider,
                                   jira_board_provider):
        """Tests update of jira from munki"""
        munki_repo_provider.load()
        munki_packages = copy.deepcopy(munki_repo_provider.get())

        jira_board_provider._jira = Mock()
        jira_board_provider.is_loaded = True
        jira_issue = []
        result_list = ResultList(jira_issue, _total=len(jira_issue))
        jira_board_provider._jira.search_issues.return_value = result_list
        jira_board_provider.load()

        assert len(munki_repo_provider.get()) != 0
        assert len(jira_board_provider.get()) == 0

        jira_board_provider.update_jira_from_repo(munki_packages)

        assert len(jira_board_provider.get()) != 0
Beispiel #10
0
    def test_update_new_package(self, jira_board_provider, jira_test_issues,
                                random_package):
        """Test the update if a new package is inserted"""
        jira_board_provider._jira = Mock()
        jira_board_provider.is_loaded = True
        jira_issue = [jira_test_issues]
        result_list = ResultList(jira_issue, _total=len(jira_issue))
        jira_board_provider._jira.search_issues.return_value = result_list
        jira_board_provider.load()

        jira_packages = copy.deepcopy(jira_board_provider.get())

        # because we want to simulate a new package it can not have a jira id
        # already
        random_package.jira_id = None
        jira_board_provider.update(random_package)

        jira_package = jira_board_provider._get(random_package.key)

        assert (random_package.key in jira_board_provider.get()
                and random_package.key not in jira_packages)
        assert is_exact_match(random_package, jira_package, ["state"])
        assert jira_package.state == PackageState.NEW
Beispiel #11
0
 def teams(self, startAt=0, maxResults=50, type=None, name=None) -> ResultList:
     r_json = self._get_json('team', base=self.AGILE_BASE_URL)
     teams = [Team(self._options, self._session, raw_teams_json) for raw_teams_json in r_json]
     return ResultList(teams, 0, len(teams), len(teams), True)