Skip to content

Commit

Permalink
ENH: Raise error if kinds and exclude_kinds are provided at once
Browse files Browse the repository at this point in the history
skipci
  • Loading branch information
cortadocodes committed Aug 6, 2024
1 parent 7c1c65b commit c833934
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions octue/cloud/pub_sub/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ def _validate_inputs(question_uuid, parent_question_uuid, originator_question_uu
"provided."
)

kinds_inputs = (bool(kinds), bool(exclude_kinds))

if sum(kinds_inputs) > 1:
raise ValueError(
f"Only one of `kinds` and `exclude_kinds` can be provided at once; received kinds={kinds!r} and "
f"exclude_kinds={exclude_kinds!r}."
)

if kinds:
for kind in kinds:
if kind not in VALID_EVENT_KINDS:
Expand Down
7 changes: 6 additions & 1 deletion tests/cloud/pub_sub/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def test_error_if_more_than_one_question_uuid_type_provided(self):
with self.assertRaises(ValueError):
get_events(table_id="blah", **kwargs)

def test_error_raised_if_kinds_and_exclude_kinds_provided_together(self):
"""Test that an error is raised if both `kinds` and `exclude_kinds` are provided at once."""
with self.assertRaises(ValueError):
get_events(table_id="blah", question_uuid="blah", kinds=["result"], exclude_kinds=["question"])

def test_error_raised_if_kinds_invalid(self):
"""Test that an error is raised if the event kinds are invalid."""
for invalid_kinds in ["frisbee_tournament", ["frisbee_tournament"]]:
Expand Down Expand Up @@ -100,7 +105,7 @@ def test_with_kind(self):
)

def test_with_kinds(self):
"""Test the query used to retrieve events of pecific kinds."""
"""Test the query used to retrieve events of specific kinds."""
with patch("octue.cloud.pub_sub.bigquery.Client") as mock_client:
get_events(table_id="blah", question_uuid="blah", kinds=["result", "question"])

Expand Down

0 comments on commit c833934

Please sign in to comment.