Skip to content

Commit

Permalink
Merge pull request #168 from tisnik/fix-for-issue-159
Browse files Browse the repository at this point in the history
Fix for issue #159
  • Loading branch information
tisnik authored Mar 21, 2019
2 parents 6b5d5b2 + 1cf2dda commit 4064df1
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from src.utils import (
DatabaseIngestion, alert_user, fetch_public_key, get_session, get_session_retry,
retrieve_worker_result, scan_repo, server_run_flow, validate_request_data,
fix_gremlin_output, generate_comparison
fix_gremlin_output, generate_comparison, get_first_query_result
)

from unittest.mock import patch
Expand Down Expand Up @@ -305,3 +305,33 @@ def test_generate_comparison(_mock1):
"""Test generate_comparison()."""
result = generate_comparison(2)
assert(result.get('average_response_time') is not None)


class QueryResultMock():
"""Class that mocks QueryResult class."""

def __init__(self):
"""Initialize the mocked QueryResult class."""
self.first_called = False

def first(self):
"""Implement the tested method with tracepoint variable."""
self.first_called = True
return "X"

def get_first_called(self):
"""Return the actual state of tracepoint variable."""
return self.first_called


def test_get_first_query_result():
"""Test the function get_first_query_result()."""
query_result_mock = QueryResultMock()
# make sure the first() was not called
assert not query_result_mock.get_first_called()

# this is a value returned by mocked class
assert get_first_query_result(query_result_mock) == "X"

# now first() was called, so check it
assert query_result_mock.get_first_called()

0 comments on commit 4064df1

Please sign in to comment.