示例#1
0
    def test_book_all2(self, mock_stdout):
        """No overwrite."""
        os.makedirs(os.path.join(test_dir, WSB_DIR), exist_ok=True)
        with open(os.path.join(test_dir, WSB_DIR, 'config.ini'), 'w') as f:
            f.write('dummy1')
        with open(os.path.join(test_dir, WSB_DIR, 'serve.py'), 'w') as f:
            f.write('dummy2')
        with open(os.path.join(test_dir, WSB_DIR, 'app.py'), 'w') as f:
            f.write('dummy3')

        cli.cmd_config({
            'root': test_dir,
            'book': True,
            'user': False,
            'all': True,
            'edit': False,
            'name': None,
        })

        with open(os.path.join(test_dir, WSB_DIR, 'config.ini')) as f1:
            self.assertTrue(f1.read(), 'dummy1')

        with open(os.path.join(test_dir, WSB_DIR, 'serve.py')) as f1:
            self.assertTrue(f1.read(), 'dummy2')

        with open(os.path.join(test_dir, WSB_DIR, 'app.py')) as f1:
            self.assertTrue(f1.read(), 'dummy3')

        self.assertEqual(mock_stdout.getvalue(), '')
示例#2
0
    def test_dump(self, mock_dump):
        cli.cmd_config({
            'root': test_dir,
            'book': False,
            'user': False,
            'all': False,
            'edit': False,
            'name': None,
        })

        mock_dump.assert_called_once_with(sys.stdout)
示例#3
0
    def test_name_call(self, mock_getname, mock_stdout):
        cli.cmd_config({
            'root': test_dir,
            'book': False,
            'user': False,
            'all': False,
            'edit': False,
            'name': 'app.name',
        })

        mock_getname.assert_called_once_with('app.name')
        self.assertEqual(mock_stdout.getvalue(), 'dummy\n')
示例#4
0
    def test_all(self, mock_die):
        with self.assertRaises(SystemExit):
            cli.cmd_config({
                'root': test_dir,
                'book': False,
                'user': False,
                'all': True,
                'edit': False,
                'name': None,
            })

        mock_die.assert_called_once_with('Use --all in combine with --book.')
示例#5
0
    def test_name_call2(self, mock_getname, mock_die):
        with self.assertRaises(SystemExit):
            cli.cmd_config({
                'root': test_dir,
                'book': False,
                'user': False,
                'all': False,
                'edit': False,
                'name': 'unknown.config',
            })

        mock_getname.assert_called_once_with('unknown.config')
        mock_die.assert_called_once_with(
            'Config entry "unknown.config" does not exist')
示例#6
0
    def test_book_create(self, mock_stdout):
        cli.cmd_config({
            'root': test_dir,
            'book': True,
            'user': False,
            'all': False,
            'edit': False,
            'name': None,
        })

        with open(os.path.join(test_dir, WSB_DIR, 'config.ini')) as f1:
            with open(os.path.join(resource_dir, 'config.ini')) as f2:
                self.assertTrue(f1.read(), f2.read())

        self.assertNotEqual(mock_stdout.getvalue(), '')
示例#7
0
    def test_user_edit2(self, mock_launch, mock_stdout):
        os.makedirs(os.path.join(test_dir, WSB_DIR), exist_ok=True)
        with open(os.path.join(test_dir, WSB_DIR, 'userconfig.ini'), 'w') as f:
            f.write('dummy')

        cli.cmd_config({
            'root': test_dir,
            'book': False,
            'user': True,
            'all': False,
            'edit': True,
            'name': None,
        })

        mock_launch.assert_called_once_with(
            os.path.join(test_dir, WSB_DIR, 'userconfig.ini'))

        self.assertEqual(mock_stdout.getvalue(), '')
示例#8
0
    def test_user_create2(self, mock_stdout):
        os.makedirs(os.path.join(test_dir, WSB_DIR), exist_ok=True)
        with open(os.path.join(test_dir, WSB_DIR, 'userconfig.ini'), 'w') as f:
            f.write('dummy')

        cli.cmd_config({
            'root': test_dir,
            'book': False,
            'user': True,
            'all': False,
            'edit': False,
            'name': None,
        })

        with open(os.path.join(test_dir, WSB_DIR, 'userconfig.ini')) as f1:
            self.assertTrue(f1.read(), 'dummy')

        self.assertEqual(mock_stdout.getvalue(), '')