Exemplo n.º 1
0
def _calculate_stage_strictness(stage, test_block_config, test_spec):
    """Figure out the strictness for this stage

    Can be overridden per stage, or per test

    Priority is global (see pytest util file) <= test <= stage
    """
    stage_options = None

    if test_spec.get("strict", None) is not None:
        stage_options = test_spec["strict"]

    if stage.get("response", {}).get("strict", None) is not None:
        stage_options = stage["response"]["strict"]
    elif stage.get("mqtt_response", {}).get("strict", None) is not None:
        stage_options = stage["mqtt_response"]["strict"]

    if stage_options is not None:
        logger.debug("Overriding global strictness")
        if stage_options is True:
            strict_level = StrictLevel.all_on()
        elif stage_options is False:
            strict_level = StrictLevel.all_off()
        else:
            strict_level = StrictLevel.from_options(stage_options)

        test_block_config["strict"] = strict_level
    else:
        logger.debug("Global default strictness used for this stage")

    logger.debug("Strict key checking for this stage is '%s'",
                 test_block_config["strict"])
Exemplo n.º 2
0
def test_nothing_returned_fails():
    """Raises an error if no message was received"""
    fake_client = Mock(spec=MQTTClient, message_received=Mock(return_value=None))

    expected = {"topic": "/a/b/c", "payload": "hello"}

    verifier = MQTTResponse(
        fake_client, "Test stage", expected, {"strict": StrictLevel.all_on()}
    )

    with pytest.raises(exceptions.TestFailError):
        verifier.verify(expected)

    assert not verifier.received_messages
Exemplo n.º 3
0
def fix_example_includes():
    includes = {
        "variables": {
            "request": {"prefix": "www.", "url": "google.com"},
            "test_auth_token": "abc123",
            "code": "def456",
            "callback_url": "www.yahoo.co.uk",
            "request_topic": "/abc",
        },
        "backends": {"mqtt": "paho-mqtt", "http": "requests"},
        "strict": StrictLevel.all_on(),
        "tavern_internal": {"pytest_hook_caller": Mock()},
    }

    return includes.copy()