Esempio n. 1
0
def test_or_predicate_structure_roundtrip():
    expected = OrPredicateBuilder().build()
    structure = expected.as_structure()

    # When
    actual = BasePredicate.from_structure(structure)

    # Then
    assert_that(actual, instance_of(OrPredicate))
    assert_that(actual, has_identical_properties_to(expected))
Esempio n. 2
0
 def from_structure(cls, structure: JsonStructure) -> "Stub":
     responses: List[Union[InjectionResponse, Proxy, Response]] = []
     for response in structure.get("responses", ()):
         if "proxy" in response:
             responses.append(Proxy.from_structure(response))
         elif "inject" in response:
             responses.append(InjectionResponse.from_structure(response))
         else:
             responses.append(Response.from_structure(response))
     return cls(
         [
             BasePredicate.from_structure(predicate)
             for predicate in structure.get("predicates", ())
         ],
         responses,
     )
Esempio n. 3
0
def test_structure_xpath():
    expected_predicate = Predicate(xpath="darwin")
    predicate_structure = expected_predicate.as_structure()
    predicate = BasePredicate.from_structure(predicate_structure)
    assert predicate.xpath == expected_predicate.xpath
Esempio n. 4
0
def test_structure_operator():
    expected_predicate = Predicate(operator="deepEquals")
    predicate_structure = expected_predicate.as_structure()
    predicate = BasePredicate.from_structure(predicate_structure)
    assert predicate.operator == expected_predicate.operator
Esempio n. 5
0
def test_structure_headers():
    expected_predicate = Predicate(headers={"key": "value"})
    predicate_structure = expected_predicate.as_structure()
    predicate = BasePredicate.from_structure(predicate_structure)
    assert predicate.headers == expected_predicate.headers
Esempio n. 6
0
def test_structure_query():
    expected_predicate = Predicate(query={"key": "value"})
    predicate_structure = expected_predicate.as_structure()
    predicate = BasePredicate.from_structure(predicate_structure)
    assert predicate.query == expected_predicate.query
Esempio n. 7
0
def test_structure_method():
    expected_predicate = Predicate(method="GET")
    predicate_structure = expected_predicate.as_structure()
    predicate = BasePredicate.from_structure(predicate_structure)
    assert predicate.method == expected_predicate.method
Esempio n. 8
0
def test_structure_body():
    expected_predicate = Predicate(body="darwin")
    predicate_structure = expected_predicate.as_structure()
    predicate = BasePredicate.from_structure(predicate_structure)
    assert predicate.body == expected_predicate.body
Esempio n. 9
0
def test_structure_path():
    expected_predicate = Predicate(path="/darwin")
    predicate_structure = expected_predicate.as_structure()
    predicate = BasePredicate.from_structure(predicate_structure)
    assert_that(predicate, instance_of(Predicate))
    assert predicate.path == expected_predicate.path