Skip to content

Commit

Permalink
added not operator (#42)
Browse files Browse the repository at this point in the history
* added not operator

* use BasePredicate.from_structure instead of Predicate.from_structure in Stub

* unittest for AndPredicate, OrPredicate, NotPredicate

Co-authored-by: Georgy <georgy.kulikov@aliexpress.ru>
  • Loading branch information
SShatun and Georgy committed Jan 31, 2021
1 parent 9ed588e commit e030b9a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/mbtest/imposters/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def from_structure(cls, structure: JsonStructure) -> "Stub":
else:
responses.append(Response.from_structure(response))
return cls(
[Predicate.from_structure(predicate) for predicate in structure.get("predicates", ())],
[
BasePredicate.from_structure(predicate)
for predicate in structure.get("predicates", ())
],
responses,
)

Expand Down
24 changes: 23 additions & 1 deletion tests/unit/mbtest/test_imposter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# encoding=utf-8
import logging

import pytest
from brunns.matchers.object import has_identical_properties_to
from hamcrest import assert_that, instance_of

from mbtest.imposters import Imposter, Proxy, Response, Stub
from tests.utils.builders import ImposterBuilder
from tests.utils.builders import (
AndPredicateBuilder,
ImposterBuilder,
NotPredicateBuilder,
OrPredicateBuilder,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -71,3 +77,19 @@ def test_imposter_structure_roundtrip():
# Then
assert_that(actual, instance_of(Imposter))
assert_that(actual, has_identical_properties_to(expected, ignoring="configuration_url"))


@pytest.mark.parametrize(
"predicate", [AndPredicateBuilder, OrPredicateBuilder, NotPredicateBuilder]
)
def test_imposter_complex_predicates(predicate):
# Given
expected = Imposter(Stub(predicate().build()))
structure = expected.as_structure()

# When
actual = Imposter.from_structure(structure)

# Then
assert_that(actual, instance_of(Imposter))
assert_that(actual, has_identical_properties_to(expected, ignoring="configuration_url"))

0 comments on commit e030b9a

Please sign in to comment.