Exemplo n.º 1
0
    def test_execute_keyboard_interrupt_during_scanning(self):
        self.scanner.scan.side_effect = KeyboardInterrupt

        command = commands.ScanCommand(self.db, self.view)

        self.assertRaises(SystemExit, command.execute, self.args)
        self.db.save_notebook.assert_not_called()
Exemplo n.º 2
0
    def test_execute_cannot_open_device(self):
        sane.open.side_effect = _sane.error

        command = commands.ScanCommand(self.db, self.view)

        self.assertRaises(SystemExit, command.execute, self.args)
        self.db.save_notebook.assert_not_called()
        self.view.show_error.assert_called()
Exemplo n.º 3
0
    def test_execute_keyboard_interrupt_when_searching_for_devices(self):
        sane.get_devices.side_effect = KeyboardInterrupt

        command = commands.ScanCommand(self.db, self.view)

        self.assertRaises(SystemExit, command.execute, self.args)
        sane.open.assert_not_called()
        self.db.save_notebook.assert_not_called()
Exemplo n.º 4
0
    def test_execute_wrong_device_set(self):
        self.conf.scanner_device = 'dev'

        sane.open.side_effect = _sane.error

        command = commands.ScanCommand(self.db, self.view)

        self.assertRaises(SystemExit, command.execute, self.args)
        self.db.save_notebook.assert_not_called()
        self.view.show_error.assert_called_once()
Exemplo n.º 5
0
    def test_execute_db_error_notebook_by_title(self):
        self.db.get_notebook_by_title.side_effect = db.Error

        command = commands.ScanCommand(self.db, self.view)

        self.assertRaises(SystemExit, command.execute, self.args)
        self.view.ask_for_pages_to_append.assert_not_called()
        self.view.ask_for_pages_to_replace.assert_not_called()
        sane.open.assert_not_called()
        self.db.save_notebook.assert_not_called()
Exemplo n.º 6
0
    def test_execute_with_pdf_only_option(self):
        self.args.pdf_only = True

        scanner_ = mock.MagicMock()
        callback = mock.MagicMock()

        with mock.patch('smth.scanner.Scanner', return_value=scanner_):
            with mock.patch('smth.commands.ScanCommand.ScannerCallback',
                            return_value=callback):
                commands.ScanCommand(self.db, self.view).execute(self.args)

        scanner_.scan.assert_not_called()
        callback.on_finish.assert_called_once()
Exemplo n.º 7
0
    def test_execute_no_notebooks(self):
        self.db.get_notebook_titles.return_value = []

        with mock.patch(
                'smth.commands.create.CreateCommand') as command_constructor:
            command_ = mock.MagicMock()
            command_constructor.return_value = command_

            with self.assertRaises(SystemExit):
                commands.ScanCommand(self.db, self.view).execute(self.args)

            self.view.ask_for_notebook.assert_not_called()
            self.view.ask_for_pages_to_append.assert_not_called()
            self.view.ask_for_pages_to_replace.assert_not_called()
            command_.execute.assert_called()
            self.scanner.scan.assert_not_called()
Exemplo n.º 8
0
 def test_execute_no_devices(self):
     sane.get_devices.return_value = []
     command = commands.ScanCommand(self.db, self.view)
     self.assertRaises(SystemExit, command.execute, self.args)
     self.view.show_error.assert_called()
Exemplo n.º 9
0
 def test_execute_no_notebook_chosen(self):
     self.view.ask_for_notebook.return_value = ''
     with mock.patch('smth.scanner.Scanner', return_value=mock.MagicMock()):
         command = commands.ScanCommand(self.db, self.view)
         self.assertRaises(SystemExit, command.execute, self.args)
Exemplo n.º 10
0
    def test_execute_with_set_device_option(self):
        self.args.set_device = True

        with mock.patch('smth.scanner.Scanner', return_value=mock.MagicMock()):
            commands.ScanCommand(self.db, self.view).execute(self.args)
        self.assertEqual(self.conf.scanner_device, '')
Exemplo n.º 11
0
def scan(args, db_: db. DB, view_: view.View) -> None:
    """Runs `scan` command."""
    commands.ScanCommand(db_, view_).execute(args)