本文整理汇总了Python中alarmageddon.validations.http.HttpValidation.get方法的典型用法代码示例。如果您正苦于以下问题:Python HttpValidation.get方法的具体用法?Python HttpValidation.get怎么用?Python HttpValidation.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alarmageddon.validations.http.HttpValidation
的用法示例。
在下文中一共展示了HttpValidation.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_send
# 需要导入模块: from alarmageddon.validations.http import HttpValidation [as 别名]
# 或者: from alarmageddon.validations.http.HttpValidation import get [as 别名]
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
示例2: test_get_json_value_less_than_zero
# 需要导入模块: from alarmageddon.validations.http import HttpValidation [as 别名]
# 或者: from alarmageddon.validations.http.HttpValidation import get [as 别名]
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({}))
示例3: test_get_json_value
# 需要导入模块: from alarmageddon.validations.http import HttpValidation [as 别名]
# 或者: from alarmageddon.validations.http.HttpValidation import get [as 别名]
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({}))
示例4: test_configure_replacement_context_email_type_found
# 需要导入模块: from alarmageddon.validations.http import HttpValidation [as 别名]
# 或者: from alarmageddon.validations.http.HttpValidation import get [as 别名]
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}}."
示例5: test_expected_code_default_correctly_fails
# 需要导入模块: from alarmageddon.validations.http import HttpValidation [as 别名]
# 或者: from alarmageddon.validations.http.HttpValidation import get [as 别名]
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({}))
示例6: test_expected_text
# 需要导入模块: from alarmageddon.validations.http import HttpValidation [as 别名]
# 或者: from alarmageddon.validations.http.HttpValidation import get [as 别名]
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({}))
示例7: test_get_email_settings
# 需要导入模块: from alarmageddon.validations.http import HttpValidation [as 别名]
# 或者: from alarmageddon.validations.http.HttpValidation import get [as 别名]
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
示例8: test_expected_header
# 需要导入模块: from alarmageddon.validations.http import HttpValidation [as 别名]
# 或者: from alarmageddon.validations.http.HttpValidation import get [as 别名]
def test_expected_header(httpserver):
httpserver.serve_content(code=200,
headers={"header": "exists"},
content="this")
(HttpValidation.get(httpserver.url)
.expect_header("header", "exists")
.perform({}))
示例9: test_expected_code
# 需要导入模块: from alarmageddon.validations.http import HttpValidation [as 别名]
# 或者: from alarmageddon.validations.http.HttpValidation import get [as 别名]
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({}))
示例10: test_expected_code_correct_on_set
# 需要导入模块: from alarmageddon.validations.http import HttpValidation [as 别名]
# 或者: from alarmageddon.validations.http.HttpValidation import get [as 别名]
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({}))
示例11: test_get_json_value_greater_than
# 需要导入模块: from alarmageddon.validations.http import HttpValidation [as 别名]
# 或者: from alarmageddon.validations.http.HttpValidation import get [as 别名]
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({}))
示例12: test_properly_records_elapsed_time_on_timeout
# 需要导入模块: from alarmageddon.validations.http import HttpValidation [as 别名]
# 或者: from alarmageddon.validations.http.HttpValidation import get [as 别名]
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
示例13: test_get_array_value
# 需要导入模块: from alarmageddon.validations.http import HttpValidation [as 别名]
# 或者: from alarmageddon.validations.http.HttpValidation import get [as 别名]
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({}))
示例14: test_get_json_key_fails
# 需要导入模块: from alarmageddon.validations.http import HttpValidation [as 别名]
# 或者: from alarmageddon.validations.http.HttpValidation import get [as 别名]
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({}))
示例15: test_expected_header_bad_value
# 需要导入模块: from alarmageddon.validations.http import HttpValidation [as 别名]
# 或者: from alarmageddon.validations.http.HttpValidation import get [as 别名]
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({}))