コード例 #1
0
ファイル: test_main.py プロジェクト: rlugojr/kinto
 def test_cli_can_configure_logger_in_debug(self):
     with mock.patch('kinto.__main__.logging') as mocked_logging:
         main(['--debug', '--ini', TEMP_KINTO_INI, 'init',
               '--backend', 'memory'])
         mocked_logging.basicConfig.assert_called_with(
             level=mocked_logging.DEBUG,
             format=DEFAULT_LOG_FORMAT)
コード例 #2
0
ファイル: test_main.py プロジェクト: pombredanne/kinto
 def test_cli_delete_collection_run_delete_collection_script(self):
     with mock.patch("kinto.__main__.scripts.delete_collection") as del_col:
         del_col.return_value = mock.sentinel.del_col_code
         res = main(
             [
                 "init",
                 "--ini",
                 TEMP_KINTO_INI,
                 "--backend",
                 "memory",
                 "--cache-backend",
                 "memory",
             ]
         )
         assert res == 0
         res = main(
             [
                 "delete-collection",
                 "--ini",
                 TEMP_KINTO_INI,
                 "--bucket",
                 "test_bucket",
                 "--collection",
                 "test_collection",
             ]
         )
         assert res == mock.sentinel.del_col_code
         assert del_col.call_count == 1
コード例 #3
0
ファイル: test_main.py プロジェクト: rlugojr/kinto
 def test_cli_use_default_logging_logger(self):
     with mock.patch('kinto.__main__.logging') as mocked_logging:
         main(['--ini', TEMP_KINTO_INI, 'init',
               '--backend', 'memory'])
         mocked_logging.basicConfig.assert_called_with(
             level=logging.INFO,
             format=DEFAULT_LOG_FORMAT)
コード例 #4
0
ファイル: test_main.py プロジェクト: mohamedMaalej/kinto
 def test_cli_start_runs_pserve(self):
     with mock.patch('kinto.__main__.pserve.main') as mocked_pserve:
         res = main(['--ini', TEMP_KINTO_INI,
                     '--backend', 'memory', 'init'])
         assert res == 0
         res = main(['--ini', TEMP_KINTO_INI, 'start'])
         assert res == 0
         assert mocked_pserve.call_count == 1
コード例 #5
0
ファイル: test_main.py プロジェクト: mohamedMaalej/kinto
 def test_cli_migrate_command_runs_init_schema(self):
     with mock.patch('kinto.__main__.cliquet.init_schema') as mocked_init:
         res = main(['--ini', TEMP_KINTO_INI,
                     '--backend', 'memory', 'init'])
         assert res == 0
         res = main(['--ini', TEMP_KINTO_INI, 'migrate'])
         assert res == 0
         assert mocked_init.call_count == 1
コード例 #6
0
ファイル: test_main.py プロジェクト: michaelferreira/kinto
 def test_cli_start_with_reload_runs_pserve_with_reload(self):
     with mock.patch('kinto.__main__.pserve.main') as mocked_pserve:
         res = main(['--ini', TEMP_KINTO_INI, 'init',
                     '--backend', 'memory'])
         assert res == 0
         res = main(['--ini', TEMP_KINTO_INI, 'start', '--reload'])
         assert res == 0
         assert mocked_pserve.call_count == 1
         assert '--reload' in mocked_pserve.call_args[0][0]
コード例 #7
0
ファイル: test_main.py プロジェクト: mohamedMaalej/kinto
    def test_main_takes_sys_argv_by_default(self):
        testargs = ["prog", "--ini", TEMP_KINTO_INI,
                    '--backend', 'memory', 'init']
        with mock.patch.object(sys, 'argv', testargs):
            main()

        with open(TEMP_KINTO_INI) as f:
            content = f.read()
        assert 'memory' in content
