Ejemplo n.º 1
0
 def test_connect_other_error(self, mock_connect):
     inst = Postgres(self.source, OPTIONS)
     inst.tables = [{'value': 'schema.foo'}]
     msg = 'something unexpected'
     mock_connect.side_effect = psycopg2.OperationalError(msg)
     with self.assertRaises(psycopg2.OperationalError):
         inst.get_tables()
Ejemplo n.º 2
0
 def test_connect_auth_error(self, mock_connect):
     inst = Postgres(self.source, OPTIONS)
     inst.tables = [{'value': 'schema.foo'}]
     msg = 'authentication failed'
     mock_connect.side_effect = psycopg2.OperationalError(msg)
     with self.assertRaises(PanoplyException):
         inst.get_tables()
Ejemplo n.º 3
0
    def test_get_tables(self, m):
        '''gets the list of tables from the database'''

        # Notice 'name' here is only for validation of expected result.
        # It is not a field that returns in the actual query results
        mock_tables = [{
            'table_schema': 'dbo',
            'table_name': 'testNoUnique',
            'table_type': 'BASE TABLE',
            'name': 'dbo.testNoUnique'
        }, {
            'table_schema': 'dbo',
            'table_name': 'testNoIndex',
            'table_type': 'BASE TABLE',
            'name': 'dbo.testNoIndex'
        }, {
            'table_schema': 'SalesLT',
            'table_name': 'Customer',
            'table_type': 'BASE TABLE',
            'name': 'SalesLT.Customer'
        }, {
            'table_schema': 'SalesLT',
            'table_name': 'ProductModel',
            'table_type': 'BASE TABLE',
            'name': 'SalesLT.ProductModel'
        }, {
            'table_schema': 'mySchema',
            'table_name': 'someTable',
            'table_type': 'VIEW',
            'name': 'mySchema.someTable (VIEW)'
        }]

        inst = Postgres(self.source, OPTIONS)
        m.return_value.cursor.return_value.fetchall.return_value = mock_tables

        tables = inst.get_tables()
        self.assertEqual(len(tables), len(mock_tables))
        for x in range(0, len(tables)):
            mtable = mock_tables[x]
            v = '{}.{}'.format(mtable["table_schema"], mtable["table_name"])

            self.assertEqual(tables[x]['name'], mtable['name'])
            self.assertEqual(tables[x]['value'], v)