Skip to content

Commit

Permalink
Fix on mocking bigquery.Client
Browse files Browse the repository at this point in the history
  • Loading branch information
smpiano committed Nov 22, 2024
1 parent 2bf0406 commit 5e7ba16
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'}

0 comments on commit 5e7ba16

Please sign in to comment.