Esempio n. 1
0
    def test_output_load_results(self, capsys):
        config = configuration.Load('output', {})
        pingdom = Mock()
        pingdom.check_results = MagicMock(
            return_value={
                "results": [{
                    'statusdesclong': 'OK',
                    'responsetime': 582,
                    'probeid': 50,
                    'status': 'up',
                    'statusdesc': 'OK',
                    'time': 1458376174
                }, {
                    'statusdesclong': 'OK',
                    'responsetime': 1420,
                    'probeid': 34,
                    'status': 'up',
                    'statusdesc': 'OK',
                    'time': 1458376114
                }]
            })
        checks_results_load.Load(config, pingdom).results(
            {
                "id": 2057736,
                "created": 1458372620
            }, c_to=1458372620 + 100)

        pingdom.check_results.assert_called_with(2057736, 1458372620,
                                                 1458372720)
        out = capsys.readouterr()
        assert len(out) == 2
        assert '2057736,1458376174,50,up,OK,OK,582\r\n2057736,1458376114,34,up,OK,OK,1420\r\n' == out[
            0]
        assert '' == out[1]
Esempio n. 2
0
    def test_output_load(self, capsys):
        config = configuration.Load('output', {})
        checks_load.Load(config).load([{
            'hostname': 'www.a.com',
            'use_legacy_notifications': True,
            'lastresponsetime': 411,
            'ipv6': False,
            'type': 'http',
            'name': 'A',
            'resolution': 1,
            'created': 1458372620,
            'lasttesttime': 1459005934,
            'status': 'up',
            'id': 2057736
        }, {
            'lasterrortime': 1458938840,
            'type': 'http',
            'hostname': 'b.a.com',
            'lastresponsetime': 827,
            'created': 1458398619,
            'lasttesttime': 1459005943,
            'status': 'up',
            'ipv6': False,
            'use_legacy_notifications': True,
            'resolution': 1,
            'name': 'B',
            'id': 2057910
        }])

        out = capsys.readouterr()
        assert len(out) == 2
        assert 'Id,Name,Created at,Status,Hostname,Type\r\n2057736,A,1458372620,up,www.a.com,http\r\n2057910,B,1458398619,up,b.a.com,http\r\n' == out[
            0]
        assert '' == out[1]
Esempio n. 3
0
 def test_mysql(self):
     load = configuration.Load('mysql', {'db_url': 'test'})
     assert load.type() == 'mysql'
     assert load.params() == {'db_url': 'test'}
     assert not load.is_type_output()
     assert load.is_type_mysql()
     assert not load.is_type_postgres()
     assert load.is_type_db()
Esempio n. 4
0
 def test_output(self):
     load = configuration.Load('output', {})
     assert load.type() == 'output'
     assert load.params() == {}
     assert load.is_type_output()
     assert not load.is_type_mysql()
     assert not load.is_type_postgres()
     assert not load.is_type_db()
Esempio n. 5
0
    def test_output_load(self, capsys):
        config = configuration.Load('output', {})
        pingdom = Mock()
        pingdom.check_results.side_effect = [{
            "results": [{
                'statusdesclong': 'OK',
                'responsetime': 582,
                'probeid': 50,
                'status': 'up',
                'statusdesc': 'OK',
                'time': 1458376174
            }]
        }, {
            "results": [{
                'statusdesclong': 'OK',
                'responsetime': 582,
                'probeid': 50,
                'status': 'up',
                'statusdesc': 'OK',
                'time': 1458376175
            }]
        }, {
            "results": [{
                'statusdesclong': 'OK',
                'responsetime': 582,
                'probeid': 50,
                'status': 'up',
                'statusdesc': 'OK',
                'time': 1458376176
            }]
        }, {
            "results": [{
                'statusdesclong': 'OK',
                'responsetime': 582,
                'probeid': 50,
                'status': 'up',
                'statusdesc': 'OK',
                'time': 1458376177
            }]
        }]
        checks_results_load.Load(config,
                                 pingdom).load([{
                                     "id": 2057736,
                                     "created": 1458372620
                                 }, {
                                     "id": 2057737,
                                     "created": 1458372620
                                 }],
                                               c_to=1458372620 + 3600 * 2)

        assert 4 == pingdom.check_results.call_count
        out = capsys.readouterr()
        assert len(out) == 2
        assert 'Check ID,Time,Probe ID,Status,Status description,Status long description,Response time\r\n2057736,1458376174,50,up,OK,OK,582\r\n2057736,1458376175,50,up,OK,OK,582\r\n2057737,1458376176,50,up,OK,OK,582\r\n2057737,1458376177,50,up,OK,OK,582\r\n' == out[
            0]
        assert '' == out[1]
Esempio n. 6
0
    def test_output_load_results_with_from(self, capsys):
        config = configuration.Load('output', {})
        created = 1458372620
        pingdom = Mock()
        pingdom.check_results = MagicMock(return_value={"results": []})
        checks_results_load.Load(config, pingdom).results(
            {
                "id": 2057736,
                "created": created
            }, created + 100, created + 1000)

        pingdom.check_results.assert_called_with(2057736, created + 100,
                                                 created + 1000)
Esempio n. 7
0
    def test_output_load_results_multi(self, capsys):
        config = configuration.Load('output', {})
        pingdom = Mock()
        pingdom.check_results.side_effect = [{
            "results": [{
                'statusdesclong': 'OK',
                'responsetime': 582,
                'probeid': 50,
                'status': 'up',
                'statusdesc': 'OK',
                'time': 1458376174
            }, {
                'statusdesclong': 'OK',
                'responsetime': 682,
                'probeid': 51,
                'status': 'up',
                'statusdesc': 'OK',
                'time': 1458376184
            }]
        }, {
            "results": [{
                'statusdesclong': 'OK',
                'responsetime': 1420,
                'probeid': 34,
                'status': 'up',
                'statusdesc': 'OK',
                'time': 1458376114
            }]
        }]
        checks_results_load.Load(config, pingdom).results(
            {
                "id": 2057736,
                "created": 1458372620
            }, c_to=1458372620 + 3600 * 2)

        assert 2 == pingdom.check_results.call_count
        out = capsys.readouterr()
        assert len(out) == 2
        assert '2057736,1458376174,50,up,OK,OK,582\r\n2057736,1458376184,51,up,OK,OK,682\r\n2057736,1458376114,34,up,OK,OK,1420\r\n' == out[
            0]
        assert '' == out[1]
Esempio n. 8
0
 def test_postgres_without_db_url(self):
     with pytest.raises(ValueError):
         configuration.Load('postgres', {})
Esempio n. 9
0
 def test_mysql_without_db_url(self):
     with pytest.raises(ValueError):
         configuration.Load('mysql', {})
Esempio n. 10
0
 def test_output_with_parameters(self):
     with pytest.raises(ValueError):
         configuration.Load('output', {'db_url': 'test'})
Esempio n. 11
0
 def test_type_unrecognized(self):
     with pytest.raises(ValueError):
         configuration.Load('t', {})