Exemplo n.º 1
0
    def test_main_with_explicit_refresh(self):
        cache = SSMParameter("my_param")  # will not expire

        class InvalidCredentials(Exception):
            pass

        def do_something():
            my_value = cache.value()
            if my_value == self.PARAM_VALUE:
                raise InvalidCredentials()

        try:
            do_something()
        except InvalidCredentials:
            # manually update value
            self._create_params(["my_param"], "new_value")
            cache.refresh()  # force refresh
            do_something()  # won't fail anymore
Exemplo n.º 2
0
    def test_main_with_explicit_refresh(self):
        """ Test explicit refresh case """
        param = SSMParameter("my_param")  # will not expire

        class InvalidCredentials(Exception):
            """ Mock exception class """

        def do_something():
            """ Raise an exception until the value has changed """
            my_value = param.value
            if my_value == self.PARAM_VALUE:
                raise InvalidCredentials()

        try:
            do_something()
        except InvalidCredentials:
            # manually update value
            self._create_params(["my_param"], "new_value")
            param.refresh()  # force refresh
            do_something()  # won't fail anymore
    def test_select_versions(self):
        """ Test version selection """

        method_name = sys._getframe().f_code.co_name
        self._setUp(method_name)

        name = method_name
        self._create_or_update_param(name)

        param = SSMParameter("%s:1" % name)

        self.assertEqual(param.value, self.PARAM_VALUE)
        self.assertEqual(param.version, 1)

        # this will update the value and create version 2
        self._create_or_update_param(name, self.PARAM_VALUE_V2)

        param.refresh()

        self.assertEqual(param.value, self.PARAM_VALUE)
        self.assertEqual(param.version, 1)

        self._delete_param(name)
    def test_update_versions(self):
        """ Test version update """

        method_name = sys._getframe().f_code.co_name
        self._setUp(method_name)

        name = method_name
        self._create_or_update_param(name)

        param = SSMParameter(name)

        self.assertEqual(param.version, 1)
        self.assertEqual(param.value, self.PARAM_VALUE)

        # this will update the value and create version 2
        self._create_or_update_param(name, self.PARAM_VALUE_V2)

        param.refresh()

        # refreshing should give you version 2
        self.assertEqual(param.version, 2)
        self.assertEqual(param.value, self.PARAM_VALUE_V2)

        self._delete_param(name)