import os
import unittest
import subprocess

TEST_PROJECT_DIR = os.path.join(os.path.dirname(__file__), 'test_project/')

class MySqlTest(unittest.TestCase):
    def test_sqlgeneration_create_table(self):
        cmd = '(cd {0} && python manage.py sqlmigrate test_app 0001)'.format(TEST_PROJECT_DIR)
        process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        process.wait()

        self.assertEqual(process.returncode, 0)

        contains_create_table = any(x.strip() == 'CREATE TABLE `test_app_a` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `null_field` integer NULL);' for x in process.stdout)
        self.assertTrue(contains_create_table)

    def test_sqlgeneration_add_not_null_field(self):
        cmd = '(cd {0} && python manage.py sqlmigrate test_app 0002)'.format(TEST_PROJECT_DIR)
        process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        process.wait()

        self.assertEqual(process.returncode, 0)

        contains_add_column = any(x.strip() == 'ALTER TABLE `test_app_a` ADD COLUMN `new_not_null_field` integer DEFAULT 1 NOT NULL;' for x in process.stdout)
        contains_drop_default = any(x.strip() == 'ALTER TABLE `test_app_a` ALTER COLUMN `new_not_null_field` DROP DEFAULT;' for x in process.stdout)
        self.assertTrue(contains_add_column)
        self.assertTrue(contains_drop_default)

    def test_cannot_migrate(self):
        cmd = '(cd {0} && python manage.py migrate)'.format(TEST_PROJECT_DIR)
        process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        process.wait()

        self.assertNotEqual(process.returncode, 0)

    #def test_show_warning_runserver(self):
        #cmd = '(cd {0} && python manage.py runserver)'.format(TEST_PROJECT_DIR)
        #process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        #process.wait()

        # TODO

@@ -78,16 +78,32 @@
 os.path.
+abspath(os.path.
 dirname(
@@ -111,16 +111,17 @@
 _file__)
+)
 , 'test_
@@ -135,44 +135,467 @@
 /')%0A
-%0Aclass MySqlTest(unittest.TestCase):
+SRC_DIR = os.path.join(%0A    os.path.dirname(os.path.abspath(os.path.dirname(__file__))),%0A    'django_fake_database_backends')%0A%0A%0Aclass MySqlTest(unittest.TestCase):%0A    @classmethod%0A    def setUpClass(cls):%0A        cmd = 'cp -rf %7B0%7D %7B1%7D'.format(SRC_DIR, TEST_PROJECT_DIR)%0A        process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)%0A        process.wait()%0A        assert process.returncode == 0%0A        return super(MySqlTest, cls).setUpClass()%0A
 %0A   
@@ -2292,32 +2292,31 @@
 #process.wait()%0A
-%0A
         # TODO%0A

Copy sources to test folder so dependency works (to do: change this, instead add lib to path)