Esempio n. 1
0
 def test_get_group_children_bad_target(self):
     """ Negative test - random target group """
     response = groups.get_group_children(
         environment.ATHERA_API_TEST_BASE_URL,
         environment.ATHERA_API_TEST_GROUP_ID, self.token,
         str(uuid.uuid4()))
     self.assertEqual(response.status_code, codes.not_found)
Esempio n. 2
0
    def get_leaf_group(self, parent_id):
        """
        Walk the context tree from the parent group, until a group is selected with no descendents.
        """
        children_response = groups.get_group_children(self.base_url, parent_id, self.token)
        if children_response.status_code != 200:
            self.logger.error("Failed getting children for group {}".format(parent_id))
            return None

        children = convert_response(children_response)
        if 'groups' not in children:            
            self.logger.error("Missing groups data")
            return None
        
        # json data in contained within the 'groups' object, so extract that
        children = children['groups']

        if len(children) == 0:
            # No children. Its a leaf
            return parent_id

        choices = [x['name'] for x in children]
        child_index, child_name = SelectionHelper(self.logger, choices, "Select an sub-group")()
        self.logger.info("Selected {}".format(child_name))
        
        # Recurse into selected child group
        return self.get_leaf_group(children[child_index]['id'])
Esempio n. 3
0
 def test_get_group_children_wrong_target(self):
     """ Negative test - target group is real but should not be accessible """
     response = groups.get_group_children(
         environment.ATHERA_API_TEST_BASE_URL,
         environment.ATHERA_API_TEST_GROUP_ID,
         self.token,
         environment.ATHERA_API_TEST_OTHER_GROUP_ID,
     )
     self.assertEqual(response.status_code, codes.not_found)
Esempio n. 4
0
 def test_get_group_children(self):
     """ Positive test """
     response = groups.get_group_children(
         environment.ATHERA_API_TEST_BASE_URL,
         environment.ATHERA_API_TEST_GROUP_ID,
         self.token,
     )
     self.assertEqual(response.status_code, codes.ok)
     data = response.json()
     group_data = data['groups']
     first_child = group_data[0]
     self.assertNotEqual(len(first_child), 0)
     self.assertIn("id", first_child)
Esempio n. 5
0
    def get_children(self):
        """
        For the current group, fetch the children. We could return the whole objects, but we're just returning the IDs.
        """
        children_response = groups.get_group_children(self.base_url, self.group_id, self.token)
        if children_response.status_code != 200:
            self.logger.error("Failed getting children for group {}".format(self.group_id))
            return None

        children = common.convert_response(children_response)
        if 'groups' not in children:            
            self.logger.error("Missing groups data")
            return None
        
        # json data in contained within the 'groups' object, so extract that
        children = children['groups']

        if len(children) == 0:
            # No children. Its a leaf
            return []
        
        # Return just the ids. This is rather inefficient. How could you improve this?
        return [x['id'] for x in children]