#!/usr/bin/python
# coding=utf-8
##########################################################################

from test import CollectorTestCase
from test import get_collector_config

from postgres import PostgresqlCollector


class TestPostgresqlCollector(CollectorTestCase):

    def setUp(self, allowed_names=None):
        if not allowed_names:
            allowed_names = []
        config = get_collector_config('PostgresqlCollector', {
        })
        self.collector = PostgresqlCollector(config, None)

    def test_import(self):
        self.assertTrue(PostgresqlCollector)

@@ -176,16 +176,45 @@
 config%0A%0A
+from mock import patch, Mock%0A
 from pos
@@ -607,8 +607,1443 @@
 lector)%0A
+%0A    @patch('postgres.psycopg2')%0A    def test_connect_with_password(self, psycopg2_mock):%0A        conn_mock = Mock()%0A        psycopg2_mock.connect.return_value = conn_mock%0A%0A        ret = self.collector._connect('test_db')%0A%0A        self.assertTrue(conn_mock.set_isolation_level.called)%0A        self.assertEqual(ret, conn_mock)%0A        psycopg2_mock.connect.assert_called_once_with(%0A            database='test_db', host='localhost', password='postgres',%0A            port=5432, sslmode='disable', user='postgres'%0A        )%0A%0A    @patch('postgres.psycopg2')%0A    def test_connect_with_pgpass(self, psycopg2_mock):%0A        config = get_collector_config('PostgresqlCollector', %7B%0A            'password_provider': 'pgpass'%0A        %7D)%0A        self.collector = PostgresqlCollector(config, None)%0A%0A        conn_mock = Mock()%0A        psycopg2_mock.connect.return_value = conn_mock%0A%0A        ret = self.collector._connect('test_db')%0A%0A        self.assertTrue(conn_mock.set_isolation_level.called)%0A        self.assertEqual(ret, conn_mock)%0A        psycopg2_mock.connect.assert_called_once_with(%0A            database='test_db', host='localhost',%0A            port=5432, sslmode='disable', user='postgres'%0A        )%0A%0A    @patch('postgres.psycopg2')%0A    def test_connect_error(self, psycopg2_mock):%0A        psycopg2_mock.connect.side_effect = Exception('Some db exc')%0A%0A        with self.assertRaises(Exception):%0A            self.collector._connect('test_db')%0A

add connection tests