コード例 #8
0
ファイル: test_main.py プロジェクト: profmcdan/kinto
 def test_cli_start_runs_pserve(self):
     with mock.patch('kinto.__main__.pserve.main') as mocked_pserve:
         res = main([
             'init', '--ini', TEMP_KINTO_INI, '--backend', 'memory',
             '--cache-backend', 'memory'
         ])
         assert res == 0
         res = main(['start', '--ini', TEMP_KINTO_INI])
         assert res == 0
         assert mocked_pserve.call_count == 1
コード例 #9
0
ファイル: test_main.py プロジェクト: profmcdan/kinto
 def test_cli_migrate_command_runs_init_schema(self):
     with mock.patch('kinto.__main__.scripts.migrate') as mocked_migrate:
         res = main([
             'init', '--ini', TEMP_KINTO_INI, '--backend', 'memory',
             '--cache-backend', 'memory'
         ])
         assert res == 0
         res = main(['migrate', '--ini', TEMP_KINTO_INI])
         assert res == 0
         assert mocked_migrate.call_count == 1
コード例 #10
0
    def test_main_takes_sys_argv_by_default(self):
        testargs = [
            'prog', 'init', '--ini', TEMP_KINTO_INI, '--backend', 'memory'
        ]
        with mock.patch.object(sys, 'argv', testargs):
            main()

        with open(TEMP_KINTO_INI) as f:
            content = f.read()
        assert 'memory' in content
コード例 #11
0
ファイル: test_main.py プロジェクト: makaisson/kinto
 def test_cli_delete_collection_run_delete_collection_script(self):
     with mock.patch('kinto.__main__.scripts.delete_collection') as del_col:
         del_col.return_value = mock.sentinel.del_col_code
         res = main(['init', '--ini', TEMP_KINTO_INI, '--backend', 'memory'])
         assert res == 0
         res = main(['delete-collection', '--ini', TEMP_KINTO_INI,
                     '--bucket', 'test_bucket',
                     '--collection', 'test_collection'])
         assert res == mock.sentinel.del_col_code
         assert del_col.call_count == 1
コード例 #12
0
ファイル: test_main.py プロジェクト: profmcdan/kinto
 def test_cli_start_with_verbose_option_runs_pserve_with_verbose(self):
     with mock.patch('kinto.__main__.pserve.main') as mocked_pserve:
         res = main([
             'init', '--ini', TEMP_KINTO_INI, '--backend', 'memory',
             '--cache-backend', 'memory'
         ])
         assert res == 0
         res = main(['start', '-v', '--ini', TEMP_KINTO_INI])
         assert res == 0
         assert mocked_pserve.call_count == 1
         assert mocked_pserve.call_args[1]['argv'][1] == '-v'
コード例 #13
0
ファイル: test_main.py プロジェクト: profmcdan/kinto
 def test_cli_rebuild_quotas_run_rebuild_quotas_script(self):
     with mock.patch('kinto.__main__.scripts.rebuild_quotas') as reb_quo:
         reb_quo.return_value = mock.sentinel.reb_quo_code
         res = main([
             'init', '--ini', TEMP_KINTO_INI, '--backend', 'memory',
             '--cache-backend', 'memory'
         ])
         assert res == 0
         res = main(['rebuild-quotas', '--ini', TEMP_KINTO_INI])
         assert res == mock.sentinel.reb_quo_code
         assert reb_quo.call_count == 1
コード例 #14
0
ファイル: test_main.py プロジェクト: michaelferreira/kinto
 def test_cli_delete_collection_run_delete_collection_script(self):
     with mock.patch('kinto.__main__.scripts.delete_collection') as del_col:
         del_col.return_value = mock.sentinel.del_col_code
         res = main(['--ini', TEMP_KINTO_INI, 'init',
                     '--backend', 'memory'])
         assert res == 0
         res = main(['--ini', TEMP_KINTO_INI, 'delete-collection',
                     '--bucket', 'test_bucket',
                     '--collection', 'test_collection'])
         assert res == mock.sentinel.del_col_code
         assert del_col.call_count == 1
