Skip to content

Commit

Permalink
test: adding comprehensive tests for todo view
Browse files Browse the repository at this point in the history
  • Loading branch information
anthraxx committed May 30, 2018
1 parent dfeb85f commit ad1d8d6
Showing 1 changed file with 181 additions and 1 deletion.
182 changes: 181 additions & 1 deletion test/test_todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_todo_json_empty(db, client):
@create_package(name='foo', base='lol', version='1.2.3-4')
@create_package(name='bar', base='lol', version='1.2.3-4')
@create_group(id=DEFAULT_GROUP_ID, issues=['CVE-1111-1111'], packages=['foo', 'bar'], affected='1.2.3-3', fixed='1.2.3-4')
def test_todo_unhandled_advisory(db, client):
def test_todo_advisory_unhandled(db, client):
resp = client.get(url_for('tracker.todo_json', postfix='.json'))
assert 200 == resp.status_code

Expand All @@ -84,3 +84,183 @@ def test_todo_unhandled_advisory(db, client):
advisory = next(iter(data['advisories']['unhandled']))
assert advisory['name'] == DEFAULT_GROUP_NAME
assert advisory['status'] == Status.fixed


@create_issue(id='CVE-1111-1111', issue_type=issue_types[2])
@create_package(name='foo', base='lol', version='1.2.3-4')
@create_package(name='bar', base='lol', version='1.2.3-4')
@create_group(id=DEFAULT_GROUP_ID, issues=['CVE-1111-1111'], packages=['foo', 'bar'], affected='1.2.3-3', fixed='1.2.3-4')
@create_advisory(id=DEFAULT_ADVISORY_ID, group_package_id=2, publication=Publication.scheduled)
def test_todo_advisory_scheduled(db, client):
resp = client.get(url_for('tracker.todo_json', postfix='.json'))
assert 200 == resp.status_code

data = resp.get_json()
assert 1 == len(data['advisories']['scheduled'])

advisory = next(iter(data['advisories']['scheduled']))
assert advisory['name'] == DEFAULT_ADVISORY_ID
assert advisory['package'] == 'bar'


@create_issue(id='CVE-1111-1111', issue_type=issue_types[2])
@create_package(name='foo', base='lol', version='1.2.3-4')
@create_package(name='bar', base='lol', version='1.2.3-4')
@create_group(id=DEFAULT_GROUP_ID, issues=['CVE-1111-1111'], packages=['foo', 'bar'], affected='1.2.3-3', fixed='1.2.3-4')
@create_advisory(id=DEFAULT_ADVISORY_ID, group_package_id=2, publication=Publication.published)
def test_todo_advisory_incomplete(db, client):
resp = client.get(url_for('tracker.todo_json', postfix='.json'))
assert 200 == resp.status_code

data = resp.get_json()
assert 1 == len(data['advisories']['incomplete'])

advisory = next(iter(data['advisories']['incomplete']))
assert advisory['name'] == DEFAULT_ADVISORY_ID
assert advisory['package'] == 'bar'


@create_issue(id='CVE-1111-1111', issue_type=issue_types[2])
@create_package(name='foo', base='lol', version='1.2.3-4')
@create_package(name='bar', base='lol', version='1.2.3-4')
@create_group(id=DEFAULT_GROUP_ID, issues=['CVE-1111-1111'], packages=['foo', 'bar'], affected='1.2.3-3', fixed='1.2.3-4')
@create_advisory(id=DEFAULT_ADVISORY_ID, group_package_id=2, publication=Publication.published, content='broken!', impact='snafu', reference='https://foo.bar')
def test_todo_advisory_not_incomplete_with_data(db, client):
resp = client.get(url_for('tracker.todo_json', postfix='.json'))
assert 200 == resp.status_code

data = resp.get_json()
assert not data['advisories']['incomplete']


@create_issue(id='CVE-1111-1111', issue_type=issue_types[0])
@create_package(name='foo', base='lol', version='1.2.3-4')
@create_group(id=DEFAULT_GROUP_ID, issues=['CVE-1111-1111'], packages=['foo'], status=Status.unknown, affected='1.2.3-3', fixed='1.2.3-4')
def test_todo_group_unknown_by_status(db, client):
resp = client.get(url_for('tracker.todo_json', postfix='.json'))
assert 200 == resp.status_code

data = resp.get_json()
assert 1 == len(data['groups']['unknown'])

group = next(iter(data['groups']['unknown']))
assert DEFAULT_GROUP_NAME == group['name']
assert ['foo'] == group['packages']


@create_issue(id='CVE-1111-1111', issue_type=issue_types[1], severity=Severity.high)
@create_package(name='foo', base='lol', version='1.2.3-4')
@create_group(id=DEFAULT_GROUP_ID, issues=['CVE-1111-1111'], packages=['foo'], status=Status.vulnerable, affected='1.2.3-3', fixed='1.2.3-4')
def test_todo_group_not_unknown_with_data(db, client):
resp = client.get(url_for('tracker.todo_json', postfix='.json'))
assert 200 == resp.status_code

