def test_get_type_configuration_with_not_exist_file():
    with patch("builtins.open", mock_open()) as f:
        f.side_effect = FileNotFoundError()
        try:
            TypeConfiguration.get_type_configuration()
        except FileNotFoundError:
            pass
def test_get_type_configuration():
    type_configuration = TypeConfiguration.get_type_configuration()
    assert type_configuration["Credentials"]["ApiKey"] == "123"
    assert type_configuration["Credentials"]["ApplicationKey"] == "123"

    # get type config again, should be the same config
    type_configuration = TypeConfiguration.get_type_configuration()
    assert type_configuration["Credentials"]["ApiKey"] == "123"
    assert type_configuration["Credentials"]["ApplicationKey"] == "123"
예제 #3
0
    def call(
        self,
        invocation_point,
        target,
        target_model,
        **kwargs,
    ):
        request = self._make_payload(
            invocation_point,
            target,
            target_model,
            TypeConfiguration.get_hook_configuration(),
            **kwargs,
        )
        start_time = time.time()
        response = self._call(request)
        self.assert_time(start_time, time.time(), invocation_point)

        # this throws a KeyError if status isn't present, or if it isn't a valid status
        status = HookStatus[response["hookStatus"]]

        while status == HookStatus.IN_PROGRESS:
            callback_delay_seconds = self.assert_in_progress(
                status, response, target)
            time.sleep(callback_delay_seconds)

            request["requestContext"]["callbackContext"] = response.get(
                "callbackContext")

            response = self._call(request)
            status = HookStatus[response["hookStatus"]]

        return status, response
    def call(self, action, current_model, previous_model=None, **kwargs):
        request = self._make_payload(
            action,
            current_model,
            previous_model,
            TypeConfiguration.get_type_configuration(),
            **kwargs,
        )
        start_time = time.time()
        response = self._call(request)
        self.assert_time(start_time, time.time(), action)

        # this throws a KeyError if status isn't present, or if it isn't a valid status
        status = OperationStatus[response["status"]]

        if action in (Action.READ, Action.LIST):
            assert status != OperationStatus.IN_PROGRESS
            return status, response

        while status == OperationStatus.IN_PROGRESS:
            callback_delay_seconds = self.assert_in_progress(status, response)
            self.assert_primary_identifier(self.primary_identifier_paths,
                                           response.get("resourceModel"))
            sleep(callback_delay_seconds)

            request["requestData"]["resourceProperties"] = response.get(
                "resourceModel")
            request["callbackContext"] = response.get("callbackContext")
            # refresh credential for every handler invocation
            request["requestData"][
                "callerCredentials"] = get_temporary_credentials(
                    self._session, LOWER_CAMEL_CRED_KEYS, self._role_arn)

            response = self._call(request)
            status = OperationStatus[response["status"]]

        # ensure writeOnlyProperties are not returned on final responses
        if "resourceModel" in response.keys(
        ) and status == OperationStatus.SUCCESS:
            self.assert_write_only_property_does_not_exist(
                response["resourceModel"])

        return status, response
def test_get_type_configuration_with_invalid_json():
    try:
        TypeConfiguration.get_type_configuration()
    except InvalidProjectError:
        pass
예제 #6
0
def test_get_hook_configuration_with_invalid_json():
    with pytest.raises(InvalidProjectError) as execinfo:
        TypeConfiguration.get_hook_configuration()

    assert "Hook configuration is invalid" in str(execinfo.value)