How to use pyral - 10 common examples

To help you get started, we’ve selected a few pyral examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RallyTools / RallyRestToolkitForPython / pyral / context.py View on Github external
"""
            Given a project_name in BaseProject // NextLevelProject // TargetProjectName form,
            determine the existence/accessiblity of each successive path from the BaseProject
            on towards the full path ending with TargetProjectName.
            If found return a pyral entity for the TargetProject which will include the ObjectID (oid)
            after setting an attribute for FullProjectPath with the value of project_name.
        """
        proj_path_elements = project_name.split(PROJECT_PATH_ELEMENT_SEPARATOR)
        base_path_element = proj_path_elements[0]
        result = self.agent.get('Project', fetch="Name,ObjectID,Parent", 
                                query='Name = "%s"' % base_path_element,
                                workspace=self._currentWorkspace, project=base_path_element,
                                projectScopeDown=False)
        if not result or (result.errors or result.resultCount != 1):
            problem = "No such accessible base Project found in the Workspace '%s'" % project_name
            raise RallyRESTAPIError(problem)
        base_project = result.next()
        parent = base_project
        project_path = [base_project.Name]

        for proj_path_element in proj_path_elements[1:]:
            project_path.append(proj_path_element)
            criteria = ['Name = "%s"' % proj_path_element , 'Parent = %s' % parent._ref]
            result = self.agent.get('Project', fetch="Name,ObjectID,Parent", query=criteria, workspace=self._currentWorkspace, project=parent.ref)
            if not result or result.errors or result.resultCount != 1:
                problem = "No such accessible Project found: '%s'" % PROJECT_PATH_ELEMENT_SEPARATOR.join(project_path)
                raise RallyRESTAPIError(problem)
            path_el = result.next()
            parent = path_el
        if PROJECT_PATH_ELEMENT_SEPARATOR.join(project_path) != project_name:
            raise RallyRESTAPIError()
        return path_el
github RallyTools / RallyRestToolkitForPython / pyral / context.py View on Github external
problem = "No accessible Projects found in the Workspace '%s'" % self._defaultWorkspace
            raise RallyRESTAPIError(problem)

        try:
            projects = [proj for proj in result]
        except:
            problem = "Unable to obtain Project Name values for projects in the '%s' Workspace"
            raise RallyRESTAPIError(problem % self._defaultWorkspace)

        # does the project_name contain a ' // ' path element separator token?
        # if so, then we have to sidebar process this
        if project_name and PROJECT_PATH_ELEMENT_SEPARATOR in project_name:
            target_project = self._findMultiElementPathToProject(project_name)
            if not target_project:
                problem = "No such accessible multi-element-path Project: %s  found in the Workspace '%s'"
                raise RallyRESTAPIError(problem % (project_name, self._currentWorkspace))
            #  have to set:
            #     self._defaultProject, self._currentProject
            #     self._workspace_ref, self._project_ref
            #     self.defaultContext, self.operatingContext

        else:
            match_for_default_project = [project for project in projects if project.Name == self._defaultProject]
            match_for_named_project   = [project for project in projects if project.Name == project_name]

            if project_name:
                if not match_for_named_project:
                    problem = "The current Workspace '%s' does not contain an accessible Project with the name of '%s'"
                    raise RallyRESTAPIError(problem % (self._currentWorkspace, project_name))
                else:
                    project = match_for_named_project[0]
                    proj_ref = project._ref
github RallyTools / RallyRestToolkitForPython / pyral / context.py View on Github external
return self.context, augments

            project = kwargs['project']
            wks = workspace or self._currentWorkspace or self._defaultWorkspace
            if project in self._projects[wks]:
                prj_ref = self._project_ref[wks][project]
            elif PROJECT_PATH_ELEMENT_SEPARATOR in project: # ' // '
                proj_path_leaf = self._findMultiElementPathToProject(project)
                prj_ref = proj_path_leaf.ref
                project = proj_path_leaf.Name
            elif re.search('project/\d+$', project):
                prj_ref = project
            else:
                problem = 'Project specified: "%s" (in workspace: "%s") not accessible with current credentials' % \
                           (project, workspace)
                raise RallyRESTAPIError(problem)

            augments.append("project=%s" % prj_ref)
            self.context.project = project

        if 'projectScopeUp' in kwargs:
            projectScopeUp = kwargs['projectScopeUp']
            if   projectScopeUp in [1, True, 'true', 'True']:
                augments.append("projectScopeUp=true")
            elif projectScopeUp in [0, False, 'false', 'False']:
                augments.append("projectScopeUp=false")
            else:
                augments.append("projectScopeUp=false")
        else:
            augments.append("projectScopeUp=false")

        if 'projectScopeDown' in kwargs:
github RallyTools / RallyRestToolkitForPython / pyral / context.py View on Github external
# the workspaces and projects this user has access to (and their defaults)
        self._subs_name        = ""
        self._subs_workspaces  = []  # a list of Workspace "shell" objects
        self._workspaces       = []
        self._workspace_ref    = {}
        self._workspace_inflated = {}
        self._defaultWorkspace = None
        self._currentWorkspace = None
        self._inflated         = False

        self._projects         = {}  # key by workspace name with list of projects per workspace
        self._project_ref      = {}  # key by workspace name with dict of project_name: project_ref
        self._project_path     = {}  # keyed by project ref, value is "base // intermed // leaf", only for "pathed" projects
        self._defaultProject   = None
        self._currentProject   = None
        self.context           = RallyContext(server, user, password, self.agent.serviceURL())
        self.defaultContext    = self.context # to be updated on check call 
        self.operatingContext  = self.context # to be updated on check call
