Exemple #1
0
def get_config_ctx(template_file):
    ctx = click.get_current_context()

    samconfig_dir = getattr(ctx, "samconfig_dir", None)
    samconfig = SamConfig(
        config_dir=samconfig_dir if samconfig_dir else SamConfig.config_dir(template_file_path=template_file)
    )
    return ctx, samconfig
    def get_config_ctx(self, config_file=None):
        ctx = click.get_current_context()

        samconfig_dir = getattr(ctx, "samconfig_dir", None)
        samconfig = SamConfig(
            config_dir=samconfig_dir if samconfig_dir else SamConfig.config_dir(template_file_path=self.template_file),
            filename=config_file or DEFAULT_CONFIG_FILE_NAME,
        )
        return ctx, samconfig
    def test_get_ctx_defaults_non_nested(self):
        provider = MagicMock()

        mock_context1 = MockContext(info_name="sam", parent=None)
        mock_context2 = MockContext(info_name="local", parent=mock_context1)
        mock_context3 = MockContext(info_name="start-api", parent=mock_context2)

        get_ctx_defaults("start-api", provider, mock_context3, "default")

        provider.assert_called_with(SamConfig.config_dir(), "default", ["local", "start-api"])
    def test_get_ctx_defaults_nested(self):
        provider = MagicMock()

        mock_context1 = MockContext(info_name="sam", parent=None)
        mock_context2 = MockContext(info_name="local", parent=mock_context1)
        mock_context3 = MockContext(info_name="generate-event", parent=mock_context2)
        mock_context4 = MockContext(info_name="alexa-skills-kit", parent=mock_context3)

        get_ctx_defaults("intent-answer", provider, mock_context4, "default")

        provider.assert_called_with(
            SamConfig.config_dir(), "default", ["local", "generate-event", "alexa-skills-kit", "intent-answer"]
        )