async def test_update_previous_value(self): with patch.object(FoglampProcess, '__init__'): with patch.object(logger, "setup"): sh = StatisticsHistory() sh._storage_async = MagicMock(spec=StorageClientAsync) payload = {'updates': [{'where': {'value': 'Bla', 'condition': '=', 'column': 'key'}, 'values': {'previous_value': 1}}]} with patch.object(sh._storage_async, "update_tbl", return_value=mock_coro(None)) as patch_storage: await sh._bulk_update_previous_value(payload) args, kwargs = patch_storage.call_args assert "statistics" == args[0] payload = ast.literal_eval(args[1]) assert "Bla" == payload["updates"][0]["where"]["value"] assert 1 == payload["updates"][0]["values"]["previous_value"]
def test_update_previous_value(self): mockStorageClient = MagicMock(spec=StorageClient) with patch.object(FoglampProcess, '__init__'): with patch.object(logger, "setup"): sh = StatisticsHistory() sh._storage = mockStorageClient with patch.object(sh._storage, "update_tbl", return_value=None) as patch_storage: sh._update_previous_value(key='Bla', value=1) args, kwargs = patch_storage.call_args assert args[0] == "statistics" payload = ast.literal_eval(args[1]) assert payload["where"]["value"] == "Bla" assert payload["values"]["previous_value"] == 1
async def _stats_history_instance(): mock_storage_client = MagicMock(spec=StorageClientAsync) mock_audit_logger = AuditLogger(mock_storage_client) with patch.object(FoglampProcess, "__init__"): with patch.object(logger, "setup"): with patch.object(mock_audit_logger, "__init__", return_value=None): stats = StatisticsHistory() return stats
async def test_run(self): with patch.object(FoglampProcess, '__init__'): with patch.object(logger, "setup"): sh = StatisticsHistory() sh._storage_async = MagicMock(spec=StorageClientAsync) retval = {'count': 2, 'rows': [{'description': 'Readings removed from the buffer by the purge process', 'value': 0, 'key': 'PURGED', 'previous_value': 0, 'ts': '2018-08-31 17:03:17.597055+05:30'}, {'description': 'Readings received by FogLAMP', 'value': 0, 'key': 'READINGS', 'previous_value': 0, 'ts': '2018-08-31 17:03:17.597055+05:30' }] } with patch.object(sh._storage_async, "query_tbl", return_value=mock_coro(retval)) as mock_keys: with patch.object(sh, "_bulk_update_previous_value", return_value=mock_coro(None)) as mock_update: with patch.object(sh._storage_async, "insert_into_tbl", return_value=mock_coro(None)) as mock_bulk_insert: await sh.run() assert 1 == mock_bulk_insert.call_count assert 1 == mock_update.call_count mock_keys.assert_called_once_with('statistics')