<commit_before># Copyright (c) 2013 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 json

import ddt
import falcon
import six

from . import base  # noqa
from marconi import tests as testing


@ddt.ddt
class QueueLifecycleBaseTest(base.TestBase):

    config_file = None

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

    def test_empty_project_id(self):
        path = '/v1/queues/gumshoe'

        self.simulate_get(path, '')
        self.assertEqual(self.srmock.status, falcon.HTTP_400)

        self.simulate_put(path, '')
        self.assertEqual(self.srmock.status, falcon.HTTP_400)

        self.simulate_head(path, '')
        self.assertEqual(self.srmock.status, falcon.HTTP_400)

        self.simulate_delete(path, '')
        self.assertEqual(self.srmock.status, falcon.HTTP_400)

    @ddt.data('480924', 'foo', None)
    def test_basics_thoroughly(self, project_id):
        path = '/v1/queues/gumshoe'

        # Stats not found - queue not created yet
        self.simulate_get(path + '/stats', project_id)
        self.assertEqual(self.srmock.status, falcon.HTTP_404)

        # Metadata not found - queue not created yet
        self.simulate_get(path + '/metadata', project_id)
        self.assertEqual(self.srmock.status, falcon.HTTP_404)

        # Create
        self.simulate_put(path, project_id)
        self.assertEqual(self.srmock.status, falcon.HTTP_201)

        location = ('Location', '/v1/queues/gumshoe')
        self.assertIn(location, self.srmock.headers)

        # Ensure queue existence
        self.simulate_head(path, project_id)
        self.assertEqual(self.srmock.status, falcon.HTTP_204)

        # Add metadata
        doc = '{"messages": {"ttl": 600}}'
        self.simulate_put(path + '/metadata', project_id, body=doc)
        self.assertEqual(self.srmock.status, falcon.HTTP_204)

        # Fetch metadata<commit_msg>test: Use srmock header_dict in preparation for Falcon 0.1.8<commit_after># Copyright (c) 2013 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 json

import ddt
import falcon
import six

from . import base  # noqa
from marconi import tests as testing


@ddt.ddt
class QueueLifecycleBaseTest(base.TestBase):

    config_file = None

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

    def test_empty_project_id(self):
        path = '/v1/queues/gumshoe'

        self.simulate_get(path, '')
        self.assertEqual(self.srmock.status, falcon.HTTP_400)

        self.simulate_put(path, '')
        self.assertEqual(self.srmock.status, falcon.HTTP_400)

        self.simulate_head(path, '')
        self.assertEqual(self.srmock.status, falcon.HTTP_400)

        self.simulate_delete(path, '')
        self.assertEqual(self.srmock.status, falcon.HTTP_400)

    @ddt.data('480924', 'foo', None)
    def test_basics_thoroughly(self, project_id):
        path = '/v1/queues/gumshoe'

        # Stats not found - queue not created yet
        self.simulate_get(path + '/stats', project_id)
        self.assertEqual(self.srmock.status, falcon.HTTP_404)

        # Metadata not found - queue not created yet
        self.simulate_get(path + '/metadata', project_id)
        self.assertEqual(self.srmock.status, falcon.HTTP_404)

        # Create
        self.simulate_put(path, project_id)
        self.assertEqual(self.srmock.status, falcon.HTTP_201)

        location = self.srmock.headers_dict['Location']
        self.assertEqual(location, '/v1/queues/gumshoe')

        # Ensure queue existence
        self.simulate_head(path, project_id)
        self.assertEqual(self.srmock.status, falcon.HTTP_204)

        # Add metadata
        doc = '{"messages": {"ttl": 600}}'
        self.simulate_put(path + '/metadata', project_id, body=doc)
        self.assertEqual(self.srmock.status, falcon.HTTP_204)

        # Fetch metadata
{'fraction_non_alphanumeric': 0.10354000409249028, 'fraction_numerical': 0.019848577859627584, 'mean_word_length': 3.1144781144781146, 'pattern_counts': {'":': 4, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4737204', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1499, 'n_words': 386}