Skip to content

Commit

Permalink
Fix missing test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyli committed Apr 24, 2015
1 parent f0d45b1 commit 491bde5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion mimic/test/helpers.py
Expand Up @@ -6,6 +6,8 @@

import json

from six import string_types

from zope.interface import implementer

from twisted.test.proto_helpers import StringTransport, MemoryReactor
Expand Down Expand Up @@ -184,7 +186,7 @@ def json_request(testCase, rootResource, method, uri, body=b"",
Issue a request with a JSON body (if there's a body at all) and return
synchronously with a tuple of ``(response, JSON response body)``
"""
if body != "":
if not isinstance(body, string_types):
body = json.dumps(body)

d = request(testCase, rootResource, method, uri, body, baseURI, headers)
Expand Down
17 changes: 16 additions & 1 deletion mimic/test/test_nova.py
Expand Up @@ -941,7 +941,7 @@ def test_set_metadata_with_invalid_json_body_fails(self):
When setting metadata with an invalid request body (not a dict), it
should return an HTTP status code of 400:malformed request body
"""
self.assert_malformed_body(*self.set_metadata("meh"))
self.assert_malformed_body(*self.set_metadata('meh'))

def test_set_metadata_with_invalid_metadata_object(self):
"""
Expand Down Expand Up @@ -1049,6 +1049,21 @@ def test_set_metadata_item_with_wrong_key_fails(self):
*self.set_metadata_item({}, "meh",
{"metadata": {"meh": "value"}}))

def test_set_metadata_item_with_mismatching_key_and_body(self):
"""
When setting metadata item, the key in the 'meta' dictionary needs to
match the key in the URL, or a special 400 response is returned.
"""
response, body = self.set_metadata_item(
{}, "key", {"meta": {"notkey": "value"}})
self.assertEqual(response.code, 400)
self.assertEqual(body, {
"badRequest": {
"message": "Request body and URI mismatch",
"code": 400
}
})

def test_set_metadata_item_with_wrong_meta_type_fails(self):
"""
When setting metadata item without a 'meta' key mapped to not a
Expand Down

0 comments on commit 491bde5

Please sign in to comment.