def test_embed(dci_context): team_id = team.create(dci_context, name="teama").json()["team"]["id"] rci = remoteci.create(dci_context, name="boa", team_id=team_id).json() rci_id = rci["remoteci"]["id"] rci_with_embed = remoteci.get(dci_context, id=rci_id, embed="team").json() embed_team_id = rci_with_embed["remoteci"]["team"]["id"] assert team_id == embed_team_id
def test_embed(dci_context): team_id = team.create(dci_context, name="teama").json()["team"]["id"] rci = remoteci.create(dci_context, name="boa", team_id=team_id).json() rci_id = rci["remoteci"]["id"] rci_with_embed = remoteci.get(dci_context, id=rci_id, embed=["team"]).json() embed_team_id = rci_with_embed["remoteci"]["team"]["id"] assert team_id == embed_team_id
def test_embed(dci_context): team_id = team.create(dci_context, name='teama').json()['team']['id'] rci = remoteci.create(dci_context, name='boa', team_id=team_id).json() rci_id = rci['remoteci']['id'] rci_with_embed = remoteci.get(dci_context, id=rci_id, embed='team').json() embed_team_id = rci_with_embed['remoteci']['team']['id'] assert team_id == embed_team_id
def job_id(dci_context): my_team = team.create(dci_context, name='tname').json()['team'] my_remoteci = remoteci.create(dci_context, name='tname', team_id=my_team['id'], data={'remoteci': 'remoteci'}).json() my_remoteci_id = my_remoteci['remoteci']['id'] my_test = test.create( dci_context, name='tname', data={'test': 'test'}).json() my_test_id = my_test['test']['id'] my_jobdefinition = jobdefinition.create( dci_context, name='tname', test_id=my_test_id).json() my_component = component.create( dci_context, name='hihi', type='git_review', data={'component': 'component'}).json() my_component_id = my_component['component']['id'] jobdefinition.add_component(dci_context, my_jobdefinition['jobdefinition']['id'], my_component_id) my_job = job.schedule(dci_context, my_remoteci_id).json() return my_job['job']['id']
def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent'], type='str'), # Authentication related parameters # login=dict(required=False, type='str'), password=dict(required=False, type='str'), url=dict(required=False, type='str'), # Resource related parameters # id=dict(type='str'), name=dict(type='str'), country=dict(type='str'), email=dict(type='str'), notification=dict(type='bool'), ), ) if not dciclient_found: module.fail_json(msg='The python dciclient module is required') login, password, url = get_details(module) if not login or not password: module.fail_json(msg='login and/or password have not been specified') ctx = dci_context.build_dci_context(url, login, password, 'Ansible') # Action required: Delete the team matching team id # Endpoint called: /teams/<team_id> DELETE via dci_team.delete() # # If the team exists and it has been succesfully deleted the changed is # set to true, else if the team does not exist changed is set to False if module.params['state'] == 'absent': if not module.params['id']: module.fail_json(msg='id parameter is required') res = dci_team.get(ctx, module.params['id']) if res.status_code not in [400, 401, 404, 422]: kwargs = { 'id': module.params['id'], 'etag': res.json()['team']['etag'] } res = dci_team.delete(ctx, **kwargs) # Action required: Retrieve team informations # Endpoint called: /teams/<team_id> GET via dci_team.get() # # Get team informations elif module.params['id'] and not module.params['name'] and not module.params['country'] and not module.params['email'] and module.params['notification'] is None: res = dci_team.get(ctx, module.params['id']) # Action required: Update an existing team # Endpoint called: /teams/<team_id> PUT via dci_team.update() # # Update the team with the specified characteristics. elif module.params['id']: res = dci_team.get(ctx, module.params['id']) if res.status_code not in [400, 401, 404, 422]: kwargs = { 'id': module.params['id'], 'etag': res.json()['team']['etag'] } if module.params['name']: kwargs['name'] = module.params['name'] if module.params['country']: kwargs['country'] = module.params['country'] if module.params['email']: kwargs['email'] = module.params['email'] if module.params['notification'] is not None: kwargs['notification'] = module.params['notification'] res = dci_team.update(ctx, **kwargs) # Action required: Creat a team with the specified content # Endpoint called: /teams POST via dci_team.create() # # Create the new team. else: if not module.params['name']: module.fail_json(msg='name parameter must be specified') kwargs = {'name': module.params['name']} if module.params['country']: kwargs['country'] = module.params['country'] if module.params['email']: kwargs['email'] = module.params['email'] if module.params['notification'] is not None: kwargs['notification'] = module.params['notification'] res = dci_team.create(ctx, **kwargs) try: result = res.json() if res.status_code == 404: module.fail_json(msg='The resource does not exist') if res.status_code == 422: result['changed'] = False else: result['changed'] = True except: result = {} result['changed'] = True module.exit_json(**result)
def create(context, args): params = {k: getattr(args, k) for k in ["name", "country", "state"]} params["state"] = active_string(params["state"]) return team.create(context, **params)
def team_id(dci_context): return api_team.create(dci_context, name="tname").json()["team"]["id"]
def team_id(dci_context): return team.create(dci_context, name='tname').json()['team']['id']
def create(context, name): result = team.create(context, name=name) utils.format_output(result.json(), context.format, team.RESOURCE[:-1])