~launchpad-committers/storm/lp

« back to all changes in this revision

Viewing changes to storm/tests/store/mysql.py

  • Committer: Colin Watson
  • Date: 2023-07-06 10:51:34 UTC
  • mfrom: (386.34.138 storm)
  • Revision ID: cjwatson@canonical.com-20230706105134-rzpb4opv8nfpg56r
Merge Storm 0.26 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright (c) 2006, 2007 Canonical
 
3
#
 
4
# Written by Gustavo Niemeyer <gustavo@niemeyer.net>
 
5
#
 
6
# This file is part of Storm Object Relational Mapper.
 
7
#
 
8
# Storm is free software; you can redistribute it and/or modify
 
9
# it under the terms of the GNU Lesser General Public License as
 
10
# published by the Free Software Foundation; either version 2.1 of
 
11
# the License, or (at your option) any later version.
 
12
#
 
13
# Storm is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
# GNU Lesser General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU Lesser General Public License
 
19
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
from __future__ import print_function
 
22
 
 
23
import os
 
24
 
 
25
from storm.database import create_database
 
26
 
 
27
from storm.tests.store.base import StoreTest, EmptyResultSetTest
 
28
from storm.tests.helper import TestHelper
 
29
 
 
30
 
 
31
class MySQLStoreTest(TestHelper, StoreTest):
 
32
 
 
33
    def setUp(self):
 
34
        TestHelper.setUp(self)
 
35
        StoreTest.setUp(self)
 
36
 
 
37
    def tearDown(self):
 
38
        TestHelper.tearDown(self)
 
39
        StoreTest.tearDown(self)
 
40
 
 
41
    def is_supported(self):
 
42
        return bool(os.environ.get("STORM_MYSQL_URI"))
 
43
 
 
44
    def create_database(self):
 
45
        self.database = create_database(os.environ["STORM_MYSQL_URI"])
 
46
 
 
47
    def create_tables(self):
 
48
        connection = self.connection
 
49
        connection.execute("CREATE TABLE foo "
 
50
                           "(id INT PRIMARY KEY AUTO_INCREMENT,"
 
51
                           " title VARCHAR(50) DEFAULT 'Default Title') "
 
52
                           "ENGINE=InnoDB")
 
53
        connection.execute("CREATE TABLE bar "
 
54
                           "(id INT PRIMARY KEY AUTO_INCREMENT,"
 
55
                           " foo_id INTEGER, title VARCHAR(50)) "
 
56
                           "ENGINE=InnoDB")
 
57
        connection.execute("CREATE TABLE bin "
 
58
                           "(id INT PRIMARY KEY AUTO_INCREMENT,"
 
59
                           " bin BLOB, foo_id INTEGER) "
 
60
                           "ENGINE=InnoDB")
 
61
        connection.execute("CREATE TABLE link "
 
62
                           "(foo_id INTEGER, bar_id INTEGER,"
 
63
                           " PRIMARY KEY (foo_id, bar_id)) "
 
64
                           "ENGINE=InnoDB")
 
65
        connection.execute("CREATE TABLE money "
 
66
                           "(id INT PRIMARY KEY AUTO_INCREMENT,"
 
67
                           " value NUMERIC(6,4)) "
 
68
                           "ENGINE=InnoDB")
 
69
        connection.execute("CREATE TABLE selfref "
 
70
                           "(id INT PRIMARY KEY AUTO_INCREMENT,"
 
71
                           " title VARCHAR(50),"
 
72
                           " selfref_id INTEGER,"
 
73
                           " INDEX (selfref_id),"
 
74
                           " FOREIGN KEY (selfref_id) REFERENCES selfref(id)) "
 
75
                           "ENGINE=InnoDB")
 
76
        connection.execute("CREATE TABLE foovalue "
 
77
                           "(id INT PRIMARY KEY AUTO_INCREMENT,"
 
78
                           " foo_id INTEGER,"
 
79
                           " value1 INTEGER, value2 INTEGER) "
 
80
                           "ENGINE=InnoDB")
 
81
        connection.execute("CREATE TABLE unique_id "
 
82
                           "(id VARCHAR(36) PRIMARY KEY) "
 
83
                           "ENGINE=InnoDB")
 
84
        connection.commit()
 
85
 
 
86
 
 
87
class MySQLEmptyResultSetTest(TestHelper, EmptyResultSetTest):
 
88
 
 
89
    def setUp(self):
 
90
        TestHelper.setUp(self)
 
91
        EmptyResultSetTest.setUp(self)
 
92
 
 
93
    def tearDown(self):
 
94
        TestHelper.tearDown(self)
 
95
        EmptyResultSetTest.tearDown(self)
 
96
 
 
97
    def is_supported(self):
 
98
        return bool(os.environ.get("STORM_MYSQL_URI"))
 
99
 
 
100
    def create_database(self):
 
101
        self.database = create_database(os.environ["STORM_MYSQL_URI"])
 
102
 
 
103
    def create_tables(self):
 
104
        self.connection.execute("CREATE TABLE foo "
 
105
                                "(id INT PRIMARY KEY AUTO_INCREMENT,"
 
106
                                " title VARCHAR(50) DEFAULT 'Default Title') "
 
107
                                "ENGINE=InnoDB")
 
108
        self.connection.commit()