aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/buildbot-0.8.8-py2.7.egg/buildbot/test/unit/test_db_model.py
blob: 99af34ef6e0dc32955a19a2712ada61a36bcd2d3 (plain)
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
51
52
53
54
55
56
57
58
# This file is part of Buildbot.  Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members

import os
import mock
from twisted.trial import unittest
from twisted.internet import defer
from buildbot.db import model, enginestrategy
from buildbot.test.util import db

class DBConnector_Basic(db.RealDatabaseMixin, unittest.TestCase):
    """
    Basic tests of the DBConnector class - all start with an empty DB
    """

    def setUp(self):
        d = self.setUpRealDatabase()
        def make_fake_pool(_):
            engine = enginestrategy.create_engine(self.db_url,
                        basedir=os.path.abspath('basedir'))

            # mock out the pool, and set up the model
            self.db = mock.Mock()
            self.db.pool.do_with_engine = lambda thd : defer.maybeDeferred(thd,engine)
            self.db.model = model.Model(self.db)
            self.db.start()
        d.addCallback(make_fake_pool)
        return d

    def tearDown(self):
        self.db.stop()
        return self.tearDownRealDatabase()

    def test_is_current_empty(self):
        d = self.db.model.is_current()
        d.addCallback(lambda r : self.assertFalse(r))
        return d

    def test_is_current_full(self):
        d = self.db.model.upgrade()
        d.addCallback(lambda _ : self.db.model.is_current())
        d.addCallback(lambda r : self.assertTrue(r))
        return d

    # the upgrade method is very well-tested by the integration tests; the
    # remainder of the object is just tables.