コード例 #15
0
 def test_cli_flush_cache_command_runs_flush_cache_script(self):
     # Build a temporary ini file.
     res = main([
         "init", "--ini", TEMP_KINTO_INI, "--backend", "memory",
         "--cache-backend", "memory"
     ])
     assert res == 0
     with mock.patch("kinto.__main__.core_scripts.flush_cache"
                     ) as mocked_cache_script:
         res = main(["flush-cache", "--ini", TEMP_KINTO_INI])
         assert res == 0
         assert mocked_cache_script.call_count == 1
コード例 #16
0
ファイル: test_main.py プロジェクト: xcffl/kinto
 def test_cli_create_user_runs_account_script(self):
     with mock.patch('kinto.__main__.create_user',
                     return_value=0) as mocked_create_user:
         res = main(
             ['init', '--ini', TEMP_KINTO_INI, '--backend', 'memory'])
         assert res == 0
         res = main([
             'create-user', '--ini', TEMP_KINTO_INI, '-u', 'username', '-p',
             'password'
         ])
         assert res == 0
         mocked_create_user.call_count == 1
コード例 #17
0
 def test_cli_use_default_logging_logger(self):
     with mock.patch("kinto.__main__.logging") as mocked_logging:
         main([
             "init",
             "--ini",
             TEMP_KINTO_INI,
             "--backend",
             "memory",
             "--cache-backend",
             "memory",
         ])
         mocked_logging.basicConfig.assert_called_with(
             level=logging.INFO, format=DEFAULT_LOG_FORMAT)
コード例 #18
0
 def test_cli_can_configure_logger_in_debug(self):
     with mock.patch("kinto.__main__.logging") as mocked_logging:
         main([
             "init",
             "--debug",
             "--ini",
             TEMP_KINTO_INI,
             "--backend",
             "memory",
             "--cache-backend",
             "memory",
         ])
         mocked_logging.basicConfig.assert_called_with(
             level=mocked_logging.DEBUG, format=DEFAULT_LOG_FORMAT)
コード例 #19
0
 def test_cli_start_runs_pserve(self):
     with mock.patch("kinto.__main__.pserve.main") as mocked_pserve:
         res = main([
             "init",
             "--ini",
             TEMP_KINTO_INI,
             "--backend",
             "memory",
             "--cache-backend",
             "memory",
         ])
         assert res == 0
         res = main(["start", "--ini", TEMP_KINTO_INI])
         assert res == 0
         assert mocked_pserve.call_count == 1
コード例 #20
0
ファイル: test_main.py プロジェクト: yanbingms/kinto
 def test_cli_migrate_command_runs_init_schema(self):
     with mock.patch("kinto.__main__.scripts.migrate") as mocked_migrate:
         res = main([
             "init",
             "--ini",
             TEMP_KINTO_INI,
             "--backend",
             "memory",
             "--cache-backend",
             "memory",
         ])
         assert res == 0
         res = main(["migrate", "--ini", TEMP_KINTO_INI])
         assert res == 0
         assert mocked_migrate.call_count == 1
コード例 #21
0
 def test_cli_init_generates_configuration(self):
     res = main([
         "init", "--ini", TEMP_KINTO_INI, "--backend", "memory",
         "--cache-backend", "memory"
     ])
     assert res == 0
     assert os.path.exists(TEMP_KINTO_INI)
コード例 #22
0
ファイル: test_main.py プロジェクト: pombredanne/kinto
 def test_cli_use_default_logging_logger(self):
     with mock.patch("kinto.__main__.logging") as mocked_logging:
         main(
             [
                 "init",
                 "--ini",
                 TEMP_KINTO_INI,
                 "--backend",
                 "memory",
                 "--cache-backend",
                 "memory",
             ]
         )
         mocked_logging.basicConfig.assert_called_with(
             level=logging.INFO, format=DEFAULT_LOG_FORMAT
         )
