Skip to content

Commit

Permalink
test: adding tests for existing group warning with same issues
Browse files Browse the repository at this point in the history
  • Loading branch information
anthraxx committed Feb 15, 2017
1 parent 50066cc commit 9c73d9c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/view/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from app.util import multiline_to_list


ERROR_GROUP_WITH_ISSUE_EXISTS = 'The group AVG-{} already contains {} for the package {}'


@app.route('/cve/add', methods=['GET', 'POST'])
@reporter_required
def add_cve():
Expand Down Expand Up @@ -62,7 +65,7 @@ def add_group():
same_group = same_group.all()
if same_group:
for group, cve, package in same_group:
flash('The group AVG-{} already contains {} for the package {}'
flash(ERROR_GROUP_WITH_ISSUE_EXISTS
.format(group.id, cve.id, package.pkgname), 'warning')
return render_template('form/group.html',
title='Add AVG',
Expand Down
31 changes: 31 additions & 0 deletions test/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from app.model.enum import UserRole, Affected, Status
from app.model.cve import CVE
from app.model.cvegroup import CVEGroup
from app.view.add import ERROR_GROUP_WITH_ISSUE_EXISTS


def set_and_assert_group_data(db, client, route):
Expand Down Expand Up @@ -110,3 +111,33 @@ def test_edit_group_not_found(db, client):
def test_group_packge_dropped_from_repo(db, client):
resp = client.get(url_for('show_group', avg=DEFAULT_GROUP_NAME), follow_redirects=True)
assert 200 == resp.status_code


@create_package(name='foo', version='1.2.3-4')
@create_group(id=DEFAULT_GROUP_ID, issues=[DEFAULT_ISSUE_ID], packages=['foo'])
@logged_in
def test_warn_on_add_group_with_existing_issue(db, client):
pkgnames = ['foo']
issues = ['CVE-1234-1234', 'CVE-2222-2222', DEFAULT_ISSUE_ID]
data = default_group_dict(dict(
cve='\n'.join(issues),
pkgnames='\n'.join(pkgnames)))

resp = client.post(url_for('add_group'), follow_redirects=True, data=data)
assert 200 == resp.status_code
assert ERROR_GROUP_WITH_ISSUE_EXISTS.format(DEFAULT_GROUP_ID, DEFAULT_ISSUE_ID, pkgnames[0]) in resp.data.decode()


@create_package(name='foo', version='1.2.3-4')
@create_group(id=DEFAULT_GROUP_ID, issues=[DEFAULT_ISSUE_ID], packages=['foo'])
@logged_in
def test_dont_warn_on_add_group_without_existing_issue(db, client):
pkgnames = ['foo']
issues = ['CVE-1234-1234', 'CVE-2222-2222']
data = default_group_dict(dict(
cve='\n'.join(issues),
pkgnames='\n'.join(pkgnames)))

resp = client.post(url_for('add_group'), follow_redirects=True, data=data)
assert 200 == resp.status_code
assert ERROR_GROUP_WITH_ISSUE_EXISTS.format(DEFAULT_GROUP_ID, DEFAULT_ISSUE_ID, pkgnames[0]) not in resp.data.decode()

0 comments on commit 9c73d9c

Please sign in to comment.