BalsamTestCase.py 1.1 KB
Newer Older
1
2
import os
import unittest
Michael Salim's avatar
Michael Salim committed
3
import subprocess
4
5
6
7
8
9
10
11

from django.core.management import call_command
from django import db
from django.conf import settings

class BalsamTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
Michael Salim's avatar
Michael Salim committed
12
        assert db.connection.settings_dict['NAME'].endswith('test_db.sqlite3')
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
        call_command('makemigrations',interactive=False,verbosity=0)
        call_command('migrate',interactive=False,verbosity=0)
        assert os.path.exists(settings.DATABASES['default']['NAME'])

    @classmethod
    def tearDownClass(cls):
        pass

    def setUp(self):
        pass # to be implemented by test cases

    def tearDown(self):
        if not db.connection.settings_dict['NAME'].endswith('test_db.sqlite3'):
            raise RuntimeError("Test DB not configured")
        call_command('flush',interactive=False,verbosity=0)
Michael Salim's avatar
Michael Salim committed
28
29
30
31
32
33

def cmdline(cmd,envs=None,shell=True):
    '''Return string output from a command line'''
    p = subprocess.Popen(cmd, shell=shell, stdout=subprocess.PIPE,
                         stderr=subprocess.STDOUT,env=envs)
    return p.communicate()[0].decode('utf-8')