def test_query_target_value_with_and():
    """
        Query for a Project.Name = 'Operations and Support Group'
    """
    criteria = 'Project.Name = "Operations and Support Group"'
    result = RallyQueryFormatter.parenGroups(criteria)
    assert result == 'Project.Name = "Operations and Support Group"'.replace(' ', '%20')

    criteria = ['State != Open', 'Name !contains "Henry Hudson and Company"']
    result = RallyQueryFormatter.parenGroups(criteria)
    assert result.replace('%21%3D', '!=') == '(State != Open) AND (Name !contains "Henry Hudson and Company")'.replace(' ', '%20')
def test_query_target_value_with_and():
    """
        Query for a Project.Name = 'Operations and Support Group'
    """
    criteria = 'Project.Name = "Operations and Support Group"'
    result = RallyQueryFormatter.parenGroups(criteria)
    assert result == 'Project.Name = "Operations and Support Group"'.replace(
        ' ', '%20')

    criteria = ['State != Open', 'Name !contains "Henry Hudson and Company"']
    result = RallyQueryFormatter.parenGroups(criteria)
    assert result.replace(
        '%21%3D', '!='
    ) == '(State != Open) AND (Name !contains "Henry Hudson and Company")'.replace(
        ' ', '%20')
def test_query_target_value_with_ampersand():
    """
        Query for a Project.Name = 'R&D'
    """
    criteria = ['Project.Name = R&D']
    result = RallyQueryFormatter.parenGroups(criteria)
    assert unquote(result) == 'Project.Name = R&D'.replace('&', '%26')

    criteria = ['Project.Name = "R&D"']
    result = RallyQueryFormatter.parenGroups(criteria)
    assert unquote(result) == 'Project.Name = "R&D"'.replace('&', '%26')

    criteria = ['Project.Name contains "R&D"']
    result = RallyQueryFormatter.parenGroups(criteria)
    assert unquote(result) == 'Project.Name contains "R&D"'.replace('&', '%26')

    criteria = 'Railhead.Company.Name != "Atchison Topeka & Santa Fe & Cunard Lines"'
    result = RallyQueryFormatter.parenGroups(criteria)
    assert unquote(result) == criteria.replace('&', '%26')
def test_query_target_value_with_ampersand():
    """
        Query for a Project.Name = 'R&D'
    """
    criteria = ['Project.Name = R&D']
    result = RallyQueryFormatter.parenGroups(criteria)
    assert urllib.unquote(result) == 'Project.Name = R&D'.replace('&', '%26')

    criteria = ['Project.Name = "R&D"']
    result = RallyQueryFormatter.parenGroups(criteria)
    assert urllib.unquote(result) == 'Project.Name = "R&D"'.replace('&', '%26')

    criteria = ['Project.Name contains "R&D"']
    result = RallyQueryFormatter.parenGroups(criteria)
    assert urllib.unquote(result) == 'Project.Name contains "R&D"'.replace('&', '%26')

    criteria = 'Railhead.Company.Name != "Atchison Topeka & Santa Fe & Cunard Lines"'
    result = RallyQueryFormatter.parenGroups(criteria)
    assert urllib.unquote(result) == criteria.replace('&', '%26')
def test_query_target_value_with_ampersand():
    """
        Query for a Project.Name = 'R&D'

        Note: This test must be last as there is some weird interplay going on when this is higher up
              in the file.  3 Tests fail having nothing to do with ampersands in the query criteria
              when this test appears before them.
    """
    criteria = ['Project.Name = R&D']
    result = RallyQueryFormatter.parenGroups(criteria)
    #assert unquote(result) == 'Project.Name = R&D'.replace('&', '%26')
    assert unquote(result) == 'Project.Name = R&D'

    criteria = ['Project.Name = "R&D"']
    result = RallyQueryFormatter.parenGroups(criteria)
    #assert unquote(result) == 'Project.Name = "R&D"'.replace('&', '%26')
    assert unquote(result) == 'Project.Name = "R&D"'

    criteria = ['Project.Name contains "R&D"']
    result = RallyQueryFormatter.parenGroups(criteria)
    #assert unquote(result) == 'Project.Name contains "R&D"'.replace('&', '%26')
    assert unquote(result) == 'Project.Name contains "R&D"'

    criteria = 'Railhead.Company.Name != "Atchison Topeka & Santa Fe & Cunard Lines"'
    result = RallyQueryFormatter.parenGroups(criteria)
    #assert unquote(result) == criteria.replace('&', '%26')
    assert unquote(result) == criteria

    APIKEY = "_useYourRallyKey"
    RALLY_100_APIKEY = "_lsMzURZTRyBoD3bwnpn5kUZvDQkRIoEeGkq7QNkg"
    target_workspace = 'Rally'
    target_project = 'R&D'
    rally = Rally(server='rally1.rallydev.com',
                  apikey=RALLY_100_APIKEY,
                  workspace=target_workspace,
                  project=target_project)
    pifs = rally.get('Feature', fetch='Name,FormattedID')
    assert pifs.resultCount == 26  # as of 02/05/2021 this was correct, total of 26 Features for R&D
    # The following does not work...
    pifs = rally.get('Feature',
                     fetch='Name,FormattedID',
                     query=['Project.Name = "R&D"', 'Name contains "On-Prem"'])
    assert pifs.resultCount == 7  # as of 02/05/2021 this was correct, 7 Features had "On-Prem" in the Name