| | 1 | from django.test import TestCase |
| | 2 | from os import getcwd, chdir, path |
| | 3 | from django.core.management import find_management_module, get_commands |
| | 4 | import sys |
| | 5 | |
| | 6 | class TestUserCommand(TestCase): |
| | 7 | |
| | 8 | command_name = 'dance' |
| | 9 | |
| | 10 | def setUp(self): |
| | 11 | self.old_wd = getcwd() |
| | 12 | self.app_wd = path.dirname(__file__) |
| | 13 | self.cur_wd = path.dirname(self.app_wd) |
| | 14 | self.test_wd = path.dirname(self.cur_wd) |
| | 15 | self.app_name = ".".join(map(path.basename,(self.cur_wd,self.app_wd))) |
| | 16 | |
| | 17 | if '' not in sys.path: |
| | 18 | sys.path.insert(0,'') |
| | 19 | if self.test_wd in sys.path: |
| | 20 | sys.path.remove(self.test_wd) |
| | 21 | chdir(self.cur_wd) |
| | 22 | |
| | 23 | def testFindManagementModule(self): |
| | 24 | find_management_module(self.app_name) |
| | 25 | self.assertRaises(ImportError,find_management_module,self.app_name + "xxxxxx") |
| | 26 | |
| | 27 | def testGetCommands(self): |
| | 28 | self.assertTrue( self.command_name in get_commands().keys() ) |
| | 29 | |
| | 30 | def tearDown(self): |
| | 31 | chdir(self.old_wd) |
| | 32 | sys.path.insert(0,self.test_wd) |