Skip to content

Commit

Permalink
Count unique warnings only to avoid omitting unique warnings (issue g…
Browse files Browse the repository at this point in the history
  • Loading branch information
yaelmi3 committed Aug 5, 2020
1 parent aa6af6c commit cc0553c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion flask_app/blueprints/api/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ def add_warning(message:str, filename:str=None, lineno:int=None, test_id:int=Non
timestamp = get_current_time()

warning = Warning.query.filter_by(session_id=session_id, test_id=test_id, lineno=lineno, filename=filename, message=message).first()
unique_warnings_num = len(Warning.query.filter_by(session_id=session_id, test_id=test_id).all())
if warning is None:
if obj.num_warnings < current_app.config['MAX_WARNINGS_PER_ENTITY']:
if unique_warnings_num < current_app.config['MAX_WARNINGS_PER_ENTITY']:
warning = Warning(message=message, timestamp=timestamp, filename=filename, lineno=lineno, test_id=test_id, session_id=session_id)
db.session.add(warning)
else:
Expand Down
19 changes: 16 additions & 3 deletions tests/test_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,30 @@ def test_add_warnings_nonexistent_session(warning_container, message):
warning_container.add_warning(message=message)


def test_max_warnings_per_entity(warning_container, message, webapp):
@pytest.mark.parametrize("unique_warning", [True, False])
def test_max_warnings_per_entity(warning_container, message, webapp, unique_warning):
max_warnings = 3
webapp.app.config['MAX_WARNINGS_PER_ENTITY'] = max_warnings

for i in range(max_warnings + 1):
warning_container.add_warning(message=f'{message}{i}' )
warning_container.add_warning(message=f'{message}{i if not unique_warning else ""}')

warning_container.refresh()
assert warning_container.num_warnings == max_warnings + 1
assert len(warning_container.query_warnings().all()) == 1 if unique_warning else max_warnings

assert len(warning_container.query_warnings().all()) == max_warnings

def test_unique_warning_per_entity(warning_container, webapp):
max_warnings = 3
webapp.app.config['MAX_WARNINGS_PER_ENTITY'] = max_warnings

for i in range(max_warnings):
warning_container.add_warning(message=message)
warning_container.add_warning(message="unique warning")

warning_container.refresh()
assert warning_container.num_warnings == max_warnings + 1
assert len(warning_container.query_warnings().all()) == 2


def test_add_warning_twice(warning_container, filename, lineno, message, timestamp):
Expand Down

0 comments on commit cc0553c

Please sign in to comment.