Exemple #1
0
    def test_query_member(self):
        with patch('patroni.ctl.get_cursor',
                   Mock(return_value=MockConnect().cursor())):
            rows = query_member(None, None, None, 'master',
                                'SELECT pg_catalog.pg_is_in_recovery()', {})
            self.assertTrue('False' in str(rows))

            with patch.object(MockCursor, 'execute',
                              Mock(side_effect=OperationalError('bla'))):
                rows = query_member(None, None, None, 'replica',
                                    'SELECT pg_catalog.pg_is_in_recovery()',
                                    {})

        with patch('patroni.ctl.get_cursor', Mock(return_value=None)):
            rows = query_member(None, None, None, None,
                                'SELECT pg_catalog.pg_is_in_recovery()', {})
            self.assertTrue('No connection to' in str(rows))

            rows = query_member(None, None, None, 'replica',
                                'SELECT pg_catalog.pg_is_in_recovery()', {})
            self.assertTrue('No connection to' in str(rows))

        with patch('patroni.ctl.get_cursor',
                   Mock(side_effect=OperationalError('bla'))):
            rows = query_member(None, None, None, 'replica',
                                'SELECT pg_catalog.pg_is_in_recovery()', {})
    def test_query_member(self):
        rows = query_member(None, None, None, 'master',
                            'SELECT pg_is_in_recovery()')
        assert 'False' in str(rows)

        rows = query_member(None, None, None, 'replica',
                            'SELECT pg_is_in_recovery()')
        assert rows == (None, None)

        with patch('patroni.ctl.get_cursor', Mock(return_value=None)):
            rows = query_member(None, None, None, None,
                                'SELECT pg_is_in_recovery()')
            assert 'No connection to' in str(rows)

            rows = query_member(None, None, None, 'replica',
                                'SELECT pg_is_in_recovery()')
            assert 'No connection to' in str(rows)

        with patch('patroni.ctl.get_cursor',
                   Mock(side_effect=psycopg2.OperationalError('bla'))):
            rows = query_member(None, None, None, 'replica',
                                'SELECT pg_is_in_recovery()')

        with patch('test_postgresql.MockCursor.execute',
                   Mock(side_effect=psycopg2.OperationalError('bla'))):
            rows = query_member(None, None, None, 'replica',
                                'SELECT pg_is_in_recovery()')
    def test_query_member(self):
        rows = query_member(None, None, None, "master", "SELECT pg_is_in_recovery()")
        assert "False" in str(rows)

        rows = query_member(None, None, None, "replica", "SELECT pg_is_in_recovery()")
        assert rows == (None, None)

        with patch("patroni.ctl.get_cursor", Mock(return_value=None)):
            rows = query_member(None, None, None, None, "SELECT pg_is_in_recovery()")
            assert "No connection to" in str(rows)

            rows = query_member(None, None, None, "replica", "SELECT pg_is_in_recovery()")
            assert "No connection to" in str(rows)

        with patch("patroni.ctl.get_cursor", Mock(side_effect=psycopg2.OperationalError("bla"))):
            rows = query_member(None, None, None, "replica", "SELECT pg_is_in_recovery()")

        with patch("test_postgresql.MockCursor.execute", Mock(side_effect=psycopg2.OperationalError("bla"))):
            rows = query_member(None, None, None, "replica", "SELECT pg_is_in_recovery()")
    def test_query_member(self):
        with patch('patroni.ctl.get_cursor', Mock(return_value=MockConnect().cursor())):
            rows = query_member(None, None, None, 'master', 'SELECT pg_is_in_recovery()')
            self.assertTrue('False' in str(rows))

            rows = query_member(None, None, None, 'replica', 'SELECT pg_is_in_recovery()')
            self.assertEquals(rows, (None, None))

            with patch('test_postgresql.MockCursor.execute', Mock(side_effect=OperationalError('bla'))):
                rows = query_member(None, None, None, 'replica', 'SELECT pg_is_in_recovery()')

        with patch('patroni.ctl.get_cursor', Mock(return_value=None)):
            rows = query_member(None, None, None, None, 'SELECT pg_is_in_recovery()')
            self.assertTrue('No connection to' in str(rows))

            rows = query_member(None, None, None, 'replica', 'SELECT pg_is_in_recovery()')
            self.assertTrue('No connection to' in str(rows))

        with patch('patroni.ctl.get_cursor', Mock(side_effect=OperationalError('bla'))):
            rows = query_member(None, None, None, 'replica', 'SELECT pg_is_in_recovery()')