'Create sample data to be used on tests.
Created data are i) a role and ii) a domain containing: a project
hierarchy and 3 users within 3 groups.'

def load_sample_data(self):

    def create_project_hierarchy(parent_id, depth):
        'Create    a    random    project    hierarchy.'
        if (depth == 0):
            return
        breadth = random.randint(1, self.MAX_HIERARCHY_BREADTH)
        subprojects = []
        for i in range(breadth):
            subprojects.append(unit.new_project_ref(domain_id=self.domain_id, parent_id=parent_id))
            self.resource_api.create_project(subprojects[(-1)]['id'], subprojects[(-1)])
        new_parent = subprojects[random.randint(0, (breadth - 1))]
        create_project_hierarchy(new_parent['id'], (depth - 1))
    super(RoleAssignmentBaseTestCase, self).load_sample_data()
    self.domain = unit.new_domain_ref()
    self.domain_id = self.domain['id']
    self.resource_api.create_domain(self.domain_id, self.domain)
    self.project = unit.new_project_ref(domain_id=self.domain_id)
    self.project_id = self.project['id']
    self.resource_api.create_project(self.project_id, self.project)
    create_project_hierarchy(self.project_id, random.randint(1, self.MAX_HIERARCHY_DEPTH))
    self.user_ids = []
    for i in range(3):
        user = unit.new_user_ref(domain_id=self.domain_id)
        user = self.identity_api.create_user(user)
        self.user_ids.append(user['id'])
    self.group_ids = []
    for i in range(3):
        group = unit.new_group_ref(domain_id=self.domain_id)
        group = self.identity_api.create_group(group)
        self.group_ids.append(group['id'])
        self.identity_api.add_user_to_group(user_id=self.user_ids[i], group_id=group['id'])
        self.identity_api.add_user_to_group(user_id=self.user_ids[(i % 2)], group_id=group['id'])
    self.assignment_api.create_grant(user_id=self.user_id, project_id=self.project_id, role_id=self.role_id)
    self.role = unit.new_role_ref()
    self.role_id = self.role['id']
    self.role_api.create_role(self.role_id, self.role)
    self.default_user_id = self.user_ids[0]
    self.default_group_id = self.group_ids[0]