github RallyTools / RallyRestToolkitForPython / test / test_big_query.py View on Github external
def test_cargo_truck_init():
    cgo = CargoTruck(['a', 'b'], 2)
    assert len(cgo.orders) == 2
    assert cgo.orders[0] == 'a'
    assert cgo.num_loaders == 2
    print("at the end of the rope")
github RallyTools / RallyRestToolkitForPython / test / test_query.py View on Github external
def test_three_condition_query_in_list():
    """
        Using a known valid Rally server and known valid access credentials,
        issue a query with three qualifying conditions against a Rally entity
        (Defect) known to exist for which the qualifying criterion should return 
        one or more Defects. The qualifying criterion is a list that contains
        three condition strings, each condition string does _not_ have any 
        surrounding paren chars.
    """
    rally = Rally(server=AGICEN, user=AGICEN_USER, password=AGICEN_PSWD)
    #qualifiers = ["State = Submitted", "FormattedID != DE100", "Owner.UserName != horsefeathers"]
    qualifiers = ["State = Submitted", "FormattedID != DE100", "Severity != UltraMegaHurt"]
    response = rally.get('Defect', fetch=True, query=qualifiers, limit=10)
    assert response.resultCount > 0
github RallyTools / RallyRestToolkitForPython / test / test_workspaces.py View on Github external
def test_default_context():  
    """
        Using a known valid Rally server and known valid access credentials,
        obtain a Rally instance and confirm that the default workspace
        and project are set to DEFAULT_WORKSPACE and DEFAULT_PROJECT and
        that the current workspace and project are indeed the DEFAULT_WORKSPACE
        and DEFAULT_PROJECT values.
        Furthermore the construction of a GET related URL will contain
        the correct workspace and project specifications in the QUERY_STRING.
    """
    rally = Rally(server=AGICEN, user=AGICEN_USER, password=AGICEN_PSWD, server_ping=False)
    context1 = rally.contextHelper.currentContext()
    workspace = rally.getWorkspace()
    project   = rally.getProject()
    context2 = rally.contextHelper.currentContext()
    assert context1 == context2
    assert context1.workspace == DEFAULT_WORKSPACE
    assert workspace.Name     == DEFAULT_WORKSPACE
    assert context1.project   == DEFAULT_PROJECT
    assert project.Name       == DEFAULT_PROJECT
    url = makeResourceUrl(rally, 'Defect')
    #print(url)
    expected_workspace_clause = 'workspace=workspace/%s' % str(workspace.oid)
    assert expected_workspace_clause in url
    expected_project_clause = 'project=project/%s' % str(project.oid)
    assert expected_project_clause   in url
github RallyTools / RallyRestToolkitForPython / test / test_context.py View on Github external
def test_set_default_workspace_non_default_project_context():
    rally = Rally(server=AGICEN, user=AGICEN_USER, password=AGICEN_PSWD,
                  workspace=DEFAULT_WORKSPACE,
                  project=NON_DEFAULT_PROJECT)
    workspace = rally.getWorkspace()
    assert workspace.Name == DEFAULT_WORKSPACE
    project = rally.getProject()
    assert project.Name == NON_DEFAULT_PROJECT
    url = makeResourceUrl(rally, 'Defect')
    #print(url)
    expected_workspace_clause = 'workspace=workspace/%s' % str(workspace.oid)
    assert expected_workspace_clause in url
    expected_project_clause = 'project=project/%s' % str(project.oid)
    assert expected_project_clause   in url
github RallyTools / RallyRestToolkitForPython / test / test_allowed_values.py View on Github external
def test_getAllowedValues_query():
    """
        Using a known valid Rally server and known valid access credentials,
        request the allowed value information for the State field of the Defect entity and
        request the allowed value information for the PrimaryColor field of the Defect entity.
    """
    rally = Rally(server=AGICEN, user=AGICEN_USER, password=AGICEN_PSWD)
    avs = rally.getAllowedValues('Defect', 'State')
    assert len(avs) > 0
    assert len(avs) >= 4
    assert 'Open'   in avs
    assert 'Closed' in avs

    avs = rally.getAllowedValues('Defect', 'PrimaryColor')
    assert len(avs) > 0
    assert len(avs) >= 6 and len(avs) <= 8
    assert 'Red'     in avs
    assert 'Magenta' in avs
github RallyTools / RallyRestToolkitForPython / test / test_conn.py View on Github external
assert excinfo.value.__class__.__name__ == 'RallyRESTAPIError'
    assert expectedErrMsg in actualErrVerbiage
    #print "detected invalid user, blank password condition"
    time.sleep(1)
    
    with py.test.raises(RallyRESTAPIError) as excinfo:
        rally = Rally(server=AGICEN, user="guest", password="doofus")
        response = rally.get('Project', fetch=False, limit=10)
    actualErrVerbiage = excinfo.value.args[0]  # becuz Python2.6 deprecates message :-(
    assert excinfo.value.__class__.__name__ == 'RallyRESTAPIError'
    assert expectedErrMsg in actualErrVerbiage
    #print "detected invalid user, invalid password condition"
    time.sleep(1)

    with py.test.raises(RallyRESTAPIError) as excinfo:
        rally = Rally(server=AGICEN, user="guest")
        response = rally.get('Project', fetch=False, limit=10)
    actualErrVerbiage = excinfo.value.args[0]  # becuz Python2.6 deprecates message :-(
    assert excinfo.value.__class__.__name__ == 'RallyRESTAPIError'
    assert expectedErrMsg in actualErrVerbiage
    #print "detected invalid user, missing password condition"