def test_call_without_dry_run(self, get):
        """make_query_repositories_request should call requests.get."""
        buildapi_client.make_query_repositories_request(auth=None, dry_run=False)

        # We expect that make_query_repositories_request will call requests.get
        # once with the following arguments
        get.assert_called_once_with(
            "%s/branches?format=json" % HOST_ROOT,
            auth=None)
예제 #2
0
def query_repositories(clobber=False):
    """
    Return dictionary with information about the various repositories.

    The data about a repository looks like this:

    .. code-block:: python

        "ash": {
            "repo": "https://hg.mozilla.org/projects/ash",
            "graph_branches": ["Ash"],
            "repo_type": "hg"
        }

    Raises an AuthenticationError if the user credentials are invalid.
    """
    global REPOSITORIES

    if clobber:
        REPOSITORIES = {}
        if os.path.exists(REPOSITORIES_FILE):
            os.remove(REPOSITORIES_FILE)

    if REPOSITORIES:
        return REPOSITORIES

    if os.path.exists(REPOSITORIES_FILE):
        LOG.debug("Loading %s" % REPOSITORIES_FILE)
        fd = open(REPOSITORIES_FILE)
        REPOSITORIES = json.load(fd)
    else:
        try:
            REPOSITORIES = make_query_repositories_request(
                auth=get_credentials(), dry_run=False)
        except BuildapiAuthError:
            remove_credentials()
            raise AuthenticationError(
                "Your credentials were invalid. Please try again.")

        with open(REPOSITORIES_FILE, "wb") as fd:
            json.dump(REPOSITORIES, fd)

    return REPOSITORIES
예제 #3
0
def query_repositories(clobber=False):
    """
    Return dictionary with information about the various repositories.

    The data about a repository looks like this:

    .. code-block:: python

        "ash": {
            "repo": "https://hg.mozilla.org/projects/ash",
            "graph_branches": ["Ash"],
            "repo_type": "hg"
        }

    Raises an AuthenticationError if the user credentials are invalid.
    """
    global REPOSITORIES

    if clobber:
        REPOSITORIES = {}
        if os.path.exists(REPOSITORIES_FILE):
            os.remove(REPOSITORIES_FILE)

    if REPOSITORIES:
        return REPOSITORIES

    if os.path.exists(REPOSITORIES_FILE):
        LOG.debug("Loading %s" % REPOSITORIES_FILE)
        fd = open(REPOSITORIES_FILE)
        REPOSITORIES = json.load(fd)
    else:
        try:
            REPOSITORIES = make_query_repositories_request(auth=get_credentials(), dry_run=False)
        except BuildapiAuthError:
            remove_credentials()
            raise AuthenticationError("Your credentials were invalid. Please try again.")

        with open(REPOSITORIES_FILE, "wb") as fd:
            json.dump(REPOSITORIES, fd)

    return REPOSITORIES
 def test_call_with_dry_run(self, get):
     """make_cancel_request should return None when dry_run is True."""
     self.assertEquals(
         buildapi_client.make_query_repositories_request(auth=None, dry_run=True), None)
     # make_query_repositories_request should not call requests.get when dry_run is True
     assert get.call_count == 0