Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 606464669
  • Loading branch information
Chronicle Team authored and bumblebee211196 committed Feb 16, 2024
1 parent f03b71b commit 31ab875
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions common/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from common import chronicle_auth

REGION_LIST = [
"ASIA-NORTHEAST1",
"ASIA-SOUTH1",
"ASIA-SOUTHEAST1",
"AUSTRALIA-SOUTHEAST1",
Expand Down
2 changes: 2 additions & 0 deletions feeds/feed_schema_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def get_latest_schema(self) -> Dict[str, Any]:
if status_code != status.STATUS_OK:
error_message = response[key_constants.KEY_ERROR][
key_constants.KEY_MESSAGE]
if status_code == status.STATUS_NOT_FOUND:
error_message += "\nIs the region specified correctly?"
raise Exception(error_message)
return response

Expand Down
21 changes: 20 additions & 1 deletion feeds/feed_schema_utility_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ def test_get_latest_schema(get_schema_response: List[Any],
assert client.get_latest_schema() == expected_output


def test_get_latest_schema_not_found(client: feed_schema_utility.FeedSchema):
"""Test case to check handling of error while fetching feed schema.
Args:
client: Patch object of class FeedSchema.
"""
client.client.request.return_value = MockResponse(
status_code=404, text='{"error": {"message": "customer not found"}}'
)
with pytest.raises(Exception) as not_found_err:
client.get_latest_schema()
assert (
not_found_err.value.args[0]
== "customer not found\nIs the region specified correctly?"
)


def test_get_latest_schema_400(client: feed_schema_utility.FeedSchema):
"""Test case to check handling of error while fetching feed schema.
Expand All @@ -48,9 +65,11 @@ def test_get_latest_schema_400(client: feed_schema_utility.FeedSchema):
"""
client.client.request.return_value = MockResponse(
status_code=400, text='{"error": {"message": "400 error"}}')
with pytest.raises(Exception):
with pytest.raises(Exception) as error:
client.get_latest_schema()

assert error.value.args[0] == "400 error"


def test_get_detailed_schema_success(client: feed_schema_utility.FeedSchema,
get_detailed_schema_input: Dict[str, str]):
Expand Down
18 changes: 16 additions & 2 deletions parsers/commands/list_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@

ALL_STATE = "ALL"
STATE_LIST = [ALL_STATE, "ACTIVE", "INACTIVE"]
TYPE = "CUSTOM"
ALL_TYPE = "ALL"
TYPE_LIST = [ALL_TYPE, "CUSTOM", "PREBUILT"]


@click.command(name="list_parsers",
Expand All @@ -46,6 +47,14 @@
help="Filter on Parser State",
required=False
)
@click.option(
"-pt",
"--parser-type",
type=click.Choice(TYPE_LIST, case_sensitive=False),
default=TYPE_LIST[0],
help="Filter on Parser Type",
required=False
)
@click.option(
"-f",
"--file-format",
Expand Down Expand Up @@ -73,6 +82,7 @@ def list_parsers(
customer_id: str,
log_type: str,
state: str,
parser_type: str,
file_format: str) -> None:
"""List all parsers of a given customer.
Expand All @@ -89,6 +99,8 @@ def list_parsers(
log_type (str): The Log Type.
state (str): Option for selecting states. Available options - ALL, ACTIVE,
INACTIVE.
parser_type (str): Option for selecting type. Available options - ALL,
CUSTOM, PREBUILT.
file_format (str): Options for selecting the format of the content to be
exported. Availabel options - TXT, JSON.
Expand Down Expand Up @@ -122,9 +134,11 @@ def list_parsers(
"log_type": log_type,
}
# Set filter
filter_options = {"TYPE": TYPE}
filter_options = {}
if state != ALL_STATE:
filter_options["STATE"] = state
if parser_type != ALL_TYPE:
filter_options["TYPE"] = parser_type

list_parser_url = url.get_dataplane_url(
region,
Expand Down
2 changes: 1 addition & 1 deletion parsers/commands/list_parsers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_list_parsers(
""" == result.output
mock_get_dataplane_url.assert_called_once_with(
"US", "list_parsers", "prod",
RESOURCES, filter="TYPE = CUSTOM", page_size=1000)
RESOURCES, filter="", page_size=1000)
mock_http_session.return_value.request.assert_called_once_with(
"GET", LIST_URL, timeout=url.HTTP_REQUEST_TIMEOUT_IN_SECS)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ pytest==7.2.0
pytest-cov==3.0.0
pyyaml==6.0.0
stringcase==1.2.0
wheel

0 comments on commit 31ab875

Please sign in to comment.