Пример #1
0
 def test_create_test_db(self, *mocked_objects):
     creation = DatabaseCreation(connection)
     # Simulate test database creation raising "database already exists"
     with self.patch_test_db_creation(
             self._execute_raise_database_already_exists):
         with mock.patch('builtins.input', return_value='no'):
             with self.assertRaises(SystemExit):
                 # SystemExit is raised if the user answers "no" to the
                 # prompt asking if it's okay to delete the test database.
                 creation._create_test_db(verbosity=0,
                                          autoclobber=False,
                                          keepdb=False)
         # "Database already exists" error is ignored when keepdb is on
         creation._create_test_db(verbosity=0,
                                  autoclobber=False,
                                  keepdb=True)
     # Simulate test database creation raising unexpected error
     with self.patch_test_db_creation(
             self._execute_raise_permission_denied):
         with self.assertRaises(SystemExit):
             creation._create_test_db(verbosity=0,
                                      autoclobber=False,
                                      keepdb=False)
         with self.assertRaises(SystemExit):
             creation._create_test_db(verbosity=0,
                                      autoclobber=False,
                                      keepdb=True)
Пример #2
0
 def test_create_test_db(self, *mocked_objects):
     creation = DatabaseCreation(connection)
     # Simulate test database creation raising "database already exists"
     with self.patch_test_db_creation(
             self._execute_raise_database_already_exists):
         with mock.patch("builtins.input", return_value="no"):
             with self.assertRaises(SystemExit):
                 # SystemExit is raised if the user answers "no" to the
                 # prompt asking if it's okay to delete the test database.
                 creation._create_test_db(verbosity=0,
                                          autoclobber=False,
                                          keepdb=False)
         # "Database already exists" error is ignored when keepdb is on
         creation._create_test_db(verbosity=0,
                                  autoclobber=False,
                                  keepdb=True)
     # Simulate test database creation raising unexpected error
     with self.patch_test_db_creation(
             self._execute_raise_permission_denied):
         with mock.patch.object(DatabaseCreation,
                                "_database_exists",
                                return_value=False):
             with self.assertRaises(SystemExit):
                 creation._create_test_db(verbosity=0,
                                          autoclobber=False,
                                          keepdb=False)
             with self.assertRaises(SystemExit):
                 creation._create_test_db(verbosity=0,
                                          autoclobber=False,
                                          keepdb=True)
     # Simulate test database creation raising "insufficient privileges".
     # An error shouldn't appear when keepdb is on and the database already
     # exists.
     with self.patch_test_db_creation(
             self._execute_raise_permission_denied):
         with mock.patch.object(DatabaseCreation,
                                "_database_exists",
                                return_value=True):
             creation._create_test_db(verbosity=0,
                                      autoclobber=False,
                                      keepdb=True)
Пример #3
0
 def test_create_test_db(self, *mocked_objects):
     creation = DatabaseCreation(connection)
     # Simulate test database creation raising "database already exists"
     with self.patch_test_db_creation(self._execute_raise_database_already_exists):
         with mock.patch('builtins.input', return_value='no'):
             with self.assertRaises(SystemExit):
                 # SystemExit is raised if the user answers "no" to the
                 # prompt asking if it's okay to delete the test database.
                 creation._create_test_db(verbosity=0, autoclobber=False, keepdb=False)
         # "Database already exists" error is ignored when keepdb is on
         creation._create_test_db(verbosity=0, autoclobber=False, keepdb=True)
     # Simulate test database creation raising unexpected error
     with self.patch_test_db_creation(self._execute_raise_permission_denied):
         with self.assertRaises(SystemExit):
             creation._create_test_db(verbosity=0, autoclobber=False, keepdb=False)
         with self.assertRaises(SystemExit):
             creation._create_test_db(verbosity=0, autoclobber=False, keepdb=True)