Example #1
0
def run(url, match_regex, sleep_seconds):
    config = get_config_from_env()
    while True:
        check_result = http_check(url, match_regex)
        producer = HttpCheckProducer(config=config)
        producer.produce(http_check_result=check_result)
        time.sleep(sleep_seconds)
def http_check_result(freezer):
    responses.add(
        responses.GET,
        WEBSITE_URL,
        status=200,
        content_type="text/html",
    )
    result = http_check("http://website", None)
    return result
def test_website_check_with_404_response():
    responses.add(
        responses.GET,
        WEBSITE_URL,
        status=404,
        content_type="text/html",
    )
    result = http_check(WEBSITE_URL)
    assert result.status_code == 404
Example #4
0
def run_once(url, match_regex):
    config = get_config_from_env()
    producer = HttpCheckProducer(config=config)
    check_result = http_check(url, match_regex)
    producer.produce(http_check_result=check_result)
def test_website_check_regex_doesnt_match(success_response):
    result = http_check(WEBSITE_URL, regex_pattern=re.compile("Foobar"))
    assert not result.match_regex
def test_website_check_regex_matches(success_response):
    result = http_check(WEBSITE_URL, regex_pattern=re.compile("Hello"))
    assert result.match_regex
def test_website_check_with_200_response(freezer, success_response):
    result = http_check(WEBSITE_URL)
    assert result.status_code == 200
    assert result.match_regex is None
    assert result.timestamp == datetime.datetime.now(tz=datetime.timezone.utc)