Skip to content

Commit ad40aa5

Browse files
add subgroups for search filters
1 parent 8295d32 commit ad40aa5

File tree

3 files changed

+120
-5
lines changed

3 files changed

+120
-5
lines changed

src/_incydr_sdk/core/settings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ class IncydrSettings(BaseSettings):
5050
Usage:
5151
5252
>> import incydr
53-
>>> client = incydr.Client()
54-
>>> client.settings.page_size = 10
53+
>>> client = incydr.Client(page_size = 10)
5554
5655
Settings can also be loaded from shell environment variables or .env files. Just prefix a setting's attribute name
5756
with `INCYDR_` when configuring via enviroment vars.

src/_incydr_sdk/file_events/models/response.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from datetime import datetime
24
from typing import List
35
from typing import Optional
@@ -32,6 +34,17 @@ class SearchFilterGroup(ResponseModel):
3234
)
3335

3436

37+
class SearchFilterGroupV2(ResponseModel):
38+
subgroup_clause: Optional[str] = Field(
39+
alias="subgroupClause",
40+
description="Grouping clause for subgroups.",
41+
example="AND",
42+
)
43+
subgroups: Optional[List[Union[SearchFilterGroup, SearchFilterGroupV2]]] = Field(
44+
description="One or more FilterGroups to be combined in a query, or a FilterSubgroupV2"
45+
)
46+
47+
3548
class QueryProblem(ResponseModel):
3649
"""
3750
A model containing data on a query problem.
@@ -99,7 +112,7 @@ class SavedSearch(ResponseModel):
99112
* **created_by_username**: `str` - The username of the user who created the saved search.
100113
* **creation_timestamp**: `datetime` - The time at which the saved search was created.
101114
* **group_clause**: `GroupClause` - `AND` or `OR`. Grouping clause for any specified groups. Defaults to `AND`.
102-
* **groups**: `List[SearchFilterGroup]` - One or more FilterGroups to be combined in a query.
115+
* **groups**: `List[Union[SearchFilterGroup, SearchFilterGroupV2]]` - One or more FilterGroups or FilterGroupV2s to be combined in a query.
103116
* **id**: `str` - The ID for the saved search.
104117
* **modified_by_uid**: `str` - The ID of the user who last modified the saved search.
105118
* **modified_by_username**: `str` - The username of the user who last modified the saved search.
@@ -139,7 +152,7 @@ class SavedSearch(ResponseModel):
139152
description="Grouping clause for any specified groups.",
140153
example="OR",
141154
)
142-
groups: Optional[List[SearchFilterGroup]] = Field(
155+
groups: Optional[List[Union[SearchFilterGroup, SearchFilterGroupV2]]] = Field(
143156
description="One or more FilterGroups to be combined in a query."
144157
)
145158
id: Optional[str] = Field(

tests/test_file_events.py

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,93 @@
406406
srt_key=None,
407407
tenantId="c4e43418-07d9-4a9f-a138-29f39a124d33",
408408
)
409-
409+
TEST_SAVED_SEARCH_3 = SavedSearch().parse_obj(
410+
{
411+
"apiVersion": 2,
412+
"columns": None,
413+
"createdByUID": "testcreatoruid",
414+
"createdByUsername": "example@code42.com",
415+
"creationTimestamp": "2025-02-04T15:36:59.926404Z",
416+
"groupClause": "AND",
417+
"groups": [
418+
{
419+
"filterClause": "AND",
420+
"filters": [
421+
{
422+
"operator": "WITHIN_THE_LAST",
423+
"term": "@timestamp",
424+
"value": "P90D",
425+
"display": None,
426+
}
427+
],
428+
"display": '{"data":{"isMultivalue":false},"version":"v2"}',
429+
},
430+
{
431+
"filterClause": "OR",
432+
"filters": [
433+
{
434+
"operator": "IS",
435+
"term": "file.category",
436+
"value": "Image",
437+
"display": None,
438+
}
439+
],
440+
"display": '{"data":{"isMultivalue":true},"version":"v2"}',
441+
},
442+
{
443+
"subgroupClause": "OR",
444+
"subgroups": [
445+
{
446+
"subgroupClause": "AND",
447+
"subgroups": [
448+
{
449+
"filterClause": "AND",
450+
"filters": [
451+
{
452+
"operator": "IS",
453+
"term": "file.name",
454+
"value": "*gomez*",
455+
"display": None,
456+
}
457+
],
458+
"display": '{"data":{"isMultivalue":false},"version":"v2"}',
459+
}
460+
],
461+
"display": None,
462+
},
463+
{
464+
"subgroupClause": "AND",
465+
"subgroups": [
466+
{
467+
"filterClause": "AND",
468+
"filters": [
469+
{
470+
"operator": "IS",
471+
"term": "file.name",
472+
"value": "*Ticia*",
473+
"display": None,
474+
}
475+
],
476+
"display": '{"data":{"isMultivalue":false},"version":"v2"}',
477+
}
478+
],
479+
"display": None,
480+
},
481+
],
482+
"display": None,
483+
},
484+
],
485+
"id": "test-search-id",
486+
"modifiedByUID": "test-modified-uid",
487+
"modifiedByUsername": "example@code42.com",
488+
"modifiedTimestamp": "2025-02-04T15:36:59.926404Z",
489+
"name": "Chad Ticia/Gomez block saved search",
490+
"notes": "testing functionality of search blocks",
491+
"srtDir": "desc",
492+
"srtKey": None,
493+
"tenantId": "test-tenant-id",
494+
}
495+
)
410496

411497
TEST_DICT_QUERY = {
412498
"groupClause": "AND",
@@ -487,6 +573,14 @@ def mock_get_saved_search(httpserver_auth):
487573
).respond_with_json(search_data)
488574

489575

576+
@pytest.fixture
577+
def mock_get_saved_search_with_subgroups(httpserver_auth):
578+
search_data = {"searches": [json.loads(TEST_SAVED_SEARCH_3.json())]}
579+
httpserver_auth.expect_request(
580+
f"/v2/file-events/saved-searches/{TEST_SAVED_SEARCH_ID}", method="GET"
581+
).respond_with_json(search_data)
582+
583+
490584
@pytest.fixture
491585
def mock_list_saved_searches(httpserver_auth):
492586
search_data = {
@@ -559,6 +653,15 @@ def test_get_saved_search_returns_expected_data(mock_get_saved_search):
559653
assert search.json() == TEST_SAVED_SEARCH_1.json()
560654

561655

656+
def test_get_saved_search_returns_expected_data_when_search_has_subgroups(
657+
mock_get_saved_search_with_subgroups,
658+
):
659+
client = Client()
660+
search = client.file_events.v2.get_saved_search(TEST_SAVED_SEARCH_ID)
661+
assert isinstance(search, SavedSearch)
662+
assert search.json() == TEST_SAVED_SEARCH_3.json()
663+
664+
562665
# ************************************************ CLI ************************************************
563666

564667
format_arg = pytest.mark.parametrize(

0 commit comments

Comments
 (0)