def change_cycle_case_state_code_(project_id): """ Endpoint for changing the cycle cases state_code . Param: { 'cycle_id': required, 'case_id': required, 'action': required } """ action = check_none_and_blank(request, 'action') case_id = check_none_and_blank(request, 'case_id') cycle_id = check_none_and_blank(request, 'cycle_id') cycle = get_cycle(cycle_id, project_id) last_cycle = get_last_cycle(project_id) if cycle.id != last_cycle.id: return make_response(jsonify(message='NOT_LAST_CYCLE')) if action not in StateType.__members__: return make_response(jsonify(message='ACTION_UNKNOW')) edited_cycle_case = CycleCases.query.filter_by( cycle_id=cycle.id).filter_by(case_id=case_id).first() if edited_cycle_case is None: abort(make_response(jsonify(message='UNKNOW_CASE'), 404)) edited_cycle_case.state_code = StateType[action] db.session.add(edited_cycle_case) db.session.commit() return make_response(jsonify(message='CYCLE_EDITED'))
def remove_scenario(): """POST endpoint for removing the scenario. Params: { scenario_id: required, action: required -> DISABLE, ACTIVE, REMOVE } """ scenario_id = check_none_and_blank(request, 'scenario_id') scenario = get_scenario(scenario_id) action = check_none_and_blank(request, 'action') last_cycle = get_last_cycle(scenario.project_id) if action in ['DISABLE', 'ENABLE', 'REMOVE']: if action == 'DISABLE': state = StateType.disable cycle_state = StateType.blocked elif action == 'ENABLE': state = StateType.active cycle_state = StateType.not_executed else: state = StateType.removed cycle_state = None scenario_case_process(last_cycle, scenario, state, action, cycle_state) else: return make_response(jsonify(message='ACTION_UNKNOW')) return make_response(jsonify(message='DONE'))
def tstcase_changestatus(scenario_id): """POST endpoint for new scenarios. Param: { 'case_id': required, 'action': required, } TODO: State is not defined """ case_id = check_none_and_blank(request, 'case_id') action = check_none_and_blank(request, 'action') scenario = get_scenario(scenario_id) tst_case = get_tstcase(case_id) if scenario.state_code == StateType.disable: return make_response(jsonify(message='SCENARIO_DISABLED')) last_cycle = get_last_cycle(scenario.project_id) if last_cycle: cycle_case = CycleCases.query.filter_by( cycle_id=last_cycle.id).filter_by(case_id=case_id).first() if action == 'DISABLE': state = StateType.disable cycle_state = StateType.blocked elif action == 'ENABLE': state = StateType.active cycle_state = StateType.not_executed elif action == 'REMOVE': if last_cycle and last_cycle.state_code == StateType.active: cycle_state = None if cycle_case: db.session.delete(cycle_case) db.session.commit() state = StateType.removed else: return make_response(jsonify(message='ACTION_UNKNOW')) tst_case.state_code = state db.session.add(tst_case) db.session.commit() if last_cycle: if last_cycle.state_code == StateType.active: if cycle_case and cycle_state: cycle_case.state_code = cycle_state db.session.add(cycle_case) db.session.commit() return make_response(jsonify(message='DONE'))
def get_project_details(project_id): """Show Project Details and last cycle Details.""" schema = ProjectSchema(many=False) project = schema.dump(get_project(project_id)).data user = User.query.filter_by(id=project['owner_id']).first() scenarios = Scenario.query.filter_by(project_id=project_id).first() project['owner_name'] = user.name project['owner_email'] = user.email if scenarios: project['have_scenarios'] = True cases = Case.query.join( Scenario, Case.scenario_id == Scenario.id).filter( Scenario.project_id == project_id).filter( Case.state_code == StateType.active).all() if len(cases) == 0: project['have_active_cases'] = False else: project['have_active_cases'] = True else: project['have_scenarios'] = False project['have_active_cases'] = False project_last_cycle = get_last_cycle(project_id) if project_last_cycle: cycle_cases_h = CycleCases.query.filter_by( cycle_id=project_last_cycle.id).all() project['have_cycles'] = True project['last_cycle'] = {} if project_last_cycle.state_code == StateType.closed: user_ = User.query.filter_by( id=project_last_cycle.closed_by).first() closed_by = user_.name project['last_cycle']['closed_at'] = datetime.strftime( project_last_cycle.closed_at, '%d-%m-%Y') project['last_cycle'][ 'closed_reason'] = project_last_cycle.closed_reason project['last_cycle']['closed_by'] = closed_by project['last_cycle']['id'] = project_last_cycle.id project['last_cycle'][ 'state_code'] = project_last_cycle.state_code.value project['last_cycle']['cycle'] = project_last_cycle.cycle project['last_cycle']['created_at'] = datetime.strftime( project_last_cycle.created_at, '%d-%m-%Y') project['last_cycle']['stats'] = count_cycle_stats(cycle_cases_h) else: project['have_cycles'] = False return make_response(jsonify(project))
def create(project_id): """POST endpoint for new cycles. Param: {'cycle_name': required but can be empty } """ project = get_project(project_id) project_lasty_cycle = get_last_cycle(project.id) if project_lasty_cycle: if project_lasty_cycle.state_code == StateType.active: return make_response(jsonify(message='CURRENT_CYCLE_ACTIVE')) cycle_number = int(project_lasty_cycle.cycle) + 1 else: cycle_number = 1 scenarios = Scenario.query.filter_by(project_id=project.id).filter_by( state_code=StateType.active).all() cases = Case.query.join(Scenario, Case.scenario_id == Scenario.id).filter( Scenario.project_id == project.id).filter( Case.state_code == StateType.active).all() if len(cases) == 0: abort(make_response(jsonify(message='NO_TEST_SCENARIOS'))) if request.json.get( 'cycle_name') == '' or request.json.get('cycle_name') is None: cycle_name = request.json.get('cycle_name') else: cycle_name = "Cycle Number {}".format(cycle_number) new_cycle = Cycle(cycle=cycle_number, name=cycle_name, project_id=project.id) db.session.add(new_cycle) db.session.commit() for scenario in scenarios: scenario_cycle = CycleScenarios(cycle_id=new_cycle.id, scenario_id=scenario.id) db.session.add(scenario_cycle) for case in cases: cyclecase = CycleCases(cycle_id=new_cycle.id, case_id=case.id, scenario_id=case.scenario_id) db.session.add(cyclecase) db.session.commit() return make_response( jsonify(message='CYCLE_CREATED', cycle_id=new_cycle.id))
def get_project_details(project_id): """Show Project Details and last cycle Details.""" schema = ProjectSchema(many=False) project = schema.dump(get_project(project_id)).data user = User.query.filter_by(id=project['owner_id']).first() scenarios = Scenario.query.filter_by(project_id=project_id).first() project['owner_name'] = user.name project['owner_email'] = user.email if scenarios: project['have_scenarios'] = True cases = Case.query.join( Scenario, Case.scenario_id == Scenario.id).filter( Scenario.project_id == project_id).filter( Case.state_code == StateType.active).all() if len(cases) == 0: project['have_active_cases'] = False else: project['have_active_cases'] = True else: project['have_scenarios'] = False project['have_active_cases'] = False project_last_cycle = get_last_cycle(project_id) if project_last_cycle: cycle_cases_h = CycleCases.query.filter_by( cycle_id=project_last_cycle.id).all() project['have_cycles'] = True project['last_cycle'] = {} if project_last_cycle.state_code == StateType.closed: user_ = User.query.filter_by(id=project_last_cycle.closed_by).first() closed_by = user_.name project['last_cycle']['closed_at'] = datetime.strftime( project_last_cycle.closed_at, '%d-%m-%Y') project['last_cycle']['closed_reason'] = project_last_cycle.closed_reason project['last_cycle']['closed_by'] = closed_by project['last_cycle']['id'] = project_last_cycle.id project['last_cycle']['state_code'] = project_last_cycle.state_code.value project['last_cycle']['cycle'] = project_last_cycle.cycle project['last_cycle']['created_at'] = datetime.strftime( project_last_cycle.created_at, '%d-%m-%Y') project['last_cycle']['stats'] = count_cycle_stats(cycle_cases_h) else: project['have_cycles'] = False return make_response(jsonify(project))
def home(): schema = ProjectSchema(many=True) projects = schema.dump(Project.query.all()).data for item in projects: project_last_cycle = get_last_cycle(item['id']) item['have_cycle'] = False if project_last_cycle: item['have_cycle'] = True cycle_cases_h = CycleCases.query.filter_by( cycle_id=project_last_cycle.id).all() item['current_cycle'] = project_last_cycle.cycle item['cycle_state'] = project_last_cycle.state_code.value item['stats'] = count_cycle_stats(cycle_cases_h) else: item['cycle_state'] = "nocycle" return make_response(jsonify(projects_qtd=len(projects),projects=projects))
def _create_scenario(request): scenario_name = request.json.get('scenario_name') project_id = request.json.get('projectId') check_none_and_blank(request, 'scenario_name') check_none_and_blank(request, 'project_id') if not Project.query.filter_by(id=project_id).first(): abort(make_response(jsonify(message='PROJECT_NOTFOUND'), 400)) new_scenario = Scenario(name=scenario_name, project_id=project_id) db.session.add(new_scenario) db.session.commit() project_lasty_cycle = get_last_cycle(project_id) if project_lasty_cycle: scenario_cycle = CycleScenarios(cycle_id=project_lasty_cycle.id, scenario_id=new_scenario.id) db.session.add(scenario_cycle) db.session.commit() return new_scenario
def new(scenario_id): """POST endpoint for new scenarios. Param: {'case_name': required } """ case_name = check_none_and_blank(request, 'case_name') scenario = get_scenario(scenario_id) case = Case(name=case_name, scenario_id=scenario.id) db.session.add(case) db.session.commit() project_lasty_cycle = get_last_cycle(scenario.project_id) if project_lasty_cycle: cyclecase = CycleCases(cycle_id=project_lasty_cycle.id, case_id=case.id, scenario_id=case.scenario_id) db.session.add(cyclecase) db.session.commit() return make_response(jsonify(message='CASE_CREATED'))