Permalink
Browse files

[FEATURE] Delete Category (#241)

  • Loading branch information...
MatejMecka authored and canihavesomecoffee committed Nov 5, 2018
1 parent 5176d56 commit 9e90d3f4825d7d5631389092fb9dc2d52bf856ea
@@ -4,14 +4,13 @@
In this module, we are trying to create, update, edit, delete and
other various operations on regression tests.
"""
from flask import Blueprint, g, abort, jsonify, abort, redirect, url_for, request, flash
from decorators import template_renderer
from mod_auth.controllers import login_required, check_access_rights
from mod_auth.models import Role
from mod_regression.models import Category, RegressionTest, InputType, OutputType
from mod_regression.forms import AddCategoryForm, AddTestForm
from mod_regression.forms import AddCategoryForm, AddTestForm, ConfirmationForm
from mod_sample.models import Sample
mod_regression = Blueprint('regression', __name__)
@@ -25,7 +24,6 @@ def before_app_request():
'route': 'regression.index'
}
@mod_regression.route('/')
@template_renderer()
def index():
@@ -134,10 +132,33 @@ def test_add():
return redirect(url_for('.index'))
return {'form': form}
@mod_regression.route('/category/<category_id>/delete')
@mod_regression.route('/category/<category_id>/delete', methods=['GET', 'POST'])
@template_renderer()
@check_access_rights([Role.contributor, Role.admin])
def category_delete(category_id):
# Delete a regression test category
pass
"""
Delete the category
:param category_id: The ID of the Category
:type int
:return: Redirect
"""
category = Category.query.filter(Category.id == category_id).first()
if category is None:
abort(404)
form = ConfirmationForm()
if form.validate_on_submit():
g.db.delete(category)
g.db.commit()
return redirect(url_for('.index'))
return {
'form': form,
'category': category
}
@mod_regression.route('/category/<category_id>/edit', methods=['GET', 'POST'])
View
@@ -1,5 +1,5 @@
from flask_wtf import FlaskForm
from wtforms import Form, StringField, SubmitField, SelectField, validators,IntegerField
from wtforms import Form, StringField, SubmitField, SelectField, validators, IntegerField, HiddenField
from wtforms.validators import DataRequired, Email, ValidationError, NumberRange
from mod_sample.models import Sample
from mod_regression.models import InputType, OutputType, Category
@@ -34,3 +34,10 @@ class AddTestForm(FlaskForm):
expected_rc = IntegerField("Expected Runtime Code",
[DataRequired(message="Expected Runtime Code can't be empty")])
submit = SubmitField("Add Regression Test")
class ConfirmationForm(FlaskForm):
"""
Flask Form Used for Asking Confirmations
"""
confirm = HiddenField('nesho', default='yes') # nesho = something
submit = SubmitField('Confirm')
View
@@ -14,4 +14,4 @@ xmltodict
lxml
pytz
tzlocal
libvirt-python; sys_platform != 'win32'
libvirt-python; sys_platform != 'win32'
@@ -0,0 +1,37 @@
{% extends "base.html" %}
{% block title %}Category Delete {{ super() }}{% endblock %}
{% block body %}
{{ super() }}
<br />
<div class="grid-x">
<div class="callout warning">
<h5>Category Delete</h5>
<p>Are you sure you want to delete this? This change is irreversible!</p>
</div>
</div>
<form method="post" name="confirmationForm" id="confirmationForm" action="{{ url_for('.category_delete',category_id=category_id) }}">
{{ form.csrf_token }}
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<div class="grid-x">
<div class="callout alert">
<ul class="flashes">
{% for category, message in messages %}
<li class="{{ category }}">{{ message }}</li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
{% endwith %}
<div class="grid-x">
<div class="medium-12 columns" style="display:none;">
{{ macros.render_field(form.confirm) }}
</div>
<div class="medium-12 columns">
{{ macros.render_field(form.submit) }}
</div>
</div>
</form>
{% endblock %}
@@ -195,3 +195,48 @@ def test_add_test_empty_erc(self):
submit = True,
))
self.assertEqual(RegressionTest.query.filter(RegressionTest.id==3).first(),None)
def test_category_delete_if_will_abort_due_to_lack_of_permission(self):
"""
This will test if it will abort on lack of permission
:return:
"""
response = self.app.test_client().get('/regression/category/9432/delete')
self.assertEqual(response.status_code, 500)
def test_category_delete_if_will_throw_404(self):
"""
Check if it will throw an error 404
:return:
"""
self.create_user_with_role(
self.user.name, self.user.email, self.user.password, Role.admin)
with self.app.test_client() as c:
response = c.post(
'/account/login', data=self.create_login_form_data(self.user.email, self.user.password))
response_regression = c.get('/regression/category/9432/delete')
self.assertEqual(response_regression.status_code, 404)
def test_category_delete(self):
"""
Check it will delete the Category
:return:
"""
# Create Account to Delete Category
self.create_user_with_role(
self.user.name, self.user.email, self.user.password, Role.admin)
# Delete Category
with self.app.test_client() as c:
response = c.post(
'/account/login', data=self.create_login_form_data(self.user.email, self.user.password))
response_regression = c.get('/regression/category/1/delete')
self.assertEqual(response_regression.status_code, 200)
response = c.post(
'/regression/category/1/delete', data=dict(
hidden='yes',
submit=True
)
)
self.assertEqual(response_regression.status_code, 200)

0 comments on commit 9e90d3f

Please sign in to comment.