当前位置: 首页>>代码示例>>Python>>正文


Python http.HttpValidation类代码示例

本文整理汇总了Python中alarmageddon.validations.http.HttpValidation的典型用法代码示例。如果您正苦于以下问题:Python HttpValidation类的具体用法?Python HttpValidation怎么用?Python HttpValidation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HttpValidation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_send

def test_send(tmpdir, smtpserver, httpserver):
    email_pub = create_default_email_publisher(tmpdir, smtpserver)
    create_subject_template(tmpdir)
    create_body_template(tmpdir)
    http_validator = \
        HttpValidation.get(httpserver.url).expect_status_codes([200])
    general_defaults = email_pub._config["email_defaults"]["general"]
    email_settings = {"email_type": "test_alert",
                      "subject": general_defaults["email_subject_template"],
                      "body": general_defaults["email_template"],
                      "sender": general_defaults["email_sender"],
                      "recipients": general_defaults["email_recipients"]}
    emailer.enrich(http_validator, email_settings)
    failure_message = "Validation failure. Expected 200, received 404."
    result = Failure("Check Status Route", http_validator,
                     description=failure_message)
    email_pub.send(result)
    print(smtpserver.outbox[0])
    assert len(smtpserver.outbox) == 1
    payload = str(smtpserver.outbox[0].get_payload()[0])
    assert payload.split('\n')[5] == "Validation Failure in environment test:"
    assert payload.split('\n')[6] == "Test Name: [Check Status Route]"
    assert payload.split('\n')[7] == \
        "Test Description: [Validation failure. Expected 200, received 404.]"
    custom_message = "Custom Message: [Validation failed in environment " \
                     "test: Check Status Route.]"
    assert payload.split('\n')[8] == custom_message
开发者ID:4everinbeta,项目名称:Alarmageddon,代码行数:27,代码来源:test_emailer.py

示例2: test_get_json_value_less_than_zero

def test_get_json_value_less_than_zero(httpserver):
    httpserver.serve_content(code=200,
                             headers={"content-type": "application/json"},
                             content='{"mode": "NORMAL","failed":0}')
    (HttpValidation.get(httpserver.url)
     .expect_json_property_value_less_than('failed', 2)
     .perform({}))
开发者ID:4everinbeta,项目名称:Alarmageddon,代码行数:7,代码来源:test_http.py

示例3: test_get_json_value

def test_get_json_value(httpserver):
    httpserver.serve_content(code=200,
                             headers={"content-type": "application/json"},
                             content='{"mode": "NORMAL"}')
    (HttpValidation.get(httpserver.url)
     .expect_json_property_value("mode", "NORMAL")
     .perform({}))
开发者ID:grizzlyecollege,项目名称:Alarmageddon,代码行数:7,代码来源:test_http.py

示例4: test_configure_replacement_context_email_type_found

def test_configure_replacement_context_email_type_found(tmpdir, smtpserver,
                                                        httpserver):
    email_pub = create_default_email_publisher(tmpdir, smtpserver)
    http_validator = \
        HttpValidation.get(httpserver.url).expect_status_codes([200])
    email_settings = {"email_type": "test_alert",
                      "subject": "subject test line",
                      "body": "body test",
                      "sender": {"real_name": "Alarmageddon Monitor",
                                 "address": "[email protected]"},
                      "recipients": [{"real_name": "Test Recipient",
                                      "address":
                                      "[email protected]"}]
                      }
    emailer.enrich(http_validator, email_settings)
    result = Failure("validation name", http_validator,
                     description="A failure occurred.")
    email_pub.configure_replacement_context(result)
    replacement_context = email_pub._replacement_context
    assert replacement_context["test_name"] == "validation name"
    assert replacement_context["test_description"] == "A failure occurred."
    assert replacement_context["env"] == "test"
    assert replacement_context["email_type"] == "test_alert"
    assert replacement_context["email_custom_message"] == \
        "Validation failed in environment {{env}}: {{test_name}}."
开发者ID:4everinbeta,项目名称:Alarmageddon,代码行数:25,代码来源:test_emailer.py

示例5: test_expected_code_default_correctly_fails

def test_expected_code_default_correctly_fails(httpserver):
    httpserver.serve_content(code=400,
                             headers={"content-type": "application/json"},
                             content='{}')
    with pytest.raises(ValidationFailure):
        (HttpValidation.get(httpserver.url)
         .perform({}))
开发者ID:grizzlyecollege,项目名称:Alarmageddon,代码行数:7,代码来源:test_http.py

示例6: test_expected_text

def test_expected_text(httpserver):
    httpserver.serve_content(code=200,
                             headers={"header": "exists"},
                             content="Here is some text!")
    (HttpValidation.get(httpserver.url)
     .expect_contains_text("is some")
     .perform({}))
开发者ID:grizzlyecollege,项目名称:Alarmageddon,代码行数:7,代码来源:test_http.py