コード例 #23
0
ファイル: test_main.py プロジェクト: replyanshu/kinto
 def test_cli_init_asks_for_backend_if_not_specified(self):
     with mock.patch("kinto.__main__.input", create=True, return_value="2"):
         res = main(['init', '--ini', TEMP_KINTO_INI])
         assert res == 0
     with open(TEMP_KINTO_INI) as f:
         content = f.read()
     assert 'redis' in content
コード例 #24
0
ファイル: test_main.py プロジェクト: mohamedMaalej/kinto
 def test_cli_init_asks_for_backend_if_not_specified(self):
     with mock.patch("kinto.__main__.input", create=True, return_value="2"):
         res = main(['--ini', TEMP_KINTO_INI, 'init'])
         assert res == 0
     with open(TEMP_KINTO_INI) as f:
         content = f.read()
     assert 'redis' in content
コード例 #25
0
ファイル: test_main.py プロジェクト: pombredanne/kinto
 def test_cli_init_asks_until_cache_backend_is_valid(self):
     with mock.patch("kinto.__main__.input", create=True, side_effect=["2", "21", "2"]):
         res = main(["init", "--ini", TEMP_KINTO_INI])
         assert res == 0
         with open(TEMP_KINTO_INI) as f:
             content = f.read()
         assert "redis" in content
コード例 #26
0
ファイル: test_main.py プロジェクト: yanbingms/kinto
 def test_cli_rebuild_quotas_run_rebuild_quotas_script(self):
     with mock.patch("kinto.__main__.scripts.rebuild_quotas") as reb_quo:
         reb_quo.return_value = mock.sentinel.reb_quo_code
         res = main([
             "init",
             "--ini",
             TEMP_KINTO_INI,
             "--backend",
             "memory",
             "--cache-backend",
             "memory",
         ])
         assert res == 0
         res = main(["rebuild-quotas", "--ini", TEMP_KINTO_INI])
         assert res == mock.sentinel.reb_quo_code
         assert reb_quo.call_count == 1
コード例 #27
0
ファイル: test_main.py プロジェクト: profmcdan/kinto
 def test_cli_init_generates_configuration(self):
     res = main([
         'init', '--ini', TEMP_KINTO_INI, '--backend', 'memory',
         '--cache-backend', 'memory'
     ])
     assert res == 0
     assert os.path.exists(TEMP_KINTO_INI)
コード例 #28
0
 def test_cli_start_with_verbose_option_runs_pserve_with_verbose(self):
     with mock.patch("kinto.__main__.pserve.main") as mocked_pserve:
         res = main([
             "init",
             "--ini",
             TEMP_KINTO_INI,
             "--backend",
             "memory",
             "--cache-backend",
             "memory",
         ])
         assert res == 0
         res = main(["start", "-v", "--ini", TEMP_KINTO_INI])
         assert res == 0
         assert mocked_pserve.call_count == 1
         assert mocked_pserve.call_args[1]["argv"][1] == "-v"
コード例 #29
0
ファイル: test_main.py プロジェクト: makaisson/kinto
 def test_cli_init_asks_until_backend_is_valid(self):
     with mock.patch("kinto.__main__.input", create=True, side_effect=["10", "2"]):
         res = main(['init', '--ini', TEMP_KINTO_INI])
         assert res == 0
         with open(TEMP_KINTO_INI) as f:
             content = f.read()
         assert 'redis' in content
コード例 #30
0
ファイル: test_main.py プロジェクト: pombredanne/kinto
 def test_cli_init_returns_if_file_exists(self):
     with open(TEMP_KINTO_INI, "w") as f:
         f.write("exists")
     with mock.patch("sys.stderr", new_callable=StringIO) as mock_stderr:
         res = main(["init", "--ini", TEMP_KINTO_INI, "--backend", "memory"])
         assert res == 1
         content = mock_stderr.getvalue()
         assert "{} already exists.".format(TEMP_KINTO_INI) in content
