def test_auditlog_enabled_for_pro_always_returns_True(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.auditlog_enabled_for(self.pro) is True pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.auditlog_enabled_for(self.pro) is True
def test_autoimporter_enabled_for_admin_always_returns_True(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.autoimporter_enabled_for(self.admin) is True pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.autoimporter_enabled_for( self.admin) is True
def test_better_stats_enabled_for_admin_user_always_returns_True(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.better_stats_enabled_for( self.admin, self.no_pro) is True pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.better_stats_enabled_for( self.admin, self.no_pro) is True
def test_better_stats_enabled_for_pro_owner_always_returns_True(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.better_stats_enabled_for( self.no_pro, self.pro) is True assert pro_enabled_handler.better_stats_enabled_for( self.anonymous, self.pro) is True pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.better_stats_enabled_for( self.no_pro, self.pro) is True assert pro_disabled_handler.better_stats_enabled_for( self.anonymous, self.pro) is True
def create_quiz(short_name): (project, owner, n_tasks, n_task_runs, overall_progress, last_activity, n_results) = project_by_shortname(short_name) project_id = project.id project_button = add_custom_contrib_button_to(project, get_user_id_or_ip()) feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) autoimporter_enabled = feature_handler.autoimporter_enabled_for( current_user) project_sanitized, owner_sanitized = sanitize_project_owner( project_button, owner, current_user) form = Add_quiz() if request.method == "POST" and form.validate(): quiz_name = form.name.data q = quiz(name=quiz_name, project_id=project_id) db.session.add(q) db.session.commit() project.info.update({"is_quiz_provided": True}) project_repo.update(project) session['quiz_name'] = quiz_name session['quiz_id'] = models.quiz.query.filter_by( name=quiz_name, project_id=project_id).first().quiz_id flash("Sucessfully created quiz", "success") return redirect(url_for('quiz.quiz_form', short_name=short_name)) return render_template("add_quiz.html", title="create quiz", form=form, project=project_sanitized, pro_features=pro_features())
def test_only_for_pro_returns_False_if_feature_is_for_everyone(self): pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.only_for_pro('auditlog') is False
def test_only_for_pro_returns_True_if_feature_is_only_for_pro(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.only_for_pro('auditlog') is True
def test_better_stats_enabled_for_non_pro_owner_and_anonym_user_returns_True_if_disabled( self): pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.better_stats_enabled_for( self.anonymous, self.no_pro) is True
def test_better_stats_enabled_for_non_pro_owner_and_non_pro_user_returns_False_if_enabled( self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.better_stats_enabled_for( self.no_pro, self.no_pro) is False
def test_autoimporter_enabled_for_non_pro_returns_False_if_enabled(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.autoimporter_enabled_for( self.no_pro) is False
def test_webhooks_enabled_for_non_pro_returns_False_if_enabled(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.webhooks_enabled_for(self.no_pro) is False
def quiz_form(short_name): (project, owner, n_tasks, n_task_runs, overall_progress, last_activity, n_results) = project_by_shortname(short_name) form = Create_quiz() # Fetch appropriate form from forms.py project_button = add_custom_contrib_button_to(project, get_user_id_or_ip()) feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) autoimporter_enabled = feature_handler.autoimporter_enabled_for( current_user) project_sanitized, owner_sanitized = sanitize_project_owner( project_button, owner, current_user) if request.method == "POST" and form.validate(): #collecting data from forms.py que = form.question_text.data #collect the entered question text _file = request.files['file_field'] if _file and allowed_file(_file.filename): parent_path = current_app.root_path[:current_app.root_path. rfind("/")] _file.save( os.path.join((parent_path + '/uploads/' + CONTAINER), _file.filename)) file_path = '/uploads/' + CONTAINER + '/' + _file.filename option_A = form.oA.data #collect entered option A text option_B = form.oB.data #collect entered option B text option_C = form.oC.data #collect entered option C text option_D = form.oD.data #collect entered option D text correct_answer = form.correct_answer.data #collect entered correct answer # Based on entered answer, store the option text in the answer field in the database if correct_answer == 'A': correct_answer = option_A elif correct_answer == 'B': correct_answer = option_B elif correct_answer == 'C': correct_answer = option_C elif correct_answer == 'D': correct_answer = option_D category = form.category.data #collect entered question category q = question(quiz_id=session['quiz_id'], q_text=que, file_path=file_path, option1=option_A, option2=option_B, option3=option_C, option4=option_D, answer=correct_answer, category=category ) # Create object of class question from questions.py db.session.add(q) # Add object q to db.session db.session.commit() # Commit changes to app.db if request.form['submit'] == 'ADD': return redirect(url_for('quiz.quiz_form', short_name=short_name)) elif request.form['submit'] == 'SUBMIT': flash("Sucessfully added questions to " + session['quiz_name'], "success") return redirect(url_for('project.details', short_name=short_name)) return render_template("create_quiz.html", title="Add Question", quiz_name=session['quiz_name'], form=form, project=project_sanitized, pro_features=pro_features()) # Render form template