Skip to content

Commit

Permalink
Feature/add sync destination username filter (#329)
Browse files Browse the repository at this point in the history
* Add filter for sync destination username to file event search

* Add docstring

* Changelog

* Change test domains to example.com

* Clean up docstring
  • Loading branch information
peterbriggs42 committed Jun 10, 2021
1 parent 9dfdb2e commit 0ccb101
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ how a consumer would use the library (e.g. adding unit tests, updating documenta
method `sdk.detectionlists.create_user()` due to the user not existing in Code42 or
is already in the process of being created on the back-end.

- `SyncDestinationUsername` filter class to `py42.sdk.queries.fileevents.filters.exposure_filter` module.

## 1.14.2 - 2021-05-07

### Fixed
Expand Down
8 changes: 8 additions & 0 deletions src/py42/sdk/queries/fileevents/filters/exposure_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ def choices():
return get_attribute_keys_from_class(SyncDestination)


class SyncDestinationUsername(FileEventFilterStringField):
"""Class that filters events based on the username associated with the cloud service
the file is synced with (applies to ``synced to cloud service`` events only).
"""

_term = u"syncDestinationUsername"


class TabURL(FileEventFilterStringField):
"""Class that filters events based on all the URLs of the browser tabs at the time the file
contents were read by the browser (applies to ``read by browser or other app`` events only).
Expand Down
39 changes: 39 additions & 0 deletions tests/sdk/queries/fileevents/filters/test_exposure_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from py42.sdk.queries.fileevents.filters.exposure_filter import RemovableMediaVendor
from py42.sdk.queries.fileevents.filters.exposure_filter import RemovableMediaVolumeName
from py42.sdk.queries.fileevents.filters.exposure_filter import SyncDestination
from py42.sdk.queries.fileevents.filters.exposure_filter import SyncDestinationUsername
from py42.sdk.queries.fileevents.filters.exposure_filter import TabURL
from py42.sdk.queries.fileevents.filters.exposure_filter import WindowTitle

Expand Down Expand Up @@ -411,6 +412,44 @@ def test_sync_destination_name_not_in_str_gives_correct_json_representation():
assert str(_filter) == expected


def test_sync_destination_username_exists_str_gives_correct_json_representation():
_filter = SyncDestinationUsername.exists()
expected = EXISTS.format("syncDestinationUsername")
assert str(_filter) == expected


def test_sync_destination_username_not_exists_str_gives_correct_json_representation():
_filter = SyncDestinationUsername.not_exists()
expected = NOT_EXISTS.format("syncDestinationUsername")
assert str(_filter) == expected


def test_sync_destination_username_eq_str_gives_correct_json_representation():
_filter = SyncDestinationUsername.eq("test_user@example.com")
expected = IS.format("syncDestinationUsername", "test_user@example.com")
assert str(_filter) == expected


def test_sync_destination_username_not_eq_str_gives_correct_json_representation():
_filter = SyncDestinationUsername.not_eq("test_user@example.com")
expected = IS_NOT.format("syncDestinationUsername", "test_user@example.com")
assert str(_filter) == expected


def test_sync_destination_username_is_in_str_gives_correct_json_representation():
items = ["*@example2.com", "user1@example.com", "user2@example.com"]
_filter = SyncDestinationUsername.is_in(items)
expected = IS_IN.format("syncDestinationUsername", *items)
assert str(_filter) == expected


def test_sync_destination_username_not_in_str_gives_correct_json_representation():
items = ["*@example2.com", "user1@example.com", "user2@example.com"]
_filter = SyncDestinationUsername.not_in(items)
expected = NOT_IN.format("syncDestinationUsername", *items)
assert str(_filter) == expected


def test_tab_url_exists_str_gives_correct_json_representation():
_filter = TabURL.exists()
expected = EXISTS.format("tabUrls")
Expand Down

0 comments on commit 0ccb101

Please sign in to comment.