Skip to content

Commit

Permalink
Remove flakiness from dict keys by introducing OrderedDict
Browse files Browse the repository at this point in the history
  • Loading branch information
prat0318 committed Aug 22, 2014
1 parent 7e301a8 commit 7a435c2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"Operating System :: OS Independent",
"Programming Language :: Python",
],
tests_require=["nose", "tissue", "coverage", "httpretty"],
tests_require=["nose", "tissue", "coverage", "ordereddict", "httpretty"],
install_requires=(["requests", "python-dateutil"] + websocket_packages +
async_packages),
async_packages),
)
9 changes: 6 additions & 3 deletions swaggerpy_test/async_http_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
2) Timeouts by crochet's wait()
"""

import json
import unittest
from collections import namedtuple
from mock import patch, Mock
from ordereddict import OrderedDict

import swaggerpy.async_http_client
import swaggerpy.exception
Expand All @@ -26,7 +28,8 @@ def test_stringify_body_converts_dict_to_str(self):
'headers': {'content-type': 'application/json'},
'data': {'foo': 'bar', 'bar': 42}}
swaggerpy.http_client.stringify_body(request_params)
self.assertEqual('{"foo": "bar", "bar": 42}', request_params['data'])
self.assertEqual({"foo": "bar", "bar": 42},
json.loads(request_params['data']))

def test_stringify_body_ignores_data_if_header_content_type_not_json(self):
request_params = {'headers': {}, 'data': 'foo'}
Expand Down Expand Up @@ -83,7 +86,7 @@ def test_stringify_files_creates_correct_body_content(self):
mock_fbp.assert_called_once_with('foo')

def test_stringify_files_creates_correct_form_content(self):
request = {'data': {'id': 42, 'name': 'test'},
request = {'data': OrderedDict([('id', 42), ('name', 'test')]),
'headers': {'content-type': swaggerpy.http_client.APP_FORM}}
with patch('swaggerpy.async_http_client.StringIO',
return_value='foo') as mock_stringIO:
Expand All @@ -99,7 +102,7 @@ def test_listify_headers(self):
headers = {'a': 'foo', 'b': ['bar', 42]}
resp = swaggerpy.async_http_client.listify_headers(headers)
self.assertEqual([('A', ['foo']), ('B', ['bar', 42])],
list(resp.getAllRawHeaders()))
sorted(list(resp.getAllRawHeaders())))

def test_success_AsyncHTTP_response(self):
Response = namedtuple("MyResponse",
Expand Down
7 changes: 4 additions & 3 deletions swaggerpy_test/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""Swagger client tests.
"""

import json
import unittest

import httpretty
Expand Down Expand Up @@ -102,9 +103,9 @@ def test_get_client_allows_json_dict(self):
self.assertTrue(isinstance(client_stub, client.SwaggerClient))

def test_serialization_of_json_dict(self):
client.get_client({'apis': [], 'swaggerVersion': '1.2'})
serialized_key = '{"swaggerVersion": "1.2", "apis": []}'
self.assertTrue(serialized_key in client.factory.cache)
client.get_client({'swaggerVersion': '1.2', 'apis': []})
self.assertTrue({'swaggerVersion': '1.2', 'apis': []} in
map(json.loads, client.factory.cache.keys()))

@httpretty.activate
def test_bad_operation(self):
Expand Down
7 changes: 4 additions & 3 deletions swaggerpy_test/resource_operation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

import json
import unittest
import urlparse
from datetime import datetime

import httpretty
Expand Down Expand Up @@ -186,11 +187,11 @@ def test_success_on_post_with_form_params(self):
httpretty.register_uri(
httpretty.POST, "http://localhost/test_http?", body='')
resource = SwaggerClient(u'http://localhost/api-docs').api_test
resource.testHTTP(param_id=42, param_name="str").result()
resource.testHTTP(param_id=42, param_name='str').result()
self.assertEqual('application/x-www-form-urlencoded',
httpretty.last_request().headers['content-type'])
self.assertEqual('param_name=str&param_id=42',
httpretty.last_request().body)
self.assertEqual({'param_name': ['str'], 'param_id': ['42']},
urlparse.parse_qs(httpretty.last_request().body))

@httpretty.activate
def test_success_on_post_with_form_params_with_files(self):
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ deps =
nose
httpretty
mock
ordereddict
commands =
nosetests

Expand Down

0 comments on commit 7a435c2

Please sign in to comment.