From 5e7ba16046773a0900aeda50bb209595a4c45746 Mon Sep 17 00:00:00 2001 From: Matias Piano Date: Fri, 22 Nov 2024 10:34:53 -0300 Subject: [PATCH] Fix on mocking bigquery.Client --- tests/test_cli.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index a9dbc76..b32f28a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -16,26 +16,30 @@ def __init__(self, **kwargs): class TestCli: - @utm.patch("pipe_events.utils.bigquery.BigqueryHelper") - def test_cli(self, mocked): + @utm.patch("pipe_events.utils.bigquery.BigqueryHelper", autospec=True) + @utm.patch("google.cloud.bigquery.Client", autospec=True) + def test_cli(self, mocked, m2): cl = cli.Cli(Args()) assert cl is not None - @utm.patch("pipe_events.utils.bigquery.BigqueryHelper") - def test_unknown_operation_main(self, mocked): + @utm.patch("pipe_events.utils.bigquery.BigqueryHelper", autospec=True) + @utm.patch("google.cloud.bigquery.Client", autospec=True) + def test_unknown_operation_main(self, mocked, m2): with pytest.raises(SystemExit) as err: utm.MagicMock(return_value=Args()) cli.main() assert err.value.code == 2 - @utm.patch("pipe_events.utils.bigquery.BigqueryHelper") - def test_invalid_operation_cli(self, mocked): + @utm.patch("pipe_events.utils.bigquery.BigqueryHelper", autospec=True) + @utm.patch("google.cloud.bigquery.Client", autospec=True) + def test_invalid_operation_cli(self, mocked, m2): with pytest.raises(RuntimeError): cl = cli.Cli(Args()) cl.run() - @utm.patch("pipe_events.utils.bigquery.BigqueryHelper") - def test_valid_operation_cli(self, mocked): + @utm.patch("pipe_events.utils.bigquery.BigqueryHelper", autospec=True) + @utm.patch("google.cloud.bigquery.Client", autospec=True) + def test_valid_operation_cli(self, mocked, m2): cl = cli.Cli(Args(operation='incremental_events')) cl._run_incremental_fishing_events = utm.MagicMock(return_value=1) assert cl.run() == 1 @@ -48,7 +52,8 @@ def test_valid_operation_cli(self, mocked): cl._run_restricted_view_fishing_events = utm.MagicMock(return_value=3) assert cl.run() == 3 - @utm.patch("pipe_events.utils.bigquery.BigqueryHelper") - def test_params(self, mocked): + @utm.patch("pipe_events.utils.bigquery.BigqueryHelper", autospec=True) + @utm.patch("google.cloud.bigquery.Client", autospec=True) + def test_params(self, mocked, m2): cl = cli.Cli(Args(operation='incremental_events')) assert cl._params == {'operation': 'incremental_events'}