+ add_log.reset_mock()
+ report_store.log_http_request("method", "url", "body",
+ "headers", ValueError("Foo"))
+ add_log.assert_called_once_with({
+ 'type': 'http_request',
+ 'method': 'method',
+ 'url': 'url',
+ 'body': 'body',
+ 'headers': 'headers',
+ 'status': -1,
+ 'response': None,
+ 'error': 'ValueError',
+ 'error_message': 'Foo',
+ })
+
+ with self.subTest(no_http_dup=True, duplicate=True):
+ self.m.user_id = 1
+ self.m.market_id = 3
+ report_store = market.ReportStore(self.m, no_http_dup=True)
+ original_add_log = report_store.add_log
+ with mock.patch.object(report_store, "add_log", side_effect=original_add_log) as add_log:
+ report_store.log_http_request("method", "url", "body",
+ "headers", response)
+ report_store.log_http_request("method", "url", "body",
+ "headers", response)
+ self.assertEqual(2, add_log.call_count)
+ self.assertIsNone(add_log.mock_calls[0][1][0]["response_same_as"])
+ self.assertIsNone(add_log.mock_calls[1][1][0]["response"])
+ self.assertEqual(add_log.mock_calls[0][1][0]["date"], add_log.mock_calls[1][1][0]["response_same_as"])
+ with self.subTest(no_http_dup=True, duplicate=False, case="Different call"):
+ self.m.user_id = 1
+ self.m.market_id = 3
+ report_store = market.ReportStore(self.m, no_http_dup=True)
+ original_add_log = report_store.add_log
+ with mock.patch.object(report_store, "add_log", side_effect=original_add_log) as add_log:
+ report_store.log_http_request("method", "url", "body",
+ "headers", response)
+ report_store.log_http_request("method2", "url", "body",
+ "headers", response)
+ self.assertEqual(2, add_log.call_count)
+ self.assertIsNone(add_log.mock_calls[0][1][0]["response_same_as"])
+ self.assertIsNone(add_log.mock_calls[1][1][0]["response_same_as"])
+ with self.subTest(no_http_dup=True, duplicate=False, case="Call inbetween"):
+ self.m.user_id = 1
+ self.m.market_id = 3
+ report_store = market.ReportStore(self.m, no_http_dup=True)
+ original_add_log = report_store.add_log
+
+ response2 = mock.Mock()
+ response2.status_code = 200
+ response2.text = "Hey there!"
+
+ with mock.patch.object(report_store, "add_log", side_effect=original_add_log) as add_log:
+ report_store.log_http_request("method", "url", "body",
+ "headers", response)
+ report_store.log_http_request("method", "url", "body",
+ "headers", response2)
+ report_store.log_http_request("method", "url", "body",
+ "headers", response)
+ self.assertEqual(3, add_log.call_count)
+ self.assertIsNone(add_log.mock_calls[0][1][0]["response_same_as"])
+ self.assertIsNone(add_log.mock_calls[1][1][0]["response_same_as"])
+ self.assertIsNone(add_log.mock_calls[2][1][0]["response_same_as"])