getting file size for all dict files to be downloaded. coming to be 400mb or so.
[worddb.git] / libs / dmigrations / tests / .svn / text-base / commands.py.svn-base
blob8bb79ceff9074505aa5b9da7c7c2d26a641eb670
1 from common import *
2 from django.core.management import call_command
3 import sys
4 from StringIO import StringIO
6 class CommandsTest(TestCase):
7     def set_up(self):
8         self.stdout = sys.stdout
9     
10     def tear_down(self):
11         sys.stdout = self.stdout
12     
13     def test_that_syncdb_raises_exception_based_on_setting(self):
14         from django.conf import settings
15         old_setting = getattr(settings, 'DISABLE_SYNCDB', False)
16         
17         settings.DISABLE_SYNCDB = True
18         self.assertRaises(SystemExit, call_command, 'syncdb')
19         
20         settings.DISABLE_SYNCDB = False
21         self.assert_(not self.pipe_command('syncdb'))
22         
23         settings.DISABLE_SYNCDB = old_setting
24     
25     def pipe_command(self, *args, **kwargs):
26         sys.stdout = StringIO()
27         call_command(*args, **kwargs)
28         res = sys.stdout.getvalue()
29         sys.stdout = self.stdout
30         return res
31     
32     def test_dmigration(self):
33         from django.conf import settings
34         if 'django.contrib.sessions' not in settings.INSTALLED_APPS:
35             print "WARNING: Skipping ./manage.py dmigration tests, " \
36                 "add django.contrib.sessions to INSTALLED_APPS to run them"
37             return
38         
39         # ./manage.py dmigration addcolumn sessions session session_key
40         actual = self.pipe_command(
41             'dmigration', "addcolumn", "sessions", "session", "session_key",
42             output=True
43         )
44         expected = """from dmigrations.mysql import migrations as m\nimport datetime\nmigration = m.AddColumn('sessions', 'session', 'session_key', 'varchar(40) NOT NULL PRIMARY KEY')\n\n"""
45         self.assert_equal(expected, actual)
46         
47         # ./manage.py dmigration migration new something
48         actual = self.pipe_command(
49             'dmigration', "new", "something", output=True
50         )
51         expected = """from dmigrations.mysql import migrations as m
53 class CustomMigration(m.Migration):
54     def __init__(self):
55         sql_up = []
56         sql_down = []
57         super(MyMigration, self).__init__(sql_up=sql_up, sql_down=sql_down)
58     # Or override the up() and down() methods\n\nmigration = CustomMigration()\n\n"""
59         self.assert_equal(expected, actual)
60         
61         # ./manage.py dmigration addindex sessions session expire_date
62         actual = self.pipe_command(
63             'dmigration', "addindex", "sessions", "session", "expire_date", 
64             output=True
65         )
66         expected = """from dmigrations.mysql import migrations as m\nimport datetime\nmigration = m.AddIndex('sessions', 'session', 'expire_date')\n\n"""
67         self.assert_equal(expected, actual)
68         
69         # Simply check they don't raise an exception
70         actual = self.pipe_command(
71             'dmigration', "app", "sessions", output=True
72         )
73         
74         actual = self.pipe_command(
75             'dmigration', "addtable", "sessions", "session", output=True
76         )
77         
78         #actual = self.pipe_command(
79         #    'dmigration', "insert", "sessions", "session", output=True
80         #)