コード例 #31
0
ファイル: test_main.py プロジェクト: pombredanne/kinto
 def test_cli_can_configure_logger_in_debug(self):
     with mock.patch("kinto.__main__.logging") as mocked_logging:
         main(
             [
                 "init",
                 "--debug",
                 "--ini",
                 TEMP_KINTO_INI,
                 "--backend",
                 "memory",
                 "--cache-backend",
                 "memory",
             ]
         )
         mocked_logging.basicConfig.assert_called_with(
             level=mocked_logging.DEBUG, format=DEFAULT_LOG_FORMAT
         )
コード例 #32
0
ファイル: test_main.py プロジェクト: pombredanne/kinto
 def test_cli_migrate_command_runs_init_schema(self):
     with mock.patch("kinto.__main__.scripts.migrate") as mocked_migrate:
         res = main(
             [
                 "init",
                 "--ini",
                 TEMP_KINTO_INI,
                 "--backend",
                 "memory",
                 "--cache-backend",
                 "memory",
             ]
         )
         assert res == 0
         res = main(["migrate", "--ini", TEMP_KINTO_INI])
         assert res == 0
         assert mocked_migrate.call_count == 1
コード例 #33
0
ファイル: test_main.py プロジェクト: pombredanne/kinto
 def test_cli_start_runs_pserve(self):
     with mock.patch("kinto.__main__.pserve.main") as mocked_pserve:
         res = main(
             [
                 "init",
                 "--ini",
                 TEMP_KINTO_INI,
                 "--backend",
                 "memory",
                 "--cache-backend",
                 "memory",
             ]
         )
         assert res == 0
         res = main(["start", "--ini", TEMP_KINTO_INI])
         assert res == 0
         assert mocked_pserve.call_count == 1
コード例 #34
0
ファイル: test_main.py プロジェクト: makaisson/kinto
 def test_cli_init_returns_if_file_exists(self):
     with open(TEMP_KINTO_INI, 'w') as f:
         f.write("exists")
     with mock.patch('sys.stderr', new_callable=StringIO) as mock_stderr:
         res = main(['init', '--ini', TEMP_KINTO_INI, '--backend', 'memory'])
         assert res == 1
         content = mock_stderr.getvalue()
         assert '{} already exists.'.format(TEMP_KINTO_INI) in content
コード例 #35
0
ファイル: test_main.py プロジェクト: pombredanne/kinto
    def test_main_takes_sys_argv_by_default(self):
        testargs = [
            "prog",
            "init",
            "--ini",
            TEMP_KINTO_INI,
            "--backend",
            "memory",
            "--cache-backend",
            "memory",
        ]
        with mock.patch.object(sys, "argv", testargs):
            main()

        with open(TEMP_KINTO_INI) as f:
            content = f.read()
        assert "memory" in content
コード例 #36
0
ファイル: test_main.py プロジェクト: mohamedMaalej/kinto
 def test_cli_init_asks_until_backend_is_valid(self):
     with mock.patch("kinto.__main__.input", create=True,
                     side_effect=["10", "2"]):
         res = main(['--ini', TEMP_KINTO_INI, 'init'])
         assert res == 0
         with open(TEMP_KINTO_INI) as f:
             content = f.read()
         assert 'redis' in content
コード例 #37
0
    def test_main_takes_sys_argv_by_default(self):
        testargs = [
            "prog",
            "init",
            "--ini",
            TEMP_KINTO_INI,
            "--backend",
            "memory",
            "--cache-backend",
            "memory",
        ]
        with mock.patch.object(sys, "argv", testargs):
            main()

        with open(TEMP_KINTO_INI) as f:
            content = f.read()
        assert "memory" in content
コード例 #38
0
 def test_cli_init_asks_until_cache_backend_is_valid(self):
     with mock.patch("kinto.__main__.input",
                     create=True,
                     side_effect=["2", "21", "2"]):
         res = main(["init", "--ini", TEMP_KINTO_INI])
         assert res == 0
         with open(TEMP_KINTO_INI) as f:
             content = f.read()
         assert "redis" in content
