Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecations, add warning for Contains #377

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tests/test_query_filters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from thehive4py import TheHiveApi
from thehive4py.helpers import now_to_ts
from thehive4py.query.filters import (
Expand All @@ -7,6 +8,7 @@
Eq,
Gt,
Gte,
Has,
Id,
In,
Like,
Expand All @@ -24,7 +26,9 @@ def test_between_contains_in(self, thehive: TheHiveApi, test_user: OutputUser):
assert thehive.user.find(
JuanTecedor marked this conversation as resolved.
Show resolved Hide resolved
filters=Between(field="_createdAt", start=0, end=now_to_ts())
)
assert thehive.user.find(filters=Contains(field="login"))
with pytest.deprecated_call():
assert thehive.user.find(filters=Contains(field="login"))
assert thehive.user.find(filters=Has(field="login"))
assert thehive.user.find(
filters=In(field="login", values=["...", "xyz", test_user["login"]])
)
Expand Down
2 changes: 1 addition & 1 deletion thehive4py/query/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .filters import Between, Contains, EndsWith, Eq
from .filters import FilterExpr as _FilterExpr
from .filters import Gt, Gte, Id, In, Like, Lt, Lte, Match, Ne, StartsWith
from .filters import Gt, Gte, Has, Id, In, Like, Lt, Lte, Match, Ne, StartsWith
from .page import Paginate
from .sort import Asc, Desc
from .sort import SortExpr as _SortExpr
Expand Down
23 changes: 19 additions & 4 deletions thehive4py/query/filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import UserDict as _UserDict
from typing import Any as _Any
from typing import Union as _Union
import warnings

FilterExpr = _Union["_FilterBase", dict]

Expand Down Expand Up @@ -34,28 +35,28 @@ class Lt(_FilterBase):
"""Field less than value."""

def __init__(self, field: str, value: _Any):
super().__init__(_lt={field: value})
super().__init__(_lt={"_field": field, "_value": value})


class Gt(_FilterBase):
"""Field greater than value."""

def __init__(self, field: str, value: _Any):
super().__init__(_gt={field: value})
super().__init__(_gt={"_field": field, "_value": value})


class Lte(_FilterBase):
"""Field less than or equal value."""

def __init__(self, field: str, value: _Any):
super().__init__(_lte={field: value})
super().__init__(_lte={"_field": field, "_value": value})


class Gte(_FilterBase):
"""Field less than or equal value."""

def __init__(self, field: str, value: _Any):
super().__init__(_gte={field: value})
super().__init__(_gte={"_field": field, "_value": value})


class Ne(_FilterBase):
Expand Down Expand Up @@ -111,9 +112,23 @@ class Contains(_FilterBase):
"""Object contains the field."""

def __init__(self, field: str):
warnings.warn(
message="The `Contains` filter has been deprecated. "
"Please use the `Has` filter to prevent breaking "
"changes in the future.",
category=DeprecationWarning,
stacklevel=2,
)
super().__init__(_contains=field)


class Has(_FilterBase):
"""Object contains the field."""

def __init__(self, field: str):
super().__init__(_has=field)


class Like(_FilterBase):
"""Field contains the value."""

Expand Down
Loading