File: test_connection_as_dict.py

package info (click to toggle)
pymssql 2.3.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 972 kB
  • sloc: python: 3,780; sh: 153; makefile: 151; ansic: 1
file content (50 lines) | stat: -rw-r--r-- 1,294 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
"""
Test connection with as_dict=True.
"""

import unittest

import pytest

import pymssql

from .helpers import config

def pymssqlconn(**kwargs):
    return pymssql.connect(
            server=config.server,
            user=config.user,
            password=config.password,
            database=config.database,
            port=config.port,
            **kwargs
        )


@pytest.mark.mssql_server_required
class TestConnectionAsDict(unittest.TestCase):

    def setUp(self):
        self.conn = pymssqlconn(as_dict=True)

    def test_fetchall_with_connection_as_dict(self):
        # This test is for http://code.google.com/p/pymssql/issues/detail?id=18
        cursor = self.conn.cursor()
        cursor.execute("SELECT 'foo' AS first_name, 'bar' AS last_name")
        data = cursor.fetchall()
        self.assertEqual(data, [{'first_name': 'foo', 'last_name': 'bar'}])

    def test_no_results_with_connection_as_dict(self):
        # Make sure that checking for columns without names doesn't break
        # statements that don't return results

        cursor = self.conn.cursor()
        cursor.execute("""
        CREATE TABLE daily_measurement (
            datetime DATETIME,
            value FLOAT,
            notes VARCHAR,
        )
        """)