def pridat_test(): """pridat test z již vložených otázek a určit dobu platnosti testu """ if request.method == 'GET': otazky = select( (o.id, o.ucitel, o.ucitel.jmeno, o.jmeno, o.obecne_zadani) for o in Otazka) return render_template('pridat_test.html', otazky=otazky.order_by(1)) elif request.method == 'POST': nazev_testu = request.form['nazev_testu'] platne_od = request.form['datum1'] + " " + request.form['cas_od'] platne_do = request.form['datum2'] + " " + request.form['cas_do'] datum_od = datetime.datetime.strptime(platne_od, "%d.%m.%Y %H:%M") datum_do = datetime.datetime.strptime(platne_do, "%d.%m.%Y %H:%M") checked = request.form.getlist('check') Test(jmeno=nazev_testu, ucitel=get(u for u in Ucitel if u.login == session['ucitel']), zobrazeno_od=datum_od, zobrazeno_do=datum_do) for otazka in checked: Otazka_testu(poradi=0, test=get(u for u in Test if u.jmeno == nazev_testu), otazka=get(o for o in Otazka if o.jmeno == otazka)) zprava = 'Vytvořen test "' + nazev_testu + '"' otazky = select( (o.id, o.ucitel, o.ucitel.jmeno, o.jmeno, o.obecne_zadani) for o in Otazka) return render_template('pridat_test.html', zprava=zprava, otazky=otazky.order_by(1))
def update_sprint(sprint_id: str, sprint_info: dict): """ Update Sprint :param sprint_id: :param sprint_info: :return: """ _sprint = get(s for s in Sprint if str(s.uuid) == sprint_id) _project = get(p for p in Project if str(p.uuid) == sprint_info.get('project_id')) _sprint.project = _project _sprint.name = sprint_info.get('name') _sprint.version = sprint_info.get('version') _sprint.requirements = sprint_info.get('requirements') _sprint.rcs = sprint_info.get('rcs') _sprint.issue = sprint_info.get('issue') _sprint.case = sprint_info.get('case') _issue_tracker = get( t for t in Tracker if str(t.uuid) == _project.tracker.get('issue').get('id')) if _issue_tracker.type == 'jira': _sprint.queries = { 'issue': { 'jira': generateQueries.generate_jqls(_project.project['issue']['key'], sprint_info) } } return _sprint.uuid
def otazka_editovat(id): if request.method == 'GET': otazka = Otazka[id] return render_template('otazka_editovat.html', otazka=otazka, rendruj=rendruj) if request.method == 'POST': r = request r.f = r.form if r.f['jmeno'] and r.f['typ_otazky'] and r.f['obecne_zadani']: if r.f['typ_otazky'] == 'O': otazka = Otazka[id] otazka.ucitel = get(u for u in Ucitel if u.login == session['ucitel']) otazka.jmeno = r.f['jmeno'] otazka.typ_otazky = 'O' otazka.obecne_zadani = r.f['obecne_zadani'] return redirect(url_for('otazky')) elif r.f['typ_otazky'] == 'C' and r.f['spravna_odpoved']: otazka = Otazka[id] otazka.ucitel = get(u for u in Ucitel if u.login == session['ucitel']) otazka.jmeno = r.f['jmeno'] otazka.typ_otazky = 'C' otazka.obecne_zadani = r.f['obecne_zadani'] otazka.spravna_odpoved = r.f['spravna_odpoved'] return redirect(url_for('otazky')) # TODO! else: zprava = "Nebyla zadána všechna požadovaná data." otazka = Otazka[id] return render_template('otazka_editovat.html', chyba=zprava, otazka=otazka)
def add_project(body: dict): """ Add Project :param body: { 'name': string, 'issue_tracker': { 'tracker_id': string, 'project_key': string, 'project_value': string, }, 'case_tracker': { 'tracker_id': string, 'project_key': string, 'project_value': string } } :return: project_id """ i_tracker = body.get('issue_tracker') c_tracker = body.get('case_tracker') project = Project(name=body.get('name')) if i_tracker.get('tracker_id'): project.issue_tracker = get( t for t in Tracker if str(t.uuid) == i_tracker.get('tracker_id')) project.issue_project = { 'project_key': i_tracker.get('project_key'), 'project_value': i_tracker.get('project_value') } if c_tracker.get('tracker_id'): project.case_tracker = get( t for t in Tracker if str(t.uuid) == c_tracker.get('tracker_id')) project.case_project = { 'project_key': c_tracker.get('project_key'), 'project_value': c_tracker.get('project_value') } return { 'id': project.uuid, 'name': project.name, 'issue_tracker': { 'tracker_id': project.issue_tracker.uuid if project.issue_tracker else '', 'tracker_name': project.issue_tracker.name if project.issue_tracker else '', 'project_key': project.issue_project.get('project_key'), 'project_value': project.issue_project.get('project_value'), }, 'case_tracker': { 'tracker_id': project.case_tracker.uuid if project.case_tracker else '', 'tracker_name': project.case_tracker.name if project.case_tracker else '', 'project_key': project.case_project.get('project_key'), 'project_value': project.case_project.get('project_value'), }, 'status': project.status }
def list_project(project_status=None): """ List All Projects :param project_status: :return: {[ 'id': '', 'name': '', 'tracker': { 'issue': { 'id': '', 'name': '' }, 'case': { 'id': '', 'name': '' } }, 'project': { 'issue': { 'key': '' }, 'case': { 'key': '' } }, 'status': '' ]} """ projects = list() if project_status: items = select(p for p in Project if p.status in project_status).order_by(Project.name) else: items = select(p for p in Project).order_by(Project.name) for item in items: _issue_tracker = get(t for t in Tracker if item.tracker['issue']['id'] == str(t.uuid)) _case_tracker = get(t for t in Tracker if item.tracker['case']['id'] == str(t.uuid)) projects.append({ 'id': item.uuid, 'name': item.name, 'tracker': { 'issue': { 'id': _issue_tracker.uuid if _issue_tracker else '', 'name': _issue_tracker.name if _issue_tracker else '' }, 'case': { 'id': _case_tracker.uuid if _case_tracker else '', 'name': _case_tracker.name if _case_tracker else '' } }, 'project': item.project, 'status': item.status }) return projects
def search_by_name(): try: # try searching by first, last name if first_name and last_name: return orm.get(s for s in db.Staff if s.first_name.lower() == first_name.lower() and s.last_name.lower() == last_name.lower()) elif first_name: return orm.get(s for s in db.Staff if s.first_name.lower() == first_name.lower()) elif last_name: return orm.get(s for s in db.Staff if s.last_name.lower() == last_name.lower()) except (orm.MultipleObjectsFoundError, orm.ObjectNotFound): return False
def generate_grade_report(policy_id: str, sprint_id: str): """初始化 report""" report = { 'project': { 'bug_count_risk': 0, 'prod_bug_risk': 0, 'bug_found_rate': 0, 'bug_density_risk': 0, }, 'sprint': { 'bug_severity_rate': 0, 'reopen_bug_rate': 0, 'regression_bug_rate': 0, 'previous_bug_rate': 0, 'feature_found_bug_rate': 0, 'improve_found_bug_rate': 0, 'qamissed_bug_rate': 0, 'rc_bug_risk': 0, 'bug_growth_risk': 0, 'bug_fix_rate': 0, 'bug_fix_risk': 0, 'bug_verify_rate': 0, 'bug_verify_risk': 0, 'feature_bug_risk': 0, # 'case_execution_rate': 0, # 'case_pass_rate': 0, }, } """获取 issue 数据并进行指标计算 https://qualitysphere.gitee.io/images/point.png""" sprint = get(s for s in Sprint if str(s.uuid) == sprint_id) project = get(p for p in Project if p.uuid == sprint.project.uuid) # bugs in the Sprint ➗ average(bugs in all Sprints) bugs_in_the_sprint = get(i for i in IssueCaptureStaticProject if i.sprint.uuid == sprint.uuid).in_release['total'] average_bugs_in_all_sprints = list() for item in select(i for i in IssueCaptureStaticProject if i.sprint.project.uuid == project.uuid): average_bugs_in_all_sprints.append(item.in_release['total']) report['project']['bug_count_risk'] = numpy.divide( bugs_in_the_sprint, numpy.mean(average_bugs_in_all_sprints) ) # customer found bugs in the Sprint ➗ customer found bugs in the previous Sprint # team found bugs ➗ ( team found bugs + customer found bugs ) * 100% # ( the Sprint total bugs ➗ the Sprint new code lines ) ➗ ( previous Sprint total bugs ➗ previous Sprint new code lines) """创建 Sprint 评级报告""" item = GradeReportSprint( policy=get(p for p in GradePolicy if str(p.uuid) == policy_id), sprint=get(s for s in Sprint if str(s.uuid) == sprint_id), report=report )
def __collect_disable_sprint_issue_data_from_jira(sprint_id: str): """ Collect disabled sprint issue data from JIRA Sprint :param sprint_id: :return: """ logging.info('Start to collect DISABLE sprint issue data: %s' % sprint_id) sprint = get(s for s in Sprint if str(s.uuid) == sprint_id) project = get(p for p in Project if str(p.uuid) == str(sprint.project.uuid)) capture_time = datetime.now() customer_jql_base = ' AND '.join([ 'project = %s' % sprint.project.issue_project['project_key'], '%s IN (%s)' % (sprint.issue_config.type['field'], str(sprint.issue_config.type['value']).strip('[|]')), '%s IN (%s)' % (sprint.issue_config.version['field'], str(sprint.issue_config.version['value']).strip('[|]')), '%s IN (%s)' % (sprint.issue_config.since['field'], str(sprint.issue_config.since['customer']).strip('[|]')), ]) with JiraSession(project.issue_tracker.info['host'], project.issue_tracker.info['account'], project.issue_tracker.token) as jira_session: customer_total = jira_session.search_issues(customer_jql_base)['total'] static_project = get(p for p in IssueCaptureStaticProject if str(p.sprint.uuid) == str(sprint.uuid)) if static_project: logging.info('Update project %s static data into DB' % project.uuid) static_project.capture_time = capture_time static_project.from_customer = {'total': int(customer_total)} static_overview = get(o for o in IssueCaptureStaticOverview if str(o.project.uuid) == str(project.uuid)) items = select(s for s in IssueCaptureStaticProject if str(s.sprint.project.uuid) == str(project.uuid)) from_customer_total = list() for item in items: from_customer_total.append(int(item.from_customer['total'])) if static_overview: logging.info('Update overview static data into DB') static_overview.capture_time = capture_time static_overview.from_customer = { 'total': numpy.sum(from_customer_total) } return True
def get_data_variable_by_env_id(cls, env_id): obj = get(n for n in Variable if n.env.id == env_id and n.env.delete_at == None and n.delete_at == None) if obj: return obj.data else: raise IsNotExist(title='环境里没有设置项目变量', detail=f'环境id为{env_id}的环境下没有找到项目变量')
def search_by_username(): try: # try searching by first, last name return orm.get(s for s in db.Staff if s.github_username == username or s.jira_username == username) except (orm.MultipleObjectsFoundError, orm.ObjectNotFound): return False
def get_sprint(sprint_id: str): """ Get Sprint :param sprint_id: :return: """ sprint_info = dict() item = get(s for s in Sprint if str(s.uuid) == sprint_id) if item: cts = list() for ct in select(i for i in IssueSprint if str(i.sprint.uuid) == sprint_id).order_by( IssueSprint.capture_time): cts.append(ct.capture_time) sprint_info = { 'id': item.uuid, 'name': item.name, 'project_id': item.project.uuid, 'project_name': item.project.name, "version": item.version, "requirements": item.requirements, "rcs": item.rcs, "issue": item.issue, "case": item.case, "queries": item.queries, 'status': item.status, 'start_time': int(cts[0].timestamp()) if len(cts) > 0 else '', 'end_time': int(cts[-1].timestamp()) if len(cts) > 0 else '' } return sprint_info
def sync_sprint_issue_data(sprint_id: str): """ Sync Sprint Issue Data :param sprint_id: :return: """ sprint = get(s for s in Sprint if str(s.uuid) == sprint_id) _issue_tracker = get( t for t in Tracker if str(t.uuid) == sprint.project.tracker['issue']['id']) if sprint.status == 'active': if _issue_tracker.type == 'jira': _sync_jira_data_for_sprint_all_issue(sprint_id) elif sprint.status == 'disable': if _issue_tracker.type == 'jira': _sync_jira_data_for_sprint_customer_issue(sprint_id)
def delete_case_by_id(cls, case_id, user): obj = get(n for n in TestCase if n.id == case_id and n.delete_at == None) if obj: obj.delete_at = datetime.datetime.utcnow() obj.user = user else: raise IsNotExist(title='测试用例不存在', detail=f'id为{case_id}的测试用例不存在')
def copy_case_by_id(cls, case_id, user): obj = get(n for n in TestCase if n.id == case_id and n.delete_at == None) if obj: TestCase(method=obj.method, path=obj.path, case=f'{obj.case}_copy', setup=obj.setup, parameters=obj.parameters, body=obj.body, teardown=obj.teardown, validator=obj.validator, user=user, gitfile=obj.gitfile.id) else: raise IsNotExist(title='测试用例不存在', detail=f'id为{case_id}的测试用例不存在')
def db_delete_content(cls, name): obj = get(n for n in Content if n.name == name and n.isdelete == 0) if obj: obj.isdelete = 1 obj.update_time = datetime.datetime.now() else: raise IsNotExist(title='没有该名字的模版', detail=f'没有名字为【{name}】的模版')
def create(cls, namespace, description, user): obj = get(n for n in Namespace if n.namespace == namespace and n.delete_at == None) if obj: raise IsExist(title='不能创建同名的namespace', detail=f'{namespace}已经存在, uuid为{obj.uid}') Namespace(namespace=namespace, description=description, user=user)
def test_edit_setoran(self): self.login() santri = get(s for s in Santri if s.id == 1) data = dict(santri='1', start="1/1", end="1/1", jenis="tambah", lulus='1') resp = self.client.post("/setoran/edit/1", data=data) self.assert_message_flashed("Setoran with id 1 was modified.", "info") self.assert_redirects(resp, "/santri/display/1") self.assertEqual(select(s for s in Setoran).count(), 6) self.assertEqual(santri.setorans.count(), 1) enam = get(s for s in Santri if s.id == 6) self.assertEqual(enam.setorans.count(), 1)
def update(cls, namespace_id, env_id, env, url, description, user): obj = get(n for n in Env if n.env == env and n.delete_at == None and n.namespace.id == namespace_id and n.namespace.delete_at == None) if obj: raise IsExist(title='修改的环境名已经存在', detail=f'{env}已经存在, uuid为{obj.uid}') obj = get(n for n in Env if n.id == env_id and n.delete_at == None and n.namespace.id == namespace_id and n.namespace.delete_at == None) if obj: obj.env = env obj.url = url obj.description = description obj.update_at = datetime.datetime.utcnow() obj.user = user else: raise IsNotExist(title='修改的环境不存在', detail=f'id为{env_id}的环境不存在')
def db_creat_info(cls, url, name, comment, key, type): obj = get(n for n in Info if n.url == url) if obj: raise IsExist(title='该url已经存在', detail=f'url为{url}的机器人已经存在') #需要添加正在匹配,将key单独存储 else: Info(url=url, name=name, comment=comment, key=key, type=type)
def delete_suit_by_suit_id(cls, suit_id, user): obj = get(n for n in TestSuit if n.id == suit_id and n.delete_at == None) if obj: obj.delete_at = datetime.datetime.utcnow() obj.user = user else: raise IsNotExist(title='测试套件不存在', detail=f'id为{suit_id}的测试套件不存在')
def db_del_info(self, key): obj = get(n for n in Info if n.key == key) print(key) if obj: obj.delete() else: raise IsNotExist(title='删除机器人不存在', detail=f'【{key}】的机器人不存在')
def update_tracker(tracker_id: str, tracker_name: str, tracker_type: str, tracker_info: dict, tracker_secret: str): """ Update Tracker Info :param tracker_id: :param tracker_name: :param tracker_type: jira :param tracker_info: :param tracker_secret: :return: tracker_id """ item = get(t for t in Tracker if str(t.uuid) == tracker_id) if item: if tracker_type.lower() == 'jira': with JiraSession( tracker_info.get('host'), tracker_info.get('account'), tracker_secret) as jira_session: assert tracker_info.get('account') == jira_session.get_user() else: raise Exception('Only support JIRA') item.name = tracker_name item.type = tracker_type item.info = tracker_info item.secret = tracker_secret return item.uuid
def list_tracker_issue_field_value(tracker_id: str, field_key: str, project_key=None): """ List issue field values in the project from tracker server :param tracker_id: :param field_key: :param project_key: :return: """ tracker = get(t for t in Tracker if str(t.uuid) == tracker_id) values = list() items = list() if tracker.type == 'jira': with JiraSession(tracker.info.get('host'), tracker.info.get('account'), tracker.token) as jira_session: if field_key == 'status': items = jira_session.get_issue_statuses() elif field_key == 'issuetype': items = jira_session.get_issue_types() elif field_key == 'versions': if project_key: items = jira_session.get_project_versions(pid=project_key) else: raise Exception('project is required') for item in items: values.append({'key': item.id, 'value': item.name}) else: raise Exception('ONLY support JIRA') return {'count': len(values), 'results': values}
def delete_env_by_id(cls, env_id, user): obj = get(n for n in Env if n.id == env_id and n.delete_at == None) if obj: obj.delete_at = datetime.datetime.utcnow() obj.user = user else: raise IsNotExist(title='删除的环境不存在', detail=f'环境id为{env_id}的环境不存在')
def dislike_artist(self, artist): if isinstance(artist, str): # pylint: disable=consider-using-in artist = get(a for a in Artist if a.id == artist or a.name == artist) elif isinstance(artist, dict): artist = Artist.get(artist.id) or Artist.from_dict(artist) self.user.dislike(artist=artist)
def fetcher(self, *args, **kwargs): being = get(account.being for account in Account if account.id == self.account_id) #if not account pass
def delete(cls, script_id, user): obj = get(n for n in Script if n.delete_at == None and n.id == script_id) if obj: obj.user = user obj.delete_at = datetime.datetime.utcnow() return obj.script_file, obj.project_id else: raise IsNotExist(title='脚本不存在', detail=f'脚本id为{script_id}的脚本不存在')
def create(cls, namespace_id, env, url, description, user): obj = get(n for n in Env if n.env == env and n.delete_at == None and n.namespace.id == namespace_id and n.namespace.delete_at == None) if obj: raise IsExist(title='不能创建同名的环境', detail=f'{env}已经存在, uuid为{obj.uid}') else: obj = Env(env=env, description=description, user=user, namespace=namespace_id, url=url) return obj
def get_global_variable(cls, project_id): obj = get(n for n in GlobalVariable if n.project_id == project_id and n.delete_at == None) if obj: return obj.data else: raise IsNotExist(title='全部变量不存在', detail=f'repo id为{project_id}的全局变量不存在')
def register(cls, username, password): obj = get(n for n in User if n.username == username) if obj: raise IsExist(title='此用户已经存在', detail=f'用户名{username}已经存在', type='LoginError') else: User(username=username, password=password)
def get_obj_pk_by_project_id_and_file_path(cls, project_id, file_path): obj = get(n for n in GitFile if n.project_id == project_id and n.delete_at == None and n.file_path == file_path) if obj: return obj.id else: raise IsNotExist(title='获取文件不存在', detail=f'项目{project_id}下的文件{file_path}不存在')
def f(): project = orm.get(project for project in db.Project if project.name == project_name) if project is not None: list_project(project) else: list_all()
def snapshot(self): ''' Get the initial snapshot of device applications state ''' return { str(uuid): pony.get( res for res in config.db.Resource if res.id == uuid).to_json() for uuid, da in iot_conn_mgr.conns.items() }
def get_channel_with_dirname(cls, dirname): # It is impossible to use LIKE queries on BLOBs, so we have to use comparisons def extend_to_bitmask(txt): return txt + "0" * (PUBLIC_KEY_LEN * 2 - CHANNEL_DIR_NAME_LENGTH) dirname_binmask_start = "x'" + extend_to_bitmask(dirname) + "'" binmask_plus_one = ("%X" % (int(dirname, 16) + 1)).zfill(len(dirname)) dirname_binmask_end = "x'" + extend_to_bitmask(binmask_plus_one) + "'" sql = "g.public_key >= " + dirname_binmask_start + " AND g.public_key < " + dirname_binmask_end return orm.get(g for g in cls if raw_sql(sql))
def fetcher(self, *args, **kwargs): print("Fetcher", args, kwargs) # If account is already supplied, don't do anything if "account" in kwargs: return f(self, *args, **kwargs) else: # To fetch the account, we need at least the account id if self.account_id is None: raise RuntimeError account = get(account for account in Account if account.id == self.account_id) if not account: raise RuntimeError return f(self, *args, account=account, **kwargs)
def identify(self, email): return get(user for user in User if user.email == email)