~ubuntu-branches/ubuntu/trusty/mysql-connector-python/trusty

« back to all changes in this revision

Viewing changes to tests/test_errorcode.py

  • Committer: Package Import Robot
  • Author(s): Sandro Tosi, Jakub Wilk, Sandro Tosi
  • Date: 2014-02-18 16:26:46 UTC
  • mfrom: (1.2.1) (2.1.5 experimental)
  • Revision ID: package-import@ubuntu.com-20140218162646-1mvqa9g0ypnbqsq6
Tags: 1.1.5-1
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Sandro Tosi ]
* New upstream release
* debian/watch
  - updated to reflect upstream website changes
* debian/copyright
  - fix license, it's only GPLv2
  - update upstream copyright years
  - extend packaging copyright years
  - add reference to local GPL-2 file for packaging copyright notice
* debian/control
  - switch me to Maintainer (team to Uploaders)
  - bump Standards-Version to 3.9.5 (no changes needed)
* debian/rules
  - Disable test execution, currently broken upstream - see 739189
* Switch to dh_python2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# MySQL Connector/Python - MySQL driver written in Python.
 
2
# Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
 
3
 
 
4
# MySQL Connector/Python is licensed under the terms of the GPLv2
 
5
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
 
6
# MySQL Connectors. There are special exceptions to the terms and
 
7
# conditions of the GPLv2 as it is applied to this software, see the
 
8
# FOSS License Exception
 
9
# <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
 
10
#
 
11
# This program is free software; you can redistribute it and/or modify
 
12
# it under the terms of the GNU General Public License as published by
 
13
# the Free Software Foundation.
 
14
#
 
15
# This program is distributed in the hope that it will be useful,
 
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
# GNU General Public License for more details.
 
19
#
 
20
# You should have received a copy of the GNU General Public License
 
21
# along with this program; if not, write to the Free Software
 
22
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
23
 
 
24
"""Unittests for mysql.connector.errorcode
 
25
"""
 
26
 
 
27
from datetime import datetime
 
28
import tests
 
29
from mysql.connector import errorcode
 
30
 
 
31
 
 
32
class ErrorCodeTests(tests.MySQLConnectorTests):
 
33
 
 
34
    def test__GENERATED_ON(self):
 
35
        self.assertTrue(isinstance(errorcode._GENERATED_ON, str))
 
36
        try:
 
37
            generatedon = datetime.strptime(errorcode._GENERATED_ON,
 
38
                                            '%Y-%m-%d').date()
 
39
        except ValueError as err:
 
40
            self.fail(err)
 
41
 
 
42
        delta = (datetime.now().date() - generatedon).days
 
43
        self.assertTrue(
 
44
            delta < 120,
 
45
            "errorcode.py is more than 120 days old ({0})".format(delta))
 
46
 
 
47
    def test__MYSQL_VERSION(self):
 
48
        minimum = (5, 6, 6)
 
49
        self.assertTrue(isinstance(errorcode._MYSQL_VERSION, tuple))
 
50
        self.assertTrue(len(errorcode._MYSQL_VERSION) == 3)
 
51
        self.assertTrue(errorcode._MYSQL_VERSION >= minimum)
 
52
 
 
53
    def _check_code(self, code, num):
 
54
        try:
 
55
            self.assertEqual(getattr(errorcode, code), num)
 
56
        except AttributeError as err:
 
57
            self.fail(err)
 
58
 
 
59
    def test_server_error_codes(self):
 
60
        cases = {
 
61
            'ER_HASHCHK': 1000,
 
62
            'ER_TRG_INVALID_CREATION_CTX': 1604,
 
63
            'ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION': 1792,
 
64
        }
 
65
 
 
66
        for code, num in cases.items():
 
67
            self._check_code(code, num)
 
68
 
 
69
    def test_client_error_codes(self):
 
70
        cases = {
 
71
            'CR_UNKNOWN_ERROR': 2000,
 
72
            'CR_PROBE_SLAVE_STATUS': 2022,
 
73
            'CR_AUTH_PLUGIN_CANNOT_LOAD': 2059,
 
74
        }
 
75
 
 
76
        for code, num in cases.items():
 
77
            self._check_code(code, num)