def test_job_list(runner, dci_context, team_id, topic_id, remoteci_id, component_id): kwargs = {'name': 'tname', 'topic_id': topic_id, 'component_types': ['git_review']} jd = jobdefinition.create(dci_context, **kwargs).json() jobdefinition_id = jd['jobdefinition']['id'] kwargs = {'name': 'test_jobdefinition', 'team_id': team_id} test_id = test.create(dci_context, **kwargs).json()['test']['id'] jobdefinition.add_test(dci_context, jobdefinition_id, test_id) kwargs = {'name': 'test_remoteci', 'team_id': team_id} test_id = test.create(dci_context, **kwargs).json()['test']['id'] remoteci.add_test(dci_context, remoteci_id, test_id) job_id = job.schedule( dci_context, remoteci_id, topic_id).json()['job']['id'] result = runner.invoke(['job-list-test', job_id]) assert len(result['tests']) == 2 assert result['tests'][0]['name'] == 'test_jobdefinition' assert result['tests'][1]['name'] == 'test_remoteci'
def create(context, name, team_id, data): """create(context, name, team_id, data) Create a test. >>> dcictl test-create [OPTIONS] :param string name: Name of the test [required] :param string team_id: ID of the team to associate with [required] :param json data: JSON formatted data block for the test """ if not team_id: team_id = user.get(context, context.login).json()['user']['team_id'] data = json.loads(data) result = test.create(context, name=name, data=data, team_id=team_id) utils.format_output(result, context.format, None, test.TABLE_HEADERS)
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 get_test_id(dci_context, name): print("Use test '%s'" % name) test.create(dci_context, name) return test.get(dci_context, name).json()['test']['id']
def team_test(dci_context, team_id): test = api_test.create(dci_context, "sometest", team_id=team_id).json() return test["test"]
def test_user_id(dci_context, team_user_id): kwargs = {"name": "test_user_name", "team_id": team_user_id} return api_test.create(dci_context, **kwargs).json()["test"]["id"]
def create(context, args): data = validate_json(context, "data", args.data) state = active_string(args.state) return test.create(context, name=args.name, data=data, state=state)
def create(context, name, data): data = json.loads(data) result = test.create(context, name=name, data=data) utils.format_output(result.json(), context.format, test.RESOURCE[:-1])
def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent'], type='str'), # Authentication related parameters # dci_login=dict(required=False, type='str'), dci_password=dict(required=False, type='str'), dci_cs_url=dict(required=False, type='str'), # Resource related parameters # id=dict(type='str'), name=dict(type='str'), data=dict(type='dict'), team_id=dict(type='str'), ), ) 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 test matching test id # Endpoint called: /tests/<test_id> DELETE via dci_test.delete() # # If the test exists and it has been succesfully deleted the changed is # set to true, else if the test 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_test.delete(ctx, module.params['id']) # Action required: Retrieve test informations # Endpoint called: /tests/<test_id> GET via dci_test.get() # # Get test informations elif module.params['id']: res = dci_test.get(ctx, module.params['id']) # Action required: Create a test with the specified content # Endpoint called: /tests POST via dci_test.create() # # Create the new test. else: if not module.params['name']: module.fail_json(msg='name parameter must be specified') if not module.params['team_id']: module.fail_json(msg='team_id parameter must be specified') kwargs = { 'name': module.params['name'], 'team_id': module.params['team_id'], } if module.params['data']: kwargs['data'] = module.params['data'] res = dci_test.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 == 409: result['changed'] = False else: result['changed'] = True except: result = {} result['changed'] = True module.exit_json(**result)