コード例 #39
0
 def test_cli_init_returns_if_file_exists(self):
     with open(TEMP_KINTO_INI, "w") as f:
         f.write("exists")
     with mock.patch("sys.stderr", new_callable=StringIO) as mock_stderr:
         res = main(
             ["init", "--ini", TEMP_KINTO_INI, "--backend", "memory"])
         assert res == 1
         content = mock_stderr.getvalue()
         assert "{} already exists.".format(TEMP_KINTO_INI) in content
コード例 #40
0
ファイル: test_main.py プロジェクト: pombredanne/kinto
 def test_cli_start_with_verbose_option_runs_pserve_with_verbose(self):
     with mock.patch("kinto.__main__.pserve.main") as mocked_pserve:
         res = main(
             [
                 "init",
                 "--ini",
                 TEMP_KINTO_INI,
                 "--backend",
                 "memory",
                 "--cache-backend",
                 "memory",
             ]
         )
         assert res == 0
         res = main(["start", "-v", "--ini", TEMP_KINTO_INI])
         assert res == 0
         assert mocked_pserve.call_count == 1
         assert mocked_pserve.call_args[1]["argv"][1] == "-v"
コード例 #41
0
ファイル: test_main.py プロジェクト: mohamedMaalej/kinto
 def test_cli_init_returns_if_file_exists(self):
     with open(TEMP_KINTO_INI, 'w') as f:
         f.write("exists")
     with mock.patch('sys.stderr', new_callable=StringIO) as mock_stderr:
         res = main(['--ini', TEMP_KINTO_INI,
                     '--backend', 'memory', 'init'])
         assert res == 1
         content = mock_stderr.getvalue()
         assert '{} already exists.'.format(TEMP_KINTO_INI) in content
コード例 #42
0
ファイル: test_main.py プロジェクト: pombredanne/kinto
 def test_cli_rebuild_quotas_run_rebuild_quotas_script(self):
     with mock.patch("kinto.__main__.scripts.rebuild_quotas") as reb_quo:
         reb_quo.return_value = mock.sentinel.reb_quo_code
         res = main(
             [
                 "init",
                 "--ini",
                 TEMP_KINTO_INI,
                 "--backend",
                 "memory",
                 "--cache-backend",
                 "memory",
             ]
         )
         assert res == 0
         res = main(["rebuild-quotas", "--ini", TEMP_KINTO_INI])
         assert res == mock.sentinel.reb_quo_code
         assert reb_quo.call_count == 1
コード例 #43
0
 def test_cli_create_user_runs_account_script(self):
     with mock.patch("kinto.__main__.accounts_scripts.create_user",
                     return_value=0) as mocked_create_user:
         res = main([
             "init",
             "--ini",
             TEMP_KINTO_INI,
             "--backend",
             "memory",
             "--cache-backend",
             "memory",
         ])
         assert res == 0
         res = main([
             "create-user", "--ini", TEMP_KINTO_INI, "-u", "username", "-p",
             "password"
         ])
         assert res == 0
         mocked_create_user.call_count == 1
コード例 #44
0
ファイル: test_main.py プロジェクト: pombredanne/kinto
 def test_cli_create_user_runs_account_script(self):
     with mock.patch("kinto.__main__.create_user", return_value=0) as mocked_create_user:
         res = main(
             [
                 "init",
                 "--ini",
                 TEMP_KINTO_INI,
                 "--backend",
                 "memory",
                 "--cache-backend",
                 "memory",
             ]
         )
         assert res == 0
         res = main(
             ["create-user", "--ini", TEMP_KINTO_INI, "-u", "username", "-p", "password"]
         )
         assert res == 0
         mocked_create_user.call_count == 1
