Skip to content

Instantly share code, notes, and snippets.

@deepak1725
Created October 31, 2019 12:46
Show Gist options
  • Save deepak1725/2d7fe9bbc4950541f08d65c776363350 to your computer and use it in GitHub Desktop.
Save deepak1725/2d7fe9bbc4950541f08d65c776363350 to your computer and use it in GitHub Desktop.
def mock_db_post(*_args, **_kwargs):
class MockPostgres:
"""Mock response object."""
def __init__(self, json_data):
"""Create a mock json response."""
self.json_data = json_data
def execute(self):
"""Get the mock json response."""
return None
def conn(self):
"""Get the mock json response."""
return None
def cursor(self):
"""Get the mock json response."""
fetch_all = self.fetch_all
return None
@property
def fetch_all(self):
return self.json_data
return MockPostgres(stackdata)
def mock_graph_post(*_args, **_kwargs):
"""Mock the call to the insights service."""
class MockResponse:
"""Mock response object."""
def __init__(self, json_data, status_code):
"""Create a mock json response."""
self.status_code = status_code
return MockResponse(stackdata, 200)
@mock.patch('f8a_report.report_helper.Postgres')
@mock.patch('f8a_report.report_helper.ReportHelper')
def test_retrieve_stack_analyses_ids(_mock1, _mock2):
"""Test retrieve stack data function."""
_mock1.side_effect = mock_db_post
_mock2.side_effect = mock_graph_post
ids = r.retrieve_stack_analyses_ids('2018-10-09','2018-10-09')
print("Ids", ids)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment