Skip to content

Commit

Permalink
Unit tests: QueryFilter equality checks
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Tisnovsky <[email protected]>
  • Loading branch information
tisnik committed Jan 7, 2025
1 parent 76da92f commit f8c06b6
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/unit/app/models/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3039,6 +3039,69 @@ def get_query_filter():
query_filter.validate_yaml()


def get_query_filters():
"""Construct two instances of QueryFilter class."""
query_filter_1 = QueryFilter()
query_filter_2 = QueryFilter()
return query_filter_1, query_filter_2


def test_query_filter_equality(subtests):
"""Test the QueryFilter equality check."""
# compare two objects with the same content
query_filter_1, query_filter_2 = get_query_filters()
assert query_filter_1 == query_filter_2

# compare with value of different type
other_value = "foo"
assert query_filter_1 != other_value

# compare two objects with different content
with subtests.test(msg="Different attribute: name"):
query_filter_1, query_filter_2 = get_query_filters()
query_filter_1.name = "foo"
query_filter_2.name = "bar"
assert query_filter_1 != query_filter_2

# compare two objects with different content
with subtests.test(msg="Different attribute: pattern"):
query_filter_1, query_filter_2 = get_query_filters()
query_filter_1.pattern = "foo.*"
query_filter_2.pattern = "bar.*"
assert query_filter_1 != query_filter_2

# compare two objects with different content
with subtests.test(msg="Different attribute: replace_with"):
query_filter_1, query_filter_2 = get_query_filters()
query_filter_1.replace_with = "-foo-"
query_filter_2.replace_with = "-bar-"
assert query_filter_1 != query_filter_2


def test_query_filter_equality_null_values(subtests):
"""Test the QueryFilter equality check."""
# compare two objects with different content
with subtests.test(msg="Different attribute: name"):
query_filter_1, query_filter_2 = get_query_filters()
query_filter_1.name = None
query_filter_2.name = "bar"
assert query_filter_1 != query_filter_2

# compare two objects with different content
with subtests.test(msg="Different attribute: pattern"):
query_filter_1, query_filter_2 = get_query_filters()
query_filter_1.pattern = None
query_filter_2.pattern = "bar.*"
assert query_filter_1 != query_filter_2

# compare two objects with different content
with subtests.test(msg="Different attribute: replace_with"):
query_filter_1, query_filter_2 = get_query_filters()
query_filter_1.replace_with = None
query_filter_2.replace_with = "-bar-"
assert query_filter_1 != query_filter_2


def test_authentication_config_validation_proper_config():
"""Test method to validate authentication config."""
# default module
Expand Down

0 comments on commit f8c06b6

Please sign in to comment.