def runTest(self, get_server_details_mock,
                get_complete_file_path_mock,
                get_storage_directory_mock,
                realpath_mock):

        name = self.class_params['name']
        host = self.class_params['host']
        port = self.class_params['port']

        get_server_details_mock.return_value = name, host, port

        get_complete_file_path_mock.return_value \
            = self.class_params['filename']
        realpath_mock.return_value = self.class_params['filename']
        get_storage_directory_mock.return_value = '//'

        import_export_obj = IEMessage(
            *self.class_params['args'],
            **{
                'sid': self.class_params['sid'],
                'schema': self.class_params['schema'],
                'table': self.class_params['table'],
                'is_import': self.class_params['is_import'],
                'database': self.class_params['database'],
                'filename': self.class_params['filename'],
                'storage': self.class_params['storage'],
            }
        )

        expected_msg = self.expected_msg.format(
            self.class_params['schema'],
            self.class_params['table'],
            self.class_params['database'],
            self.class_params['host'],
            self.class_params['port']
        )

        # Check the expected message returned
        self.assertEqual(import_export_obj.message, expected_msg)

        # Check the command
        obj_details = import_export_obj.details(self.class_params['cmd'],
                                                self.class_params['args'])

        self.assertIn(self.class_params['schema'], obj_details)
        self.assertIn(self.class_params['table'], obj_details)
        self.assertIn(self.class_params['database'], obj_details)
        self.assertIn(self.class_params['host'], obj_details)
        self.assertIn(str(self.class_params['port']), obj_details)

        if config.SERVER_MODE is False:
            self.skipTest(
                "Skipping tests for Storage manager in Desktop mode."
            )
        else:
            storage_dir = import_export_obj.current_storage_dir
            self.assertEqual(self.expected_storage_dir, storage_dir)
Exemple #2
0
    def runTest(self, current_user_mock, current_user, db_mock,
                popen_mock, get_server_details_mock):
        with self.app.app_context():
            current_user.id = 1
            current_user_mock.id = 1
            current_app.PGADMIN_RUNTIME = False

            def db_session_add_mock(j):
                cmd_obj = loads(j.desc)
                self.assertTrue(isinstance(cmd_obj, IProcessDesc))

                self.assertEqual(cmd_obj.bfile, self.params['filename'])
                self.assertEqual(cmd_obj.database,
                                 self.class_params['database'])

                command = ' "' + self.class_params['args'][0] + '"' + \
                          ' "' + '\\' + self.class_params['args'][1].format(
                              self.params['schema'],
                              self.params['table'],
                              self.params['columns'][0],
                              self.params['columns'][1],
                              self.params['filename'],
                              '\\' + self.params['quote']
                ) + '"'
                self.assertEqual(cmd_obj._cmd, command)

            db_mock.session.add.side_effect = db_session_add_mock
            db_mock.session.commit = MagicMock(return_value=True)

            get_server_details_mock.return_value = \
                self.class_params['name'], \
                self.class_params['host'], \
                self.class_params['port']

            args = self.class_params['args'][1].format(
                self.params['schema'],
                self.params['table'],
                self.params['columns'][0],
                self.params['columns'][1],
                self.params['filename'],
                self.params['quote']
            )

            import_export_obj = IEMessage(
                *[self.class_params['args'][0], args],
                **{
                    'sid': self.class_params['sid'],
                    'schema': self.params['schema'],
                    'table': self.params['table'],
                    'is_import': self.params['is_import'],
                    'database': self.params['database'],
                    'filename': self.params['filename'],
                    'storage': self.params['storage'],
                }
            )

            p = BatchProcess(
                desc=import_export_obj,
                cmd=self.class_params['cmd'],
                args=args
            )

            # Check that _create_process has been called
            self.assertTrue(db_mock.session.add.called)

            # Check start method
            self._check_start(popen_mock, p, import_export_obj)

            # Check list method
            self._check_list(p, import_export_obj)