Skip to content

Commit 9c73d9c

Browse files
committed
test: adding tests for existing group warning with same issues
1 parent 50066cc commit 9c73d9c

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

app/view/add.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
from app.util import multiline_to_list
88

99

10+
ERROR_GROUP_WITH_ISSUE_EXISTS = 'The group AVG-{} already contains {} for the package {}'
11+
12+
1013
@app.route('/cve/add', methods=['GET', 'POST'])
1114
@reporter_required
1215
def add_cve():
@@ -62,7 +65,7 @@ def add_group():
6265
same_group = same_group.all()
6366
if same_group:
6467
for group, cve, package in same_group:
65-
flash('The group AVG-{} already contains {} for the package {}'
68+
flash(ERROR_GROUP_WITH_ISSUE_EXISTS
6669
.format(group.id, cve.id, package.pkgname), 'warning')
6770
return render_template('form/group.html',
6871
title='Add AVG',

test/test_group.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from app.model.enum import UserRole, Affected, Status
66
from app.model.cve import CVE
77
from app.model.cvegroup import CVEGroup
8+
from app.view.add import ERROR_GROUP_WITH_ISSUE_EXISTS
89

910

1011
def set_and_assert_group_data(db, client, route):
@@ -110,3 +111,33 @@ def test_edit_group_not_found(db, client):
110111
def test_group_packge_dropped_from_repo(db, client):
111112
resp = client.get(url_for('show_group', avg=DEFAULT_GROUP_NAME), follow_redirects=True)
112113
assert 200 == resp.status_code
114+
115+
116+
@create_package(name='foo', version='1.2.3-4')
117+
@create_group(id=DEFAULT_GROUP_ID, issues=[DEFAULT_ISSUE_ID], packages=['foo'])
118+
@logged_in
119+
def test_warn_on_add_group_with_existing_issue(db, client):
120+
pkgnames = ['foo']
121+
issues = ['CVE-1234-1234', 'CVE-2222-2222', DEFAULT_ISSUE_ID]
122+
data = default_group_dict(dict(
123+
cve='\n'.join(issues),
124+
pkgnames='\n'.join(pkgnames)))
125+
126+
resp = client.post(url_for('add_group'), follow_redirects=True, data=data)
127+
assert 200 == resp.status_code
128+
assert ERROR_GROUP_WITH_ISSUE_EXISTS.format(DEFAULT_GROUP_ID, DEFAULT_ISSUE_ID, pkgnames[0]) in resp.data.decode()
129+
130+
131+
@create_package(name='foo', version='1.2.3-4')
132+
@create_group(id=DEFAULT_GROUP_ID, issues=[DEFAULT_ISSUE_ID], packages=['foo'])
133+
@logged_in
134+
def test_dont_warn_on_add_group_without_existing_issue(db, client):
135+
pkgnames = ['foo']
136+
issues = ['CVE-1234-1234', 'CVE-2222-2222']
137+
data = default_group_dict(dict(
138+
cve='\n'.join(issues),
139+
pkgnames='\n'.join(pkgnames)))
140+
141+
resp = client.post(url_for('add_group'), follow_redirects=True, data=data)
142+
assert 200 == resp.status_code
143+
assert ERROR_GROUP_WITH_ISSUE_EXISTS.format(DEFAULT_GROUP_ID, DEFAULT_ISSUE_ID, pkgnames[0]) not in resp.data.decode()

0 commit comments

Comments
 (0)