Skip to content

Commit

Permalink
Adding Source_Filters (#400)
Browse files Browse the repository at this point in the history
* Adding Source_Filters

* Update Changelog.md

* Adding tests for source_filter

* add SourceCategory choices

* import Choices correctly

* docstring wording

* changelog

* style

Co-authored-by: tim.abramson <tim.abramson@code42.com>
  • Loading branch information
ryan-haley-code42 and timabrmsn committed Feb 1, 2022
1 parent 3745058 commit 476902b
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
The intended audience of this file is for py42 consumers -- as such, changes that don't affect
how a consumer would use the library (e.g. adding unit tests, updating documentation, etc) are not captured here.

## Unreleased

### Added

- New file event filter query classes to `sdk.queries.fileevents.filters.source_filters`:
- `SourceCategory`
- `SourceName`
- `SourceTabTitles`
- `SourceTabUrls`

## 1.20.0 - 2022-01-10

### Added
Expand Down
51 changes: 51 additions & 0 deletions src/py42/sdk/queries/fileevents/filters/source_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from py42.choices import Choices
from py42.sdk.queries.fileevents.file_event_query import FileEventFilterStringField


class SourceCategory(FileEventFilterStringField, Choices):
"""
Class that filters events based on source category.
Available options are provided as class attributes:
- :attr:`SourceCategory.BUSINESS_TOOLS`
- :attr:`SourceCategory.CLOUD_STORAGE`
- :attr:`SourceCategory.DEVICE`
- :attr:`SourceCategory.EMAIL`
- :attr:`SourceCategory.MESSAGING`
- :attr:`SourceCategory.MULTIPLE_POSSIBILITIES`
- :attr:`SourceCategory.SOCIAL_MEDIA`
- :attr:`SourceCategory.SOURCE_CODE_REPOSITORY`
- :attr:`SourceCategory.UNCATEGORIZED`
- :attr:`SourceCategory.UNKNOWN`
"""

_term = "sourceCategory"

BUSINESS_TOOLS = "Business Tools"
CLOUD_STORAGE = "Cloud Storage"
DEVICE = "Device"
EMAIL = "Email"
MESSAGING = "Messaging"
MULTIPLE_POSSIBILITIES = "Multiple Possibilities"
SOCIAL_MEDIA = "Social Media"
SOURCE_CODE_REPOSITORY = "Source Code Repository"
UNCATEGORIZED = "Uncategorized"
UNKNOWN = "Unknown"


class SourceName(FileEventFilterStringField):
"""Class that filters events based on source name."""

_term = "sourceName"


class SourceTabTitles(FileEventFilterStringField):
"""Class that filters events based on source tab titles (for 'browser or other app' events)."""

_term = "sourceTabTitles"


class SourceTabUrls(FileEventFilterStringField):
"""Class that filters events based on source tab URLs (for 'browser or other app' events)."""

_term = "sourceTabUrls"
171 changes: 171 additions & 0 deletions tests/sdk/queries/fileevents/filters/test_source_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
from tests.sdk.queries.conftest import EXISTS
from tests.sdk.queries.conftest import IS
from tests.sdk.queries.conftest import IS_IN
from tests.sdk.queries.conftest import IS_NOT
from tests.sdk.queries.conftest import NOT_EXISTS
from tests.sdk.queries.conftest import NOT_IN

from py42.sdk.queries.fileevents.filters.source_filters import SourceCategory
from py42.sdk.queries.fileevents.filters.source_filters import SourceName
from py42.sdk.queries.fileevents.filters.source_filters import SourceTabTitles
from py42.sdk.queries.fileevents.filters.source_filters import SourceTabUrls


def test_source_category_exists_str_gives_correct_json_representation():
_filter = SourceCategory.exists()
expected = EXISTS.format("sourceCategory")
assert str(_filter) == expected


def test_source_category_not_exists_str_gives_correct_json_representation():
_filter = SourceCategory.not_exists()
expected = NOT_EXISTS.format("sourceCategory")
assert str(_filter) == expected


def test_source_category_eq_str_gives_correct_json_representation():
_filter = SourceCategory.eq("test_sourceCategory")
expected = IS.format("sourceCategory", "test_sourceCategory")
assert str(_filter) == expected


def test_source_category_not_eq_str_gives_correct_json_representation():
_filter = SourceCategory.not_eq("test_sourceCategory")
expected = IS_NOT.format("sourceCategory", "test_sourceCategory")
assert str(_filter) == expected


def test_source_category_is_in_str_gives_correct_json_representation():
items = ["test_sourceCategory_1", "test_sourceCategory_2", "test_sourceCategory_3"]
_filter = SourceCategory.is_in(items)
expected = IS_IN.format("sourceCategory", *sorted(items))
assert str(_filter) == expected


def test_source_category_not_in_str_gives_correct_json_representation():
items = ["test_sourceCategory_1", "test_sourceCategory_2", "test_sourceCategory_3"]
_filter = SourceCategory.not_in(items)
expected = NOT_IN.format("sourceCategory", *sorted(items))
assert str(_filter) == expected


def test_source_name_exists_str_gives_correct_json_representation():
_filter = SourceName.exists()
expected = EXISTS.format("sourceName")
assert str(_filter) == expected


def test_source_name_not_exists_str_gives_correct_json_representation():
_filter = SourceName.not_exists()
expected = NOT_EXISTS.format("sourceName")
assert str(_filter) == expected


def test_source_name_eq_str_gives_correct_json_representation():
_filter = SourceName.eq("test_sourceName")
expected = IS.format("sourceName", "test_sourceName")
assert str(_filter) == expected


def test_source_name_not_eq_str_gives_correct_json_representation():
_filter = SourceName.not_eq("test_sourceName")
expected = IS_NOT.format("sourceName", "test_sourceName")
assert str(_filter) == expected


def test_source_name_is_in_str_gives_correct_json_representation():
items = ["test_sourceName_1", "test_sourceName_2", "test_sourceName_3"]
_filter = SourceName.is_in(items)
expected = IS_IN.format("sourceName", *sorted(items))
assert str(_filter) == expected


def test_source_name_not_in_str_gives_correct_json_representation():
items = ["test_sourceName_1", "test_sourceName_2", "test_sourceName_3"]
_filter = SourceName.not_in(items)
expected = NOT_IN.format("sourceName", *sorted(items))
assert str(_filter) == expected


def test_source_tab_titles_exists_str_gives_correct_json_representation():
_filter = SourceTabTitles.exists()
expected = EXISTS.format("sourceTabTitles")
assert str(_filter) == expected


def test_source_tab_titles_not_exists_str_gives_correct_json_representation():
_filter = SourceTabTitles.not_exists()
expected = NOT_EXISTS.format("sourceTabTitles")
assert str(_filter) == expected


def test_source_tab_titles_eq_str_gives_correct_json_representation():
_filter = SourceTabTitles.eq("test_sourceTabTitles")
expected = IS.format("sourceTabTitles", "test_sourceTabTitles")
assert str(_filter) == expected


def test_source_tab_titles_not_eq_str_gives_correct_json_representation():
_filter = SourceTabTitles.not_eq("test_sourceTabTitles")
expected = IS_NOT.format("sourceTabTitles", "test_sourceTabTitles")
assert str(_filter) == expected


def test_source_tab_titles_is_in_str_gives_correct_json_representation():
items = [
"test_sourceTabTitles_1",
"test_sourceTabTitles_2",
"test_sourceTabTitles_3",
]
_filter = SourceTabTitles.is_in(items)
expected = IS_IN.format("sourceTabTitles", *sorted(items))
assert str(_filter) == expected


def test_source_tab_titles_not_in_str_gives_correct_json_representation():
items = [
"test_sourceTabTitles_1",
"test_sourceTabTitles_2",
"test_sourceTabTitles_3",
]
_filter = SourceTabTitles.not_in(items)
expected = NOT_IN.format("sourceTabTitles", *sorted(items))
assert str(_filter) == expected


def test_source_tab_urls_exists_str_gives_correct_json_representation():
_filter = SourceTabUrls.exists()
expected = EXISTS.format("sourceTabUrls")
assert str(_filter) == expected


def test_source_tab_urls_not_exists_str_gives_correct_json_representation():
_filter = SourceTabUrls.not_exists()
expected = NOT_EXISTS.format("sourceTabUrls")
assert str(_filter) == expected


def test_source_tab_urls_eq_str_gives_correct_json_representation():
_filter = SourceTabUrls.eq("test_sourceTabUrls")
expected = IS.format("sourceTabUrls", "test_sourceTabUrls")
assert str(_filter) == expected


def test_source_tab_urls_not_eq_str_gives_correct_json_representation():
_filter = SourceTabUrls.not_eq("test_sourceTabUrls")
expected = IS_NOT.format("sourceTabUrls", "test_sourceTabUrls")
assert str(_filter) == expected


def test_source_tab_urls_is_in_str_gives_correct_json_representation():
items = ["test_sourceTabUrls_1", "test_sourceTabUrls_2", "test_sourceTabUrls_3"]
_filter = SourceTabUrls.is_in(items)
expected = IS_IN.format("sourceTabUrls", *sorted(items))
assert str(_filter) == expected


def test_source_tab_urls_not_in_str_gives_correct_json_representation():
items = ["test_sourceTabUrls_1", "test_sourceTabUrls_2", "test_sourceTabUrls_3"]
_filter = SourceTabUrls.not_in(items)
expected = NOT_IN.format("sourceTabUrls", *sorted(items))
assert str(_filter) == expected

0 comments on commit 476902b

Please sign in to comment.