|
1 | 1 | import json
|
2 | 2 | import pytest
|
| 3 | +from py42.sdk.queries.fileevents.filters import FileCategory |
3 | 4 | from requests import Response
|
4 | 5 | from py42.sdk import SDKClient
|
5 | 6 | from py42.response import Py42Response
|
| 7 | +from py42.sdk.queries.alerts.filters import Severity |
6 | 8 | from Code42 import (
|
7 | 9 | Code42Client,
|
8 | 10 | Code42LegalHoldMatterNotFoundError,
|
9 | 11 | Code42InvalidLegalHoldMembershipError,
|
| 12 | + get_file_category_value, |
10 | 13 | build_query_payload,
|
11 | 14 | map_observation_to_security_query,
|
12 | 15 | map_to_code42_event_context,
|
|
476 | 479 | "fileCount": 3,
|
477 | 480 | "totalFileSize": 533846,
|
478 | 481 | "isSignificant": true
|
| 482 | + }, |
| 483 | + { |
| 484 | + "type$": "OBSERVED_FILE_CATEGORY", |
| 485 | + "category": "Pdf", |
| 486 | + "fileCount": 3, |
| 487 | + "totalFileSize": 533846, |
| 488 | + "isSignificant": true |
479 | 489 | }
|
480 | 490 | ],
|
481 | 491 | "files": [
|
|
723 | 733 | "filters": [{"operator": "IS", "term": "exposure", "value": "ApplicationRead"}],
|
724 | 734 | },
|
725 | 735 | {
|
726 |
| - "filterClause": "AND", |
727 |
| - "filters": [{"operator": "IS", "term": "fileCategory", "value": "SOURCE_CODE"}], |
728 |
| - }, |
| 736 | + "filterClause": "OR", |
| 737 | + "filters": [ |
| 738 | + {"operator": "IS", "term": "fileCategory", "value": "PDF"}, |
| 739 | + {"operator": "IS", "term": "fileCategory", "value": "SOURCE_CODE"} |
| 740 | + ] |
| 741 | + } |
729 | 742 | ],
|
730 | 743 | "pgNum": 1,
|
731 | 744 | "pgSize": 10000,
|
@@ -1347,6 +1360,48 @@ def assert_detection_list_outputs_match_response_items(outputs_list, response_it
|
1347 | 1360 | """TESTS"""
|
1348 | 1361 |
|
1349 | 1362 |
|
| 1363 | +def test_get_file_category_value_handles_screaming_snake_case(): |
| 1364 | + actual = get_file_category_value("SOURCE_CODE") |
| 1365 | + expected = FileCategory.SOURCE_CODE |
| 1366 | + assert actual == expected |
| 1367 | + |
| 1368 | + |
| 1369 | +def test_get_file_category_value_handles_capitalized_case(): |
| 1370 | + actual = get_file_category_value("Pdf") |
| 1371 | + expected = FileCategory.PDF |
| 1372 | + assert actual == expected |
| 1373 | + |
| 1374 | + |
| 1375 | +def test_get_file_category_value_handles_lower_case(): |
| 1376 | + actual = get_file_category_value("pdf") |
| 1377 | + expected = FileCategory.PDF |
| 1378 | + assert actual == expected |
| 1379 | + |
| 1380 | + |
| 1381 | +def test_get_file_category_value_handles_upper_case(): |
| 1382 | + actual = get_file_category_value("PDF") |
| 1383 | + expected = FileCategory.PDF |
| 1384 | + assert actual == expected |
| 1385 | + |
| 1386 | + |
| 1387 | +def test_get_file_category_value_handles_pascal_case(): |
| 1388 | + actual = get_file_category_value("SourceCode") |
| 1389 | + expected = FileCategory.SOURCE_CODE |
| 1390 | + assert actual == expected |
| 1391 | + |
| 1392 | + |
| 1393 | +def test_get_file_category_value_handles_hungarian_case(): |
| 1394 | + actual = get_file_category_value("sourceCode") |
| 1395 | + expected = FileCategory.SOURCE_CODE |
| 1396 | + assert actual == expected |
| 1397 | + |
| 1398 | + |
| 1399 | +def test_get_file_category_value_handles_hyphenated_case(): |
| 1400 | + actual = get_file_category_value("source-code") |
| 1401 | + expected = FileCategory.SOURCE_CODE |
| 1402 | + assert actual == expected |
| 1403 | + |
| 1404 | + |
1350 | 1405 | def test_client_lazily_inits_sdk(mocker, code42_sdk_mock):
|
1351 | 1406 | sdk_factory_mock = mocker.patch("py42.sdk.from_local_account")
|
1352 | 1407 | response_json_mock = """{"total": 1, "users": [{"username": "Test"}]}"""
|
@@ -1992,8 +2047,8 @@ def test_fetch_incidents_handles_multi_severity(code42_fetch_incidents_mock):
|
1992 | 2047 | integration_context=None,
|
1993 | 2048 | )
|
1994 | 2049 | call_args = str(code42_fetch_incidents_mock.alerts.search.call_args[0][0])
|
1995 |
| - assert "HIGH" in call_args |
1996 |
| - assert "LOW" in call_args |
| 2050 | + assert Severity.HIGH in call_args |
| 2051 | + assert Severity.LOW in call_args |
1997 | 2052 |
|
1998 | 2053 |
|
1999 | 2054 | def test_fetch_when_include_files_includes_files(code42_fetch_incidents_mock):
|
|
0 commit comments