@@ -0,0 +1,2702 @@
+# -*- coding: utf-8 -*-%0A%22%22%22%0A%22%22%22%0Aimport os%0Aimport shutil%0Aimport contextlib%0Aimport pytest%0Aimport mock%0Aimport demjson%0Afrom fabric import api%0Aimport requests%0Afrom ymir import validation%0Afrom ymir.util import TemporaryDirectory%0Afrom ymir import api as yapi%0Afrom tests import common as test_common%0Afrom ymir import checks%0A%0A%0Adef _mock_service():%0A    service = mock.Mock()%0A    service._service_data = %7B%7D%0A    service._status = mock.Mock(return_value=dict(ip=''))%0A    return service%0A%0A%0Adef test_invalid_check_type():%0A    check = checks.Check(%0A        name='doesnt_matter',%0A        check_type='doesnt-exist',%0A        url_t='',%0A    )%0A    with pytest.raises(checks.InvalidCheckType):%0A        check.run(_mock_service())%0A%0A%0A@mock.patch('ymir.checks._get_request')%0Adef test_timeouts(request_mock):%0A    request_mock.side_effect = requests.exceptions.ConnectionError('timed out')%0A    check = checks.Check(%0A        name='test-json',%0A        check_type='json_200',%0A        url_t='',)%0A    assert check.run(_mock_service()).failed%0A    request_mock.side_effect = requests.exceptions.ReadTimeout(%22zooom%22)%0A    assert check.run(_mock_service()).failed%0A%0A%0A@mock.patch('ymir.util.is_port_open')%0Adef test_port_open(fake_is_port_open):%0A    fake_is_port_open.return_value = False%0A    check = checks.Check(%0A        name='test-port-open',%0A        check_type='port_open',%0A        url_t='',)%0A    assert check.run(_mock_service()).failed%0A%0A%0A@mock.patch('ymir.checks._get_request')%0Adef test_json(request_mock):%0A    response = mock.Mock()%0A    request_mock.return_value = response%0A    response.status_code = 200%0A    check = checks.Check(%0A        name='test-json',%0A        check_type='json_200',%0A        url_t='',)%0A    result = check.run(_mock_service())%0A    assert result.success%0A    assert response.json.called%0A    response.status_code = 300%0A    assert check.run(_mock_service()).failed%0A    response.status_code = 200%0A    response.json = mock.Mock(side_effect=Exception)%0A    assert check.run(_mock_service()).failed%0A%0A%0Adef _test_factory(status_code):%0A    @mock.patch('ymir.checks._get_request')%0A    def test_xxx(request_mock):%0A        response = mock.Mock()%0A        request_mock.return_value = response%0A        response.status_code = status_code + 125%0A        check = checks.Check(%0A            name='test-%7B0%7D'.format(status_code),%0A            check_type='http_%7B0%7D'.format(status_code),%0A            url_t='',)%0A        result = check.run(_mock_service())%0A        assert not result.success%0A        response.status_code = status_code%0A        result = check.run(_mock_service())%0A        assert result.success%0A    return test_xxx%0A%0Atest_301 = _test_factory(301)%0Atest_401 = _test_factory(401)%0Atest_403 = _test_factory(403)%0Atest_200 = _test_factory(200)%0A

add tests for ymir.checks