def fix_report(request, sql_session): Session.add(EmployeeGroup(n=1, name='admins')) Session.add(Employee(n=1, name='NAME_1', employee_group_n=1, disabled=False)) # Этот тупой. Нет правильных ответов Session.add(Employee(n=2, name='NAME_2', employee_group_n=1, disabled=False)) Session.add(Feature(n=1, name='FEATURE_1')) Session.add(Feature(n=2, name='FEATURE_2')) Session.add(Question(n=1, feature_n=1, txt='QUESTION_1', answer_n=12)) Session.add(Answer(n=11, question_n=1, txt='ANSWER_11')) Session.add(Answer(n=12, question_n=1, txt='ANSWER_12')) Session.add(Question(n=2, feature_n=2, txt='QUESTION_2', answer_n=21)) Session.add(Answer(n=21, question_n=2, txt='ANSWER_21')) Session.add(Answer(n=22, question_n=2, txt='ANSWER_22')) Session.add(Result(n=11, question_n=1, answer_n=12, is_correct=True, employee_n=1, ddate=date.today())) Session.add(Result(n=12, question_n=1, answer_n=11, is_correct=False, employee_n=2, ddate=date.today())) Session.add(Result(n=21, question_n=2, answer_n=21, is_correct=True, employee_n=1, ddate=date.today() + timedelta(days=1))) Session.add(Result(n=22, question_n=2, answer_n=22, is_correct=False, employee_n=2, ddate=date.today() + timedelta(days=1)))
def fix_results_for_rest(request, sql_session): Session.add(Feature(n=1, name='-')) Session.add(Feature(n=2, name='FEATURE1')) Session.add(Feature(n=3, name='FEATURE2')) # Session.commit() # Вопрос 1 к Теме 2 Session.add(Question(n=21, feature_n=2, txt='CONTENT21', answer_n=211)) # Session.commit() Session.add(Answer(n=211, question_n=21, txt='CONTENT211')) Session.add(Answer(n=212, question_n=21, txt='CONTENT212')) Session.add(Answer(n=213, question_n=21, txt='CONTENT213')) # Вопрос 2 к Теме 2 Session.add(Question(n=22, feature_n=2, txt='CONTENT22', answer_n=211)) # Session.commit() Session.add(Answer(n=221, question_n=22, txt='CONTENT221')) Session.add(Answer(n=222, question_n=22, txt='CONTENT222')) Session.add(Answer(n=223, question_n=22, txt='CONTENT223')) # Session.commit() # Вопрос 1 к Теме 3 Session.add(Question(n=31, feature_n=3, txt='CONTENT31', answer_n='311')) # Session.commit() Session.add(Answer(n=311, question_n=31, txt='CONTENT311')) Session.add(Answer(n=312, question_n=31, txt='CONTENT312')) Session.add(Answer(n=313, question_n=31, txt='CONTENT313')) # Session.commit() Session.add(Result(n=1, question_n=21, answer_n=211, is_correct=True, employee_n=1, ddate=yesterday)) Session.add(Result(n=2, question_n=22, answer_n=221, is_correct=False, employee_n=1, ddate=yesterday))
def fix_results(request, sql_session): Session.add(EmployeeGroup(n=1, name='admins')) Session.add(Employee(n=1, name='NAME', password='******', employee_group_n=1, disabled=False)) Session.add(Feature(n=1, name='-')) Session.add(Feature(n=2, name='FEATURE1')) Session.add(Feature(n=3, name='FEATURE2')) # Session.commit() # Вопрос 1 к Теме 2 Session.add(Question(n=21, feature_n=2, txt='CONTENT21', answer_n=211)) Session.add(Answer(n=211, question_n=21, txt='CONTENT211')) Session.add(Answer(n=212, question_n=21, txt='CONTENT212')) Session.add(Answer(n=213, question_n=21, txt='CONTENT213')) # Вопрос 2 к Теме 2 Session.add(Question(n=22, feature_n=2, txt='CONTENT22', answer_n=211)) Session.add(Answer(n=221, question_n=22, txt='CONTENT221')) Session.add(Answer(n=222, question_n=22, txt='CONTENT222')) Session.add(Answer(n=223, question_n=22, txt='CONTENT223')) # Вопрос 1 к Теме 3 Session.add(Question(n=31, feature_n=3, txt='CONTENT31', answer_n='311')) Session.add(Answer(n=311, question_n=31, txt='CONTENT311')) Session.add(Answer(n=312, question_n=31, txt='CONTENT312')) Session.add(Answer(n=313, question_n=31, txt='CONTENT313')) Session.add(Result(n=1, question_n=21, answer_n=211, is_correct=True, employee_n=1)) Session.add(Result(n=2, question_n=22, answer_n=221, is_correct=False, employee_n=1))
def fix_for_employee_feature_group(request, sql_session): feature_group_1 = FeatureGroup(n=1, name='GROUP_1', parent_n=1) Session.add(feature_group_1) feature_group_2 = FeatureGroup(n=2, name='GROUP_2', parent_n=1) Session.add(feature_group_2) Session.add(Feature(n=1, name='-')) Session.add(Feature(n=2, name='FEATURE_1', feature_group=[feature_group_1, ])) Session.add(Feature(n=3, name='FEATURE_2', feature_group=[feature_group_2, ])) Session.add(Question(n=21, feature_n=1, txt='CONTENT_21')) Session.add(Question(n=22, feature_n=2, txt='CONTENT_22')) Session.add(Question(n=31, feature_n=3, txt='CONTENT_31')) _today = date.today() Session.add(Result(n=1, question_n=21, is_correct=True, employee_n=1, ddate=_today)) Session.add(Result(n=2, question_n=22, is_correct=False, employee_n=1, ddate=_today)) Session.add(Result(n=3, question_n=22, is_correct=True, employee_n=2, ddate=_today)) Session.add(Result(n=4, question_n=31, is_correct=False, employee_n=2, ddate=_today)) Session.add(Plan(n=1, employee_n=1, year=date.today().year, month=date.today().month, qty_work=1, qty_question=1)) Session.add(Plan(n=2, employee_n=2, year=date.today().year, month=date.today().month, qty_work=1, qty_question=2))
def fix_questions(request, sql_session): Session.add(Feature(n=1, name='-')) Session.add(Feature(n=2, name='FEATURE1')) Session.add(Feature(n=3, name='FEATURE2')) # Session.commit() # Вопрос 1 к Теме 2 Session.add(Question(n=21, feature_n=2, txt='CONTENT21', answer_n=211)) Session.add(Answer(n=211, question_n=21, txt='CONTENT211')) Session.add(Answer(n=212, question_n=21, txt='CONTENT212')) Session.add(Answer(n=213, question_n=21, txt='CONTENT213'))
def fix_results_for_pivot_report(request, sql_session): feature_group_1 = FeatureGroup(n=1, name='GROUP_1', parent_n=1) Session.add(feature_group_1) Session.add(Feature(n=1, name='FEATURE_1', feature_group=[feature_group_1, ])) # Session.commit() # Вопрос 1 к Теме 2 Session.add(Question(n=21, feature_n=1, txt='CONTENT21', answer_n=211)) # Session.commit() Session.add(Answer(n=211, question_n=21, txt='CONTENT211')) Session.add(Question(n=31, feature_n=1, txt='CONTENT31', answer_n='311')) # Session.commit() Session.add(Answer(n=311, question_n=31, txt='CONTENT311')) # Session.commit() _today = date.today() tomorrow = _today + relativedelta(days=1) Session.add(Result(n=10, question_n=21, answer_n=211, is_correct=True, employee_n=1, ddate=_today)) Session.add(Result(n=11, question_n=21, answer_n=211, is_correct=True, employee_n=1, ddate=_today)) Session.add(Result(n=12, question_n=31, answer_n=221, is_correct=False, employee_n=1, ddate=_today)) Session.add(Result(n=13, question_n=21, answer_n=211, is_correct=True, employee_n=1, ddate=tomorrow)) Session.add(Result(n=14, question_n=31, answer_n=221, is_correct=False, employee_n=1, ddate=tomorrow))
def test_add_feature(self): _group11 = FeatureGroup.get(11) NAME_FEATURE = 'NAME_FEATURE' _feature = Feature(n=1, name=NAME_FEATURE, feature_group=[_group11]) Session.add(_feature) assert _feature.n is not None assert len(_feature.feature_group) == 1
def test_model_sets_n_automatically(self): feature = Feature(name='name_feature', employee_n=1) feature_group = FeatureGroup.get(1) feature.feature_group.append(feature_group) Session.add(feature) Session.flush() assert feature.n is not None assert feature.name == 'name_feature' assert feature.employee_n == 1 assert feature.ddate == date.today()
def test_update(self): feature = Feature.get(1) self.assertEqual(feature.n, 1) feature_param = { 'n': 1, 'name': 'FEATURE_NAME', 'info': 'FEATURE_INFO', 'info_profit': 'FEATURE_INFO_PROFIT', 'employee_n': 1, 'questions': [{ 'n': 1, 'txt': 'QUESTION_TXT', 'answer_n': 3, 'answers': [ { 'n': 1, 'txt': 'ANSWER_TXT_1' }, { 'n': 2, 'txt': 'ANSWER_TXT_2' }, { 'n': 3, 'txt': 'ANSWER_TXT_3' }, ], }], } feature = FeatureCtrl.update(1, feature_param) self.assertEqual(feature.n, feature_param['n']) self.assertEqual(feature.name, feature_param['name']) self.assertEqual(feature.info, feature_param['info']) self.assertEqual(feature.info_profit, feature_param['info_profit']) self.assertEqual(feature.employee_n, 1) self.assertEqual(feature.ddate, date.today()) self.assertEqual(feature.questions[0].txt, feature_param['questions'][0]['txt']) self.assertEqual(feature.questions[0].answer_n, feature_param['questions'][0]['answer_n']) self.assertEqual(feature.questions[0].n, feature_param['questions'][0]['n']) for i in range(3): answer = feature.questions[0].answers[i] answer_param = feature_param['questions'][0]['answers'][i] self.assertEqual(answer.n, answer_param['n']) self.assertEqual(answer.txt, answer_param['txt'])
def test_update_feature_group(self): feature = Feature.get(1) feature_group = FeatureGroup.get(1) feature.feature_group.append(feature_group) Session.flush() self.assertEqual(len(feature.feature_group), 2) feature_group_params = [{'n': 11}] f_updated = FeatureCtrl.update_feature_group(feature, feature_group_params) self.assertEqual(len(f_updated.feature_group), 1) self.assertEqual(f_updated.feature_group[0].n, 11)
def fix_for_pivot_create_feature_report(request, sql_session): Session.add(EmployeeGroup(n=2, name='SELLERS')) Session.add(Right(n=2, employee_group_n=1, section='question', access='edit')) Session.add(Employee(n=2, name='EMPLOYEE_1', password='', employee_group_n=2, disabled=False)) Session.add(Employee(n=3, name='EMPLOYEE_2', password='', employee_group_n=2, disabled=False)) feature_group_1 = FeatureGroup(n=1, name='GROUP_1', parent_n=1) Session.add(feature_group_1) Session.add(Feature(n=1, name='FEATURE_11', feature_group=[feature_group_1, ], employee_n=2, ddate=date.today())) Session.add(Feature(n=2, name='FEATURE_12', feature_group=[feature_group_1, ], employee_n=2, ddate=date.today() + timedelta(days=1))) Session.add(Feature(n=3, name='FEATURE_21', feature_group=[feature_group_1, ], employee_n=3, ddate=date.today())) Session.add(Feature(n=4, name='FEATURE_22', feature_group=[feature_group_1, ], employee_n=3, ddate=date.today() + timedelta(days=1)))
def fix_full_fixteres(request, sql_session): Session.add(FeatureGroup(n=1, name='group1')) feature_group = FeatureGroup(n=11, name='group11', parent_n=1) Session.add(feature_group) feature = Feature(n=1, name='FEATURE_1', info='INFO_1', info_profit='INFO_PROFIT_1', feature_group=[feature_group, ]) Session.add(feature) Session.add(Question(n=1, feature_n=1, txt='QUESTION_1', answer_n=2)) Session.add(Answer(n=1, question_n=1, txt='ANSWER_1')) Session.add(Answer(n=2, question_n=1, txt='ANSWER_2')) Session.add(Answer(n=3, question_n=1, txt='ANSWER_3'))
def fix_results_for_generate(request, sql_session): feature_group_1 = FeatureGroup(n=1, name='GROUP_1', parent_n=1) Session.add(feature_group_1) feature_group_2 = FeatureGroup(n=2, name='GROUP_2', parent_n=1) Session.add(feature_group_2) Session.add(Feature(n=1, name='-')) Session.add(Feature(n=2, name='FEATURE1', feature_group=[feature_group_1, ])) Session.add(Feature(n=3, name='FEATURE2', feature_group=[feature_group_2, ])) # Session.commit() # Вопрос 1 к Теме 2 Session.add(Question(n=21, feature_n=1, txt='CONTENT21', answer_n=211)) # Session.commit() Session.add(Answer(n=211, question_n=21, txt='CONTENT211')) Session.add(Answer(n=212, question_n=21, txt='CONTENT212')) Session.add(Answer(n=213, question_n=21, txt='CONTENT213')) # Вопрос 2 к Теме 2 Session.add(Question(n=22, feature_n=2, txt='CONTENT22', answer_n=211)) # Session.commit() Session.add(Answer(n=221, question_n=22, txt='CONTENT221')) Session.add(Answer(n=222, question_n=22, txt='CONTENT222')) Session.add(Answer(n=223, question_n=22, txt='CONTENT223')) # Session.commit() # Вопрос 1 к Теме 3 Session.add(Question(n=31, feature_n=3, txt='CONTENT31', answer_n='311')) # Session.commit() Session.add(Answer(n=311, question_n=31, txt='CONTENT311')) Session.add(Answer(n=312, question_n=31, txt='CONTENT312')) Session.add(Answer(n=313, question_n=31, txt='CONTENT313')) # Session.commit() _today = date.today() Session.add(Result(n=1, question_n=21, answer_n=211, is_correct=True, employee_n=1, ddate=_today))
def create_feature(params): feature = Feature() feature.name = params['name'] feature.info = params['info'] feature.info_profit = params['info_profit'] feature.employee_n = params['employee_n'] for feature_group in params['feature_group']: g = FeatureGroup.get(feature_group['n']) feature.feature_group.append(g) Session.add(feature) Session.flush() return feature
def update(n, params): q = Session.query(Feature).filter(Feature.n == n) q.update({'ddate': date.today()}) if 'name' in params: q.update({'name': params['name']}) if 'info' in params: q.update({'info': params['info']}) if 'info_profit' in params: q.update({'info_profit': params['info_profit']}) if 'employee_n' in params: q.update({'employee_n': params['employee_n']}) feature = Feature.get(n) if 'questions' in params: FeatureCtrl.update_question(feature, params['questions']) if 'feature_group' in params: feature = FeatureCtrl.update_feature_group(feature, params['feature_group']) return feature
def fix_many_features(request, sql_session): for x in range(15): name = 'FEATURE {}'.format(x) Session.add(Feature(n=x, name=name))
def fix_features(request, sql_session): feature_group_1 = FeatureGroup(n=1, name='group1') Session.add(feature_group_1) feature = Feature(n=1, name='-') feature.feature_group.append(feature_group_1) Session.add(feature)