コード例 #45
0
ファイル: test_main.py プロジェクト: makaisson/kinto
    def test_cli_init_installs_redis_dependencies_if_needed(self):
        realimport = builtins.__import__

        def redis_missing(name, *args, **kwargs):
            if name == 'kinto_redis':
                raise ImportError()
            else:
                return realimport(name, *args, **kwargs)

        with mock.patch('builtins.__import__', side_effect=redis_missing):
            with mock.patch('pip.main', return_value=None) as mocked_pip:
                with mock.patch("kinto.__main__.input", create=True, return_value="2"):
                    res = main(['init', '--ini', TEMP_KINTO_INI])
                    assert res == 0
                    assert mocked_pip.call_count == 1
コード例 #46
0
ファイル: test_main.py プロジェクト: yanbingms/kinto
 def test_cli_delete_collection_run_delete_collection_script(self):
     with mock.patch("kinto.__main__.scripts.delete_collection") as del_col:
         del_col.return_value = mock.sentinel.del_col_code
         res = main([
             "init",
             "--ini",
             TEMP_KINTO_INI,
             "--backend",
             "memory",
             "--cache-backend",
             "memory",
         ])
         assert res == 0
         res = main([
             "delete-collection",
             "--ini",
             TEMP_KINTO_INI,
             "--bucket",
             "test_bucket",
             "--collection",
             "test_collection",
         ])
         assert res == mock.sentinel.del_col_code
         assert del_col.call_count == 1
コード例 #47
0
    def test_cli_init_installs_postgresql_dependencies_if_needed(self):
        realimport = builtins.__import__

        def psycopg2_missing(name, *args, **kwargs):
            if name == 'psycopg2':
                raise ImportError()
            else:
                return realimport(name, *args, **kwargs)

        with mock.patch('builtins.__import__', side_effect=psycopg2_missing):
            with mock.patch('kinto.__main__.subprocess.check_call',
                            return_value=None) as mocked_pip:
                with mock.patch("kinto.__main__.input", create=True, return_value="1"):
                    res = main(['init', '--ini', TEMP_KINTO_INI])
                    assert res == 0
                    assert mocked_pip.call_count == 1
コード例 #48
0
ファイル: test_main.py プロジェクト: mohamedMaalej/kinto
    def test_cli_init_installs_postgresql_dependencies_if_needed(self):
        realimport = builtins.__import__

        def psycopg2_missing(name, *args, **kwargs):
            if name == 'psycopg2':
                raise ImportError()
            else:
                return realimport(name, *args, **kwargs)

        with mock.patch('{}.__import__'.format(builtins_name),
                        side_effect=psycopg2_missing):
            with mock.patch('pip.main', return_value=None) as mocked_pip:
                with mock.patch("kinto.__main__.input", create=True,
                                return_value="1"):
                    res = main(['--ini', TEMP_KINTO_INI, 'init'])
                    assert res == 0
                    assert mocked_pip.call_count == 1
コード例 #49
0
ファイル: test_main.py プロジェクト: pombredanne/kinto
    def test_cli_init_installs_redis_dependencies_if_needed(self):
        realimport = builtins.__import__

        def redis_missing(name, *args, **kwargs):
            if name == "kinto_redis":
                raise ImportError()
            else:
                return realimport(name, *args, **kwargs)

        with mock.patch("builtins.__import__", side_effect=redis_missing):
            with mock.patch(
                "kinto.__main__.subprocess.check_call", return_value=None
            ) as mocked_pip:
                with mock.patch("kinto.__main__.input", create=True, return_value="2"):
                    res = main(["init", "--ini", TEMP_KINTO_INI])
                    assert res == 0
                    assert mocked_pip.call_count == 1
