<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.
from marconi.tests.system.common import config
from marconi.tests.system.common import functionlib
from marconi.tests.system.common import http
from marconi.tests.system.messages import msgfnlib

import testtools


class TestMessages(testtools.TestCase):
    """Tests for Messages."""

    def setUp(self):
        super(TestMessages, self).setUp()
        self.cfg = config.Config()
        self.header = functionlib.create_marconi_headers()

    def test_000_message_setup(self):
        """Create Queue for Message Tests."""
        url = self.cfg.base_url + '/queues/messagetestqueue'
        doc = '{"queuemetadata": "message test queue"}'
        result = http.put(url, self.header, doc)

        self.assertEqual(result.status_code, 201)

    test_000_message_setup.tags = ['smoke', 'positive']

    def test_001_message_single_insert(self):
        """Insert Single Message into the Queue."""
        doc = msgfnlib.get_message_body(messagecount=1)
        url = self.cfg.base_url + '/queues/messagetestqueue/messages'

        result = http.post(url, self.header, doc)
        self.assertEqual(result.status_code, 201)

        #GET on posted message
        href = result.json()['resources'][0]
        url = self.cfg.base_server + href

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 200)

        #Compare message metadata
        result_body = result.json()['body']
        posted_metadata = doc[0]['body']
        self.assertEqual(result_body, posted_metadata)

    test_001_message_single_insert.tags = ['smoke', 'positive']

    def test_002_message_bulk_insert(self):
        """Bulk Insert Messages into the Queue."""
        message_count = 30
        doc = msgfnlib.get_message_body(messagecount=message_count)
        url = self.cfg.base_url + '/queues/messagetestqueue/messages'
        result = http.post(url, self.header, doc)

        self.assertEqual(result.status_code, 201)

        #GET on posted messages<commit_msg>Adds test for include_claimed flag<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.
from marconi.tests.system.common import config
from marconi.tests.system.common import functionlib
from marconi.tests.system.common import http
from marconi.tests.system.messages import msgfnlib

import testtools


class TestMessages(testtools.TestCase):
    """Tests for Messages."""

    def setUp(self):
        super(TestMessages, self).setUp()
        self.cfg = config.Config()
        self.header = functionlib.create_marconi_headers()

    def test_000_message_setup(self):
        """Create Queue for Message Tests."""
        url = self.cfg.base_url + '/queues/messagetestqueue'
        doc = '{"queuemetadata": "message test queue"}'
        result = http.put(url, self.header, doc)

        self.assertEqual(result.status_code, 201)

    test_000_message_setup.tags = ['smoke', 'positive']

    def test_001_message_single_insert(self):
        """Insert Single Message into the Queue.

        This test also verifies that claimed messages are
        retuned (or not) depending on the include_claimed flag.
        """
        doc = msgfnlib.get_message_body(messagecount=1)
        url = self.cfg.base_url + '/queues/messagetestqueue/messages'

        result = http.post(url, self.header, doc)
        self.assertEqual(result.status_code, 201)

        #GET on posted message
        href = result.json()['resources'][0]
        url = self.cfg.base_server + href

        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 200)

        #Compare message metadata
        result_body = result.json()['body']
        posted_metadata = doc[0]['body']
        self.assertEqual(result_body, posted_metadata)

        #Post a claim & verify the include_claimed flag.
        url = self.cfg.base_url + '/queues/messagetestqueue/claims'
        doc = '{"ttl": 300, "grace": 100}'
        result = http.post(url, self.header, doc)
        self.assertEqual(result.status_code, 200)

        url = self.cfg.base_url + '/queues/messagetestqueue/messages' \
                                  '?include_claimed=true'
        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 200)

        response_message_body = result.json()["messages"][0]["body"]
        self.assertEqual(response_message_body, posted_metadata)

        #By default, include_claimed = false
        url = self.cfg.base_url + '/queues/messagetestqueue/messages'
        result = http.get(url, self.header)
        self.assertEqual(result.status_code, 204)

    test_001_message_single_insert.tags = ['smoke', 'positive']

    def test_002_message_bulk_insert(self):
        """Bulk Insert Messages into the Queue."""
        message_count = 30
        doc = msgfnlib.get_message_body(messagecount=message_count)
        url = self.cfg.base_url + '/queues/messagetestqueue/messages'
        result = http.post(url, self.header, doc)

        self.assertEqual(result.status_code, 201)

        #GET on posted messages
{'fraction_non_alphanumeric': 0.10298410638987998, 'fraction_numerical': 0.015569250729808628, 'mean_word_length': 3.1584625758597435, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7383122', 'n_tokens_mistral': 1877, 'n_tokens_neox': 1757, 'n_words': 483}