示例7: test_get_email_settings

def test_get_email_settings(tmpdir, smtpserver, httpserver):
    email_pub = create_default_email_publisher(tmpdir, smtpserver)
    http_validator = \
        HttpValidation.get(httpserver.url).expect_status_codes([200])
    email_type = "test_alert"
    subject = "subject test line"
    body = "body test"
    recipient_array = [{"real_name": "Test Recipient",
                        "address": "[email protected]"}]
    sender = {"real_name": "Alarmageddon Monitor",
              "address": "[email protected]"}
    email_settings = {"email_type": email_type,
                      "subject": subject,
                      "body": body,
                      "sender": sender,
                      "recipients": recipient_array
                      }
    emailer.enrich(http_validator, email_settings)
    result = Success("validation name", http_validator)
    enriched_email_settings = email_pub.get_email_settings(result)
    assert enriched_email_settings['email_type'] == email_type
    assert enriched_email_settings['subject'] == subject
    assert enriched_email_settings['body'] == body
    assert enriched_email_settings['sender'] == sender
    assert enriched_email_settings['recipients'] == recipient_array
开发者ID:4everinbeta,项目名称:Alarmageddon,代码行数:25,代码来源:test_emailer.py

示例8: test_expected_header

def test_expected_header(httpserver):
    httpserver.serve_content(code=200,
                             headers={"header": "exists"},
                             content="this")
    (HttpValidation.get(httpserver.url)
     .expect_header("header", "exists")
     .perform({}))
开发者ID:grizzlyecollege,项目名称:Alarmageddon,代码行数:7,代码来源:test_http.py

示例9: test_expected_code

def test_expected_code(httpserver):
    httpserver.serve_content(code=300,
                             headers={"content-type": "application/json"},
                             content='{}')
    (HttpValidation.get(httpserver.url)
     .expect_status_codes([300])
     .perform({}))
开发者ID:grizzlyecollege,项目名称:Alarmageddon,代码行数:7,代码来源:test_http.py

示例10: test_expected_code_correct_on_set

def test_expected_code_correct_on_set(httpserver):
    httpserver.serve_content(code=200,
                             headers={"content-type": "application/json"},
                             content='{}')
    (HttpValidation.get(httpserver.url)
     .expect_status_codes(set(range(200, 300)))
     .perform({}))
开发者ID:grizzlyecollege,项目名称:Alarmageddon,代码行数:7,代码来源:test_http.py

示例11: test_get_json_value_greater_than

def test_get_json_value_greater_than(httpserver):
    httpserver.serve_content(code=200,
                             headers={"content-type": "application/json"},
                             content='{"mode": "NORMAL","numExecutors":3}')
    (HttpValidation.get(httpserver.url)
     .expect_json_property_value_greater_than("numExecutors", 2)
     .perform({}))
开发者ID:grizzlyecollege,项目名称:Alarmageddon,代码行数:7,代码来源:test_http.py

示例12: test_properly_records_elapsed_time_on_timeout

def test_properly_records_elapsed_time_on_timeout(slowserver):
    val = HttpValidation.get(slowserver.url, timeout=3)
    try:
        val.perform({})
    except requests.exceptions.Timeout:
        pass
    #specifically in this case the elapsed time should be the timeout
    assert val._elapsed_time == 3
开发者ID:grizzlyecollege,项目名称:Alarmageddon,代码行数:8,代码来源:test_http.py

示例13: test_get_array_value

def test_get_array_value(httpserver):
    httpserver.serve_content(code=200,
                             headers={"content-type": "application/json"},
                             content='{"num":3,"views":[{"name": "All"},' +
                                     '{"name": "None"}]}')
    (HttpValidation.get(httpserver.url)
     .expect_json_property_value("views[0].name", "All")
     .perform({}))
开发者ID:grizzlyecollege,项目名称:Alarmageddon,代码行数:8,代码来源:test_http.py

示例14: test_get_json_key_fails

def test_get_json_key_fails(httpserver):
    httpserver.serve_content(code=200,
                             headers={"content-type": "application/json"},
                             content='{"key": "NORMAL"}')
    with pytest.raises(ValidationFailure):
        (HttpValidation.get(httpserver.url)
         .expect_json_property_value("mode", "NORMAL")
         .perform({}))
开发者ID:grizzlyecollege,项目名称:Alarmageddon,代码行数:8,代码来源:test_http.py

示例15: test_expected_header_bad_value

def test_expected_header_bad_value(httpserver):
    httpserver.serve_content(code=200,
                             headers={"header": "nope"},
                             content="this")
    with pytest.raises(ValidationFailure):
        (HttpValidation.get(httpserver.url)
         .expect_header("header", "exists")
         .perform({}))
开发者ID:grizzlyecollege,项目名称:Alarmageddon,代码行数:8,代码来源:test_http.py


注:本文中的alarmageddon.validations.http.HttpValidation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。