コード例 #50
0
    def test_cli_init_installs_memcached_dependencies_if_needed(self):
        realimport = builtins.__import__

        def memcached_missing(name, *args, **kwargs):
            if name == "memcache":
                raise ImportError()
            else:
                return realimport(name, *args, **kwargs)

        with mock.patch("builtins.__import__", side_effect=memcached_missing):
            with mock.patch("kinto.__main__.subprocess.check_call",
                            return_value=None) as mocked_pip:
                with mock.patch("kinto.__main__.input",
                                create=True,
                                return_value="3"):
                    res = main([
                        "init", "--ini", TEMP_KINTO_INI, "--backend", "memory"
                    ])
                    assert res == 0
                    assert mocked_pip.call_count == 1
コード例 #51
0
ファイル: test_main.py プロジェクト: replyanshu/kinto
 def test_cli_can_configure_logger_in_quiet(self):
     with mock.patch('kinto.__main__.logging') as mocked_logging:
         main(
             ['init', '-q', '--ini', TEMP_KINTO_INI, '--backend', 'memory'])
         mocked_logging.basicConfig.assert_called_with(
             level=mocked_logging.CRITICAL, format=DEFAULT_LOG_FORMAT)
コード例 #52
0
ファイル: test_main.py プロジェクト: rlugojr/kinto
 def test_cli_can_display_kinto_version(self):
     with mock.patch('sys.stdout', new_callable=StringIO) as mock_stdout:
         res = main(['version'])
         assert mock_stdout.getvalue() == '%s\n' % kinto_version
         assert res == 0
コード例 #53
0
ファイル: test_main.py プロジェクト: mohamedMaalej/kinto
 def test_fails_if_not_enough_args(self):
     with mock.patch('sys.stderr', new_callable=StringIO) as mock_stderr:
         with pytest.raises(SystemExit) as excinfo:
             main(['--ini', TEMP_KINTO_INI])
         assert 'INI_FILE' in mock_stderr.getvalue()
         assert excinfo.value.code == 2
コード例 #54
0
ファイル: test_main.py プロジェクト: pombredanne/kinto
 def test_cli_init_generates_configuration(self):
     res = main(
         ["init", "--ini", TEMP_KINTO_INI, "--backend", "memory", "--cache-backend", "memory"]
     )
     assert res == 0
     assert os.path.exists(TEMP_KINTO_INI)
コード例 #55
0
ファイル: test_main.py プロジェクト: pombredanne/kinto
 def test_fails_if_not_enough_args(self):
     with mock.patch("sys.stderr", new_callable=StringIO) as mock_stderr:
         with pytest.raises(SystemExit) as excinfo:
             main([])
         assert "arguments are required: subcommand" in mock_stderr.getvalue()
         assert excinfo.value.code == 2
コード例 #56
0
ファイル: test_main.py プロジェクト: mohamedMaalej/kinto
 def test_cli_init_generates_configuration(self):
     res = main(['--ini', TEMP_KINTO_INI, '--backend', 'memory', 'init'])
     assert res == 0
     assert os.path.exists(TEMP_KINTO_INI)
コード例 #57
0
ファイル: test_main.py プロジェクト: pombredanne/kinto
 def test_cli_can_display_kinto_version(self):
     with mock.patch("sys.stdout", new_callable=StringIO) as mock_stdout:
         res = main(["version"])
         assert mock_stdout.getvalue() == "{}\n".format(kinto_version)
         assert res == 0
コード例 #58
0
ファイル: test_main.py プロジェクト: replyanshu/kinto
 def test_cli_can_display_kinto_version(self):
     with mock.patch('sys.stdout', new_callable=StringIO) as mock_stdout:
         res = main(['version'])
         assert mock_stdout.getvalue() == '{}\n'.format(kinto_version)
         assert res == 0
コード例 #59
0
ファイル: test_main.py プロジェクト: replyanshu/kinto
 def test_cli_use_default_logging_logger(self):
     with mock.patch('kinto.__main__.logging') as mocked_logging:
         main(['init', '--ini', TEMP_KINTO_INI, '--backend', 'memory'])
         mocked_logging.basicConfig.assert_called_with(
             level=logging.INFO, format=DEFAULT_LOG_FORMAT)