data = resp.get_json()
assert not data['groups']['unknown']


@create_issue(id='CVE-1111-1111', issue_type=issue_types[1])
@create_package(name='foo', base='lol', version='1.2.3-4')
@create_group(id=DEFAULT_GROUP_ID, issues=['CVE-1111-1111'], packages=['foo'], status=Status.vulnerable, affected='1.2.3-3')
def test_todo_group_bumped(db, client):
resp = client.get(url_for('tracker.todo_json', postfix='.json'))
assert 200 == resp.status_code

data = resp.get_json()
assert 1 == len(data['groups']['bumped'])

group = next(iter(data['groups']['bumped']))
assert DEFAULT_GROUP_NAME == group['name']
assert ['foo'] == group['packages']
assert '1.2.3-4' in group['current'].values()


@create_issue(id='CVE-1111-1111', issue_type=issue_types[1])
@create_package(name='foo', base='lol', version='1.2.3-3')
@create_group(id=DEFAULT_GROUP_ID, issues=['CVE-1111-1111'], packages=['foo'], status=Status.vulnerable, affected='1.2.3-3')
def test_todo_group_not_bumped_when_same(db, client):
resp = client.get(url_for('tracker.todo_json', postfix='.json'))
assert 200 == resp.status_code

data = resp.get_json()
assert not data['groups']['bumped']


@create_issue(id='CVE-1111-1111', issue_type=issue_types[2])
def test_todo_issues_orphan(db, client):
resp = client.get(url_for('tracker.todo_json', postfix='.json'))
assert 200 == resp.status_code

data = resp.get_json()
assert 1 == len(data['issues']['orphan_issues'])

issue = next(iter(data['issues']['orphan_issues']))
assert 'CVE-1111-1111' == issue['name']


@create_issue(id='CVE-1111-1111', issue_type=issue_types[2])
@create_package(name='foo', base='lol', version='1.2.3-3')
@create_group(id=DEFAULT_GROUP_ID, issues=['CVE-1111-1111'], packages=['foo'], status=Status.vulnerable, affected='1.2.3-3')
def test_todo_issues_referenced_not_orphan(db, client):
resp = client.get(url_for('tracker.todo_json', postfix='.json'))
assert 200 == resp.status_code

data = resp.get_json()
assert not data['issues']['orphan_issues']


@create_issue(id='CVE-1111-1111', issue_type=issue_types[2], remote=Remote.remote, severity=Severity.low, description='yay')
def test_todo_issues_not_unknown_with_data(db, client):
resp = client.get(url_for('tracker.todo_json', postfix='.json'))
assert 200 == resp.status_code

data = resp.get_json()
assert not data['issues']['unknown_issues']


@create_issue(id='CVE-1111-1111', issue_type=issue_types[0], remote=Remote.remote, severity=Severity.low, description='yay')
def test_todo_issues_unknown_without_type(db, client):
resp = client.get(url_for('tracker.todo_json', postfix='.json'))
assert 200 == resp.status_code

data = resp.get_json()
assert 1 == len(data['issues']['unknown_issues'])

issue = next(iter(data['issues']['unknown_issues']))
assert 'CVE-1111-1111' == issue['name']


@create_issue(id='CVE-1111-1111', issue_type=issue_types[1], remote=Remote.unknown, severity=Severity.low, description='yay')
def test_todo_issues_unknown_without_remote(db, client):
resp = client.get(url_for('tracker.todo_json', postfix='.json'))
assert 200 == resp.status_code

data = resp.get_json()
assert 1 == len(data['issues']['unknown_issues'])

issue = next(iter(data['issues']['unknown_issues']))
assert 'CVE-1111-1111' == issue['name']


@create_issue(id='CVE-1111-1111', issue_type=issue_types[0], remote=Remote.remote, severity=Severity.unknown, description='yay')
def test_todo_issues_unknown_without_severity(db, client):
resp = client.get(url_for('tracker.todo_json', postfix='.json'))
assert 200 == resp.status_code

data = resp.get_json()
assert 1 == len(data['issues']['unknown_issues'])

issue = next(iter(data['issues']['unknown_issues']))
assert 'CVE-1111-1111' == issue['name']


@create_issue(id='CVE-1111-1111', issue_type=issue_types[1], remote=Remote.remote, severity=Severity.low, description='')
def test_todo_issues_unknown_without_description(db, client):
resp = client.get(url_for('tracker.todo_json', postfix='.json'))
assert 200 == resp.status_code

data = resp.get_json()
assert 1 == len(data['issues']['unknown_issues'])

issue = next(iter(data['issues']['unknown_issues']))
assert 'CVE-1111-1111' == issue['name']

0 comments on commit ad1d8d6

Please sign in to comment.