Ejemplo n.º 1
0
    def test_unlock_persistent_graph_not_locked(self):
        """Error raised when object is not locked."""
        code = "0000"
        context = Context(config=self.persist_graph_config)
        context._s3_bucket_verified = True
        context._persistent_graph = Graph.from_dict({"stack1": []}, context)
        stubber = Stubber(context.s3_conn)

        stubber.add_response("get_object_tagging", {"TagSet": []},
                             context.persistent_graph_location)

        with stubber:
            with self.assertRaises(PersistentGraphCannotUnlock):
                context.unlock_persistent_graph(code)
            stubber.assert_no_pending_responses()
Ejemplo n.º 2
0
    def test_unlock_persistent_graph_code_missmatch(self):
        """Error raised when local code does not match object."""
        code = '0000'
        context = Context(config=self.persist_graph_config)
        context._s3_bucket_verified = True
        context._persistent_graph = Graph.from_dict({'stack1': []}, context)
        stubber = Stubber(context.s3_conn)

        stubber.add_response('get_object_tagging', {
            'TagSet':
            gen_tagset({context._persistent_graph_lock_tag: '1111'})
        }, context.persistent_graph_location)

        with stubber:
            with self.assertRaises(PersistentGraphCannotUnlock):
                context.unlock_persistent_graph(code)
            stubber.assert_no_pending_responses()
Ejemplo n.º 3
0
    def test_unlock_persistent_graph(self):
        """Return 'True' when delete tag is successful."""
        code = '0000'
        context = Context(config=self.persist_graph_config)
        context._s3_bucket_verified = True
        context._persistent_graph = Graph.from_dict({'stack1': []}, context)
        stubber = Stubber(context.s3_conn)

        stubber.add_response(
            'get_object_tagging',
            {'TagSet': gen_tagset({context._persistent_graph_lock_tag: code})},
            context.persistent_graph_location)
        stubber.add_response('delete_object_tagging', {},
                             context.persistent_graph_location)

        with stubber:
            self.assertTrue(context.unlock_persistent_graph(code))
            stubber.assert_no_pending_responses()
Ejemplo n.º 4
0
    def test_unlock_persistent_graph_no_object(self):
        """Return 'None' when object does not exist.

        This can occur if the object is deleted by 'put_persistent_graph'.

        """
        code = "0000"
        context = Context(config=self.persist_graph_config)
        context._s3_bucket_verified = True
        context._persistent_graph = Graph()
        stubber = Stubber(context.s3_conn)
        expected_params = context.persistent_graph_location.copy()
        expected_params.update({"ResponseContentType": "application/json"})

        stubber.add_client_error("get_object",
                                 "NoSuchKey",
                                 expected_params=expected_params)

        with stubber:
            assert context.unlock_persistent_graph(code)
            stubber.assert_no_pending_responses()