<commit_before># Copyright (c) 2013-2014 Rackspace, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import mock

from barbican import queue
from barbican.queue import server
from barbican.tests import utils


class WhenUsingBeginOrderTask(utils.BaseTestCase):
    """Test using the Tasks class for 'order' task."""

    def setUp(self):
        super(WhenUsingBeginOrderTask, self).setUp()

        self.tasks = server.Tasks()

    @mock.patch('barbican.tasks.resources.BeginOrder')
    def test_should_process_order(self, mock_begin_order):
        mock_begin_order.return_value.process.return_value = None
        self.tasks.process_order(context=None,
                                 order_id=self.order_id,
                                 keystone_id=self.keystone_id)
        mock_begin_order.return_value.process.assert_called_with(
            self.order_id, self.keystone_id)

    @mock.patch('barbican.tasks.resources.UpdateOrder')
    def test_should_update_order(self, mock_update_order):
        mock_update_order.return_value.process.return_value = None
        updated_meta = {}
        self.tasks.update_order(context=None,
                                order_id=self.order_id,
                                keystone_id=self.keystone_id,
                                updated_meta=updated_meta)
        mock_update_order.return_value.process.assert_called_with(
            self.order_id, self.keystone_id, updated_meta
        )


class WhenUsingTaskServer(utils.BaseTestCase):
    """Test using the asynchronous task client."""

    def setUp(self):<commit_msg>Adding missing unit test on queue server tasks<commit_after># Copyright (c) 2013-2014 Rackspace, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import mock

from barbican import queue
from barbican.queue import server
from barbican.tests import utils


class WhenUsingBeginOrderTask(utils.BaseTestCase):
    """Test using the Tasks class for 'order' task."""

    def setUp(self):
        super(WhenUsingBeginOrderTask, self).setUp()

        self.tasks = server.Tasks()

    @mock.patch('barbican.tasks.resources.BeginOrder')
    def test_should_process_order(self, mock_begin_order):
        mock_begin_order.return_value.process.return_value = None
        self.tasks.process_order(context=None,
                                 order_id=self.order_id,
                                 keystone_id=self.keystone_id)
        mock_begin_order.return_value.process.assert_called_with(
            self.order_id, self.keystone_id)

    @mock.patch('barbican.tasks.resources.UpdateOrder')
    def test_should_update_order(self, mock_update_order):
        mock_update_order.return_value.process.return_value = None
        updated_meta = {}
        self.tasks.update_order(context=None,
                                order_id=self.order_id,
                                keystone_id=self.keystone_id,
                                updated_meta=updated_meta)
        mock_update_order.return_value.process.assert_called_with(
            self.order_id, self.keystone_id, updated_meta
        )

    @mock.patch('barbican.tasks.resources.BeginOrder')
    def test_process_order_catch_exception(self, mock_begin_order):
        """Test process_order() handles all exceptions."""
        mock_begin_order.return_value.process.side_effect = Exception()
        self.tasks.process_order(None, self.order_id, self.keystone_id)


class WhenUsingBeginTypeOrderTask(utils.BaseTestCase):
    """Test using the Tasks class for 'type order' task."""

    def setUp(self):
        super(WhenUsingBeginTypeOrderTask, self).setUp()

        self.tasks = server.Tasks()

    @mock.patch('barbican.tasks.resources.BeginTypeOrder')
    def test_process_type_order_catch_exception(self, mock_begin_type_order):
        """Test process_type_order() method handles all exceptions."""
        mock_begin_type_order.return_value.process.side_effect = Exception()
        self.tasks.process_type_order(None, self.order_id, self.keystone_id)


class WhenUsingTaskServer(utils.BaseTestCase):
    """Test using the asynchronous task client."""

    def setUp(self):
{'fraction_non_alphanumeric': 0.08430685358255452, 'fraction_numerical': 0.004672897196261682, 'mean_word_length': 3.1096, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6521500', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1412, 'n_words': 354}