Skip to content

Commit

Permalink
Add relationship rule set endpoints (#35)
Browse files Browse the repository at this point in the history
Update logic for returning data in __get_all
  • Loading branch information
sspears-jama authored May 13, 2021
1 parent 9ffb670 commit d03cb91
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ compatibility)
- `PUT` an item
- `PUT` item lock

##### Relationship Rule Sets
- `GET` all relationship rule sets
- `GET` a specific relationship rule set by ID
- `GET` all projects for a specific relationship rule set by ID

##### Relationship Types
- `GET` all relationship types
- `GET` a specific relationship type by ID
Expand Down
45 changes: 39 additions & 6 deletions py_jama_rest_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,40 @@ def get_abstract_items_from_doc_key(self, doc_key_list, allowed_results_per_page
abstract_items = self.__get_all(resource_path, params=params, allowed_results_per_page=allowed_results_per_page)
return abstract_items

def get_relationship_rule_sets(self):
"""
This method will return all relationship rule sets across all projects of the Jama Connect instance.
Returns: An array of dictionary objects representing a rule set and its associated rules
"""
resource_path = 'relationshiprulesets/'
rule_sets = self.__get_all(resource_path)
return rule_sets

def get_relationship_rule_set(self, id):
"""
This method will return the relationship rule sets by id.
Returns: A dictionary object representing a rule set and its associated rules
"""
resource_path = 'relationshiprulesets/' + str(id)
response = self.__core.get(resource_path)
JamaClient.__handle_response_status(response)
return response.json()['data']

def get_relationship_rule_set_projects(self, id):
"""
This method will return the projects that have a given relationship rule set defined.
Returns: An array of the dictionary objects representing the projects with a given rule set assigned
"""
resource_path = 'relationshiprulesets/' + str(id) + '/projects'
projects = self.__get_all(resource_path)
return projects

def get_relationship_types(self, allowed_results_per_page=__allowed_results_per_page):
"""
This method will return all relationship types of the across all projects of the Jama Connect instance.
Expand Down Expand Up @@ -1357,19 +1391,18 @@ def __get_all(self, resource, params=None, allowed_results_per_page=__allowed_re
raise ValueError("Allowed results per page must be between 1 and 50")

start_index = 0
result_count = -1
allowed_results_per_page = 20
total_results = float("inf")

data = []

while result_count != 0:
page_response = self.__get_page(resource, start_index, params=params,
allowed_results_per_page=allowed_results_per_page, **kwargs)
while len(data) < total_results:
page_response = self.__get_page(resource, start_index, params=params, **kwargs)
page_json = page_response.json()

page_info = page_json['meta']['pageInfo']
start_index = page_info['startIndex'] + allowed_results_per_page
result_count = page_info['resultCount']

total_results = page_info.get('totalResults')
page_data = page_json.get('data')
data.extend(page_data)

Expand Down
21 changes: 21 additions & 0 deletions test/test_jamaClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,24 @@ def test_get_abstract_versioned_item(self):
self.assertEqual(item.get("version"), version_num)
self.assertEqual(item["fields"]["name"], item_name)

def test_get_relationship_rule_sets(self):
rule_set_name = "IIBA BABOK v3"
rule_sets = self.jama_client.get_relationship_rule_sets()
self.assertEqual(rule_sets[0].get('name'), rule_set_name)
self.assertEqual(len(rule_sets), 10)

def test_get_relationship_rule_set(self):
rule_set_id = 1
rule_set_name = "IIBA BABOK v3"
rule_set = self.jama_client.get_relationship_rule_set(rule_set_id)
self.assertEqual(rule_set.get('name'), rule_set_name)
self.assertEqual(len(rule_set), 5)

def test_get_relationship_rule_set_projects(self):
rule_set_id = 1
project1 = "IIBA BABOK Sample Set"
project2 = "IIBA BABOK Framework"
projects = self.jama_client.get_relationship_rule_set_projects(rule_set_id)
self.assertEqual(projects[0].get('name'), project1)
self.assertEqual(projects[1].get('name'), project2)
self.assertEqual(len(projects), 2)

0 comments on commit d03cb91

Please sign in to comment.