示例#1
0
 def test_db_command_status(self):
     mock_args = mock.MagicMock()
     mock_args.command = 'status'
     db_command(mock_args)
     self.mock_run_process.assert_called_with(
         ['pg_ctl', 'status', '-D', 'foo/data'],
         'Checking status of Postgresql database server...', '')
示例#2
0
 def test_db_command_createsuperuser(self, mock_load_apps,
                                     mock_create_superuser, _):
     mock_args = mock.MagicMock()
     mock_args.command = 'createsuperuser'
     db_command(mock_args)
     mock_load_apps.assert_called()
     mock_create_superuser.assert_called_with('PFoo', 'PEmail', 'PBar')
示例#3
0
 def test_db_command_migrate(self, mock_get_manage_path):
     mock_args = mock.MagicMock()
     mock_args.command = 'migrate'
     db_command(mock_args)
     mock_get_manage_path.assert_called()
     self.mock_run_process.assert_called_with(
         ['python', 'foo/manage.py', 'migrate', '--database', 'test'],
         'Running migrations for Tethys database...')
示例#4
0
 def test_db_command_stop(self):
     mock_args = mock.MagicMock()
     mock_args.command = 'stop'
     db_command(mock_args)
     self.mock_run_process.assert_called_with(
         ['pg_ctl', '-U', 'postgres', '-D', 'foo/data', 'stop'],
         'Stopping Postgresql database server...',
         'There was an error while stopping the Posgresql database.')
示例#5
0
 def test_db_command_init(self):
     mock_args = mock.MagicMock()
     mock_args.command = 'init'
     db_command(mock_args)
     self.mock_run_process.assert_called_with(
         ['initdb', '-U', 'postgres', '-D', 'foo/data'],
         'Initializing Postgresql database server in "foo/data"...',
         'Could not initialize the Postgresql database.')
示例#6
0
 def test_db_command_start(self):
     mock_args = mock.MagicMock()
     mock_args.command = 'start'
     db_command(mock_args)
     kwargs = self._get_kwargs(remove=['db_dir', 'port'])
     self.mock_run_process.assert_called_with(['pg_ctl', '-U', 'postgres', '-D', 'foo/data', '-l',
                                               'foo/logfile', 'start', '-o', '-p 0000'],
                                              'Starting Postgresql database server in "foo/data" on port 0000...',
                                              'There was an error while starting the Postgresql database.', **kwargs)
示例#7
0
    def test_db_command_sync(self, MockSingletonHarvester, _):
        # mock the input args
        args = mock.MagicMock(manage='', command='sync', port='8080')

        # call the testing method with the mock args
        db_command(args)

        # mock the singleton harvester
        MockSingletonHarvester.assert_called()
        MockSingletonHarvester().harvest.assert_called()
示例#8
0
 def test_db_command_configure(self, mock_init, mock_start, mock_create,
                               mock_migrate, mock_createsuperuser):
     mock_args = mock.MagicMock()
     mock_args.command = 'configure'
     db_command(mock_args)
     mock_init.assert_called_with(**self.options)
     mock_start.assert_called_with(**self.options)
     mock_create.assert_called_with(**self.options)
     mock_migrate.assert_called_with(**self.options)
     mock_createsuperuser.assert_called_with(**self.options)
示例#9
0
 def test_db_command_createsuperuser(self, mock_load_apps, mock_create_superuser, mock_write_error, _):
     from django.db.utils import IntegrityError
     mock_args = mock.MagicMock()
     mock_args.command = 'createsuperuser'
     mock_create_superuser.side_effect = IntegrityError
     db_command(mock_args)
     mock_load_apps.assert_called()
     mock_create_superuser.assert_called_with('PFoo', 'PEmail', 'PBar')
     portal_superuser = self.options['portal_superuser_name']
     mock_write_error.assert_called_with(f'Tethys Portal Superuser "{portal_superuser}" already exists.')
示例#10
0
    def test_purge_db_server(self, mock_stop, mock_write_error, mock_rmtree):
        mock_args = mock.MagicMock()
        mock_args.command = 'purge'

        kwargs = self._get_kwargs()
        kwargs.update(exit_on_error=False)

        db_command(mock_args)
        mock_stop.assert_called_with(**kwargs)
        mock_write_error.assert_called_once()
        mock_rmtree.assert_called_with(kwargs['db_dir'])
示例#11
0
 def test_db_command_create(self, mock_create_db_user):
     mock_args = mock.MagicMock()
     mock_args.command = 'create'
     db_command(mock_args)
     call_args = mock_create_db_user.call_args_list
     kwargs = self._get_kwargs(remove=['superuser_name', 'superuser_password'])
     self.assertEqual(call_args[1], mock.call(**kwargs))
     kwargs.pop('db_name')
     kwargs['username'] = self.options['superuser_name']
     kwargs['password'] = self.options['superuser_password']
     self.assertEqual(call_args[0], mock.call(is_superuser=True, **kwargs))
示例#12
0
 def test_db_command_configure(self, mock_prompt_err, mock_migrate, mock_createsuperuser):
     mock_args = mock.MagicMock()
     mock_args.command = 'configure'
     db_command(mock_args)
     kwargs = self._get_kwargs()
     calls = [
         mock.call(init_db_server, **kwargs),
         mock.call(start_db_server, **kwargs),
         mock.call(create_tethys_db, **kwargs),
     ]
     mock_prompt_err.assert_has_calls(calls)
     mock_migrate.assert_called_with(**self.options)
     mock_createsuperuser.assert_called_with(**self.options)
示例#13
0
 def test_db_command_create(self, mock_create_db_user):
     mock_args = mock.MagicMock()
     mock_args.command = 'create'
     db_command(mock_args)
     call_args = mock_create_db_user.call_args_list
     self.assertEqual(
         call_args[0],
         mock.call(hostname=self.options['hostname'],
                   port=self.options['port'],
                   username=self.options['username'],
                   password=self.options['password'],
                   db_name=self.options['db_name']))
     mock_create_db_user.assert_called_with(
         hostname=self.options['hostname'],
         port=self.options['port'],
         username=self.options['superuser_name'],
         password=self.options['superuser_password'],
         is_superuser=True)