xref: /OK3568_Linux_fs/yocto/bitbake/lib/toaster/tests/db/test_db.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# The MIT License (MIT)
2*4882a593Smuzhiyun#
3*4882a593Smuzhiyun# Copyright (c) 2016 Damien Lespiau
4*4882a593Smuzhiyun#
5*4882a593Smuzhiyun# SPDX-License-Identifier: MIT
6*4882a593Smuzhiyun#
7*4882a593Smuzhiyun# Permission is hereby granted, free of charge, to any person obtaining a copy
8*4882a593Smuzhiyun# of this software and associated documentation files (the "Software"), to deal
9*4882a593Smuzhiyun# in the Software without restriction, including without limitation the rights
10*4882a593Smuzhiyun# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11*4882a593Smuzhiyun# copies of the Software, and to permit persons to whom the Software is
12*4882a593Smuzhiyun# furnished to do so, subject to the following conditions:
13*4882a593Smuzhiyun#
14*4882a593Smuzhiyun# The above copyright notice and this permission notice shall be included in
15*4882a593Smuzhiyun# all copies or substantial portions of the Software.
16*4882a593Smuzhiyun#
17*4882a593Smuzhiyun# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18*4882a593Smuzhiyun# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19*4882a593Smuzhiyun# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20*4882a593Smuzhiyun# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21*4882a593Smuzhiyun# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22*4882a593Smuzhiyun# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23*4882a593Smuzhiyun# SOFTWARE.
24*4882a593Smuzhiyun
25*4882a593Smuzhiyunimport sys
26*4882a593Smuzhiyun
27*4882a593Smuzhiyuntry:
28*4882a593Smuzhiyun    from StringIO import StringIO
29*4882a593Smuzhiyunexcept ImportError:
30*4882a593Smuzhiyun    from io import StringIO
31*4882a593Smuzhiyun
32*4882a593Smuzhiyunfrom contextlib import contextmanager
33*4882a593Smuzhiyun
34*4882a593Smuzhiyunfrom django.core import management
35*4882a593Smuzhiyunfrom django.test import TestCase
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun@contextmanager
39*4882a593Smuzhiyundef capture(command, *args, **kwargs):
40*4882a593Smuzhiyun    out, sys.stdout = sys.stdout, StringIO()
41*4882a593Smuzhiyun    command(*args, **kwargs)
42*4882a593Smuzhiyun    sys.stdout.seek(0)
43*4882a593Smuzhiyun    yield sys.stdout.read()
44*4882a593Smuzhiyun    sys.stdout = out
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun
47*4882a593Smuzhiyundef makemigrations():
48*4882a593Smuzhiyun    management.call_command('makemigrations')
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun
51*4882a593Smuzhiyunclass MigrationTest(TestCase):
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun    def testPendingMigration(self):
54*4882a593Smuzhiyun        """Make sure there's no pending migration."""
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun        with capture(makemigrations) as output:
57*4882a593Smuzhiyun            self.assertEqual(output, "No changes detected\n")
58