def close(project_id, cycle_id): # TODO: Check untested cases. """POST endpoint for closing cycles. Param: { reason: required, } """ project = get_project(project_id) cycle = get_cycle(cycle_id, project_id) if cycle.state_code == StateType.closed: return make_response(jsonify(message='CYCLE_CLOSED')) else: reason = check_none_and_blank(request, 'reason') user = g.user cycle.closed_reason = reason cycle.closed_by = user.id cycle.state_code = StateType.closed cycle.closed_at = datetime.now() cycle.last_change = datetime.now() db.session.add(cycle) db.session.commit() return make_response(jsonify(message='CYCLE_CLOSED'))
def get_cycle_timeline_resume(project_id, cycle_limit=5): # TODO: Need to find a better way - Did this cz chartist works like that. project = get_project(project_id) project_cycles = Cycle.query.filter_by( project_id=project.id).limit(cycle_limit).all() cycles = [] cycle_cases_passed = [] cycle_cases_failed = [] cycle_cases_blocked = [] cycle_cases_not_executed = [] for item in project_cycles: cycle_cases = CycleCases.query.filter_by(cycle_id=item.id).all() stats = count_cycle_stats(cycle_cases) cycles.append('Cycle Number {}'.format(item.cycle)) cycle_cases_passed.append(stats['total_passed']) cycle_cases_failed.append(stats['total_error']) cycle_cases_blocked.append(stats['total_blocked']) cycle_cases_not_executed.append(stats['total_not_executed']) return make_response( jsonify(cycles_number=cycles, cycles_passed=cycle_cases_passed, cycles_failed=cycle_cases_failed, cycles_blocked=cycle_cases_blocked, cycles_not_executed=cycle_cases_not_executed))
def get_cycle_resume(project_id, cycle_id): project = get_project(project_id) cycle = get_cycle(cycle_id, project_id) cycle_cases_h = CycleCases.query.filter_by(cycle_id=cycle.id).all() body_response = count_cycle_stats(cycle_cases_h) return make_response(jsonify(body_response))
def get_scenarios_for_cyle(project_id, cycle_id): project = get_project(project_id) cycle = get_cycle(cycle_id, project_id) cycle_scenarios_h = CycleScenarios.query.filter_by(cycle_id=cycle.id).all() scenarios = Scenario.query.filter_by(project_id=project_id).all() obj = [] for item in cycle_scenarios_h: for scenario in scenarios: if scenario.id == item.scenario_id: cases = CycleCases.query.filter_by( cycle_id=cycle.id).filter_by( scenario_id=scenario.id).all() scenario_tags_raw = TagScenario.query.filter_by( scenario_id=scenario.id).all() schema = TagScenarioSchema(many=True) scenario_tags = schema.dump(scenario_tags_raw).data temp = {} temp['scenario_name'] = scenario.name temp['scenario_id'] = scenario.id temp['scenario_cycle_id'] = item.id temp['cases_stats'] = count_cycle_stats(cases) temp['tags'] = scenario_tags obj.append(temp) break return make_response(jsonify(obj))
def get_cases_for_cyle(project_id, cycle_id, scenario_id): project = get_project(project_id) scenario = get_scenario(scenario_id) cycle = get_cycle(cycle_id, project_id) cycle_cases_h = CycleCases.query.filter_by(cycle_id=cycle.id).all() cases = Case.query.filter_by(scenario_id=scenario.id) obj = [] for item in cycle_cases_h: for case in cases: if item.case_id == case.id: cases_tags_raw = TagCase.query.filter_by(case_id=case.id).all() schema = TagCaseSchema(many=True) case_tags = schema.dump(cases_tags_raw).data temp = {} temp['case_name'] = case.name temp['case_id'] = case.id temp['case_cycle_id'] = item.id temp['case_cycle_state'] = item.state_code.value temp['tags'] = case_tags obj.append(temp) break return make_response( jsonify(scenario_name=scenario.name, scenario_id=scenario.id, cycle_id=cycle.id, cases=obj))
def edit(project_id): """POST endpoint for editing existing users. Param: { project_name: not required, privacy_policy: not required (public or false), project_owner: not required (id), type_of_project: not required } """ edited_project = get_project(project_id) if 'project_name' in request.json: project_name = check_none_and_blank(request, 'project_name') edited_project.name = project_name if 'privacy_policy' in request.json: privacy_policy = check_none_and_blank(request, 'privacy_policy') edited_project.privacy_policy = privacy_policy if 'project_owner' in request.json: project_owner = check_none_and_blank(request, 'project_owner') user = get_user({'id': project_owner}) edited_project.owner_id = user.id if 'type_of_project' in request.json: type_of_project = check_none_and_blank(request, 'type_of_project') edited_project.type_of_project = type_of_project db.session.add(edited_project) db.session.commit() return make_response(jsonify(message='PROJECT_EDITED'))
def edit(project_id): """POST endpoint for editing existing users. Param: { project_name: not required, privacy_policy: not required (public or false), project_owner: not required (id), type_of_project: not required } """ edited_project = get_project(project_id) if 'project_name' in request.json: project_name = check_none_and_blank(request, 'project_name') edited_project.name = project_name if 'privacy_policy' in request.json: privacy_policy = check_none_and_blank(request, 'privacy_policy') edited_project.privacy_policy = privacy_policy if 'project_owner' in request.json: project_owner = check_none_and_blank(request, 'project_owner') user = get_user({'id': project_owner}) edited_project.owner_id = user.id if 'type_of_project' in request.json: type_of_project = check_none_and_blank(request, 'type_of_project') edited_project.type_of_project = type_of_project db.session.add(edited_project) db.session.commit() return make_response(jsonify(message='PROJECT_EDITED'))
def get_cycle_timeline_resume(project_id, cycle_limit=7): # TODO: Need to find a better way - Did this cz chartist works like that. project = get_project(project_id) project_cycles = Cycle.query.filter_by(project_id=project.id).order_by( Cycle.id.desc()).limit(cycle_limit).all() cycles = [] cycle_cases_passed = [] cycle_cases_failed = [] cycle_cases_blocked = [] cycle_cases_not_executed = [] for item in reversed(project_cycles): cycle_cases = CycleCases.query.filter_by(cycle_id=item.id).all() stats = count_cycle_stats(cycle_cases) if item.cycle == project_cycles[0].cycle: cycles.append('Current Cycle') else: if item.name == "": cycles.append('Cycle Number {}'.format(item.cycle)) else: cycles.append(item.name) cycle_cases_passed.append(stats['total_passed']) cycle_cases_failed.append(stats['total_error']) cycle_cases_blocked.append(stats['total_blocked']) cycle_cases_not_executed.append(stats['total_not_executed']) return make_response( jsonify(cycles_number=cycles, cycles_passed=cycle_cases_passed, cycles_failed=cycle_cases_failed, cycles_blocked=cycle_cases_blocked, cycles_not_executed=cycle_cases_not_executed))
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))