Let the test client serialize request's body

The functional test's client serializes each request content before
sending it through the wire. The _post_large_bulk_insert used to do
string formatting on a already serialized list, which ended up in a
double serialization, hence the request exceeded the max size.

The patch changes the behavior mentioned above in favor of using plain
python objects and letting the client do the serialization step.

Change-Id: If67422ea48eddfd9d35f06c68bac6a3e417fe214
Closes-bug: #1383604
This commit is contained in:
Flavio Percoco 2014-11-13 14:38:15 +01:00
parent 50cdfc9b54
commit 5935b6cba4
2 changed files with 16 additions and 9 deletions

View File

@ -15,6 +15,7 @@
from __future__ import division
import json
import uuid
import ddt
@ -51,12 +52,15 @@ class TestMessages(base.V1FunctionalTestBase):
def _post_large_bulk_insert(self, offset):
"""Insert just under than max allowed messages."""
doc = '[{{"body": "{0}", "ttl": 300}}, {{"body": "{1}", "ttl": 120}}]'
overhead = len(doc.format('', ''))
message1 = {"body": '', "ttl": 300}
message2 = {"body": '', "ttl": 120}
doc = [message1, message2]
overhead = len(json.dumps(doc))
half_size = (self.limits.max_messages_post_size - overhead) // 2
doc = doc.format(helpers.generate_random_string(half_size),
helpers.generate_random_string(half_size + offset))
message1['body'] = helpers.generate_random_string(half_size)
message2['body'] = helpers.generate_random_string(half_size + offset)
return self.client.post(data=doc)

View File

@ -15,6 +15,7 @@
from __future__ import division
import json
import uuid
import ddt
@ -52,13 +53,15 @@ class TestMessages(base.V1_1FunctionalTestBase):
def _post_large_bulk_insert(self, offset):
"""Insert just under than max allowed messages."""
doc = ('{{"messages":[{{"body": "{0}", "ttl": 300}},'
'{{"body": "{1}", "ttl": 120}}]}}')
overhead = len(doc.format('', ''))
message1 = {"body": '', "ttl": 300}
message2 = {"body": '', "ttl": 120}
doc = {'messages': [message1, message2]}
overhead = len(json.dumps(doc))
half_size = (self.limits.max_messages_post_size - overhead) // 2
doc = doc.format(helpers.generate_random_string(half_size),
helpers.generate_random_string(half_size + offset))
message1['body'] = helpers.generate_random_string(half_size)
message2['body'] = helpers.generate_random_string(half_size + offset)
return self.client.post(data=doc)