This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

modified fakeserver to accept GET parameters

Signed-off-by: Flavio Curella <flavio.curella@gmail.com>
  • Loading branch information...
1 parent 2268462 commit 203dee3f46e16882f78bf200bdbc455efd1a9f58 @fcurella fcurella committed May 26, 2011
Showing with 17 additions and 9 deletions.
  1. +7 −4 tests/fakeserver.py
  2. +8 −2 tests/test_subtypes.py
  3. +2 −3 tests/utils.py
View
@@ -6,6 +6,7 @@
from __future__ import absolute_import
import httplib2
+from urlparse import parse_qsl
from storymarket import Storymarket
from storymarket.client import StorymarketClient
from nose.tools import assert_equal
@@ -45,7 +46,12 @@ def _storymarket_request(self, url, method, *args, **kwargs):
assert_equal(kwargs['headers']['Authorization'], self.apikey)
# Call the method
- munged_url = url.strip('/').replace('/', '_').replace('.', '_').replace('?','filter')
+ munged_url = url.strip('/').replace('/', '_').replace('.', '_').split('_?')[0]
+ print munged_url
+ qs = url.split('?')[-1]
+ url_args = dict(parse_qsl(qs))
+ kwargs.update(url_args)
+
callback = "%s_%s" % (method.lower(), munged_url)
if not hasattr(self, callback):
fail('Called unknown API method: %s %s' % (method, url))
@@ -77,9 +83,6 @@ def get_content_category_1(self, **kw):
def get_content_sub_type(self, **kw):
return (200, [self.get_content_sub_type_proto()[1]])
- def get_content_sub_type_filter(self, **kw):
- return (200, [self.get_content_sub_type_proto()[1]])
-
def get_content_sub_type_proto(self, type_model='text', id=1, **kw):
return (200, {
u"id": 1,
View
@@ -9,8 +9,14 @@
def test_list_subtypes():
assert_list_api(sm, sm.sub_types.all, Subtype, 'content/sub_type/')
-def test_filter_subtype():
- assert_list_api(sm, sm.sub_types.filter, Subtype, 'content/sub_type/?')
+def test_filter_subtype_default():
+ assert_list_api(sm, sm.sub_types.filter, Subtype, 'content/sub_type/?is_default=1', {'is_default':True})
+
+def test_filter_subtype_nondefault():
+ assert_list_api(sm, sm.sub_types.filter, Subtype, 'content/sub_type/?is_default=0', {'is_default':False})
+
+def test_filter_subtype_type():
+ assert_list_api(sm, sm.sub_types.filter, Subtype, 'content/sub_type/?type__model=text', {'type':'text'})
def test_get_subtype():
assert_get_api(sm, sm.sub_types.get, Subtype, 'content/sub_type/1/')
View
@@ -23,7 +23,7 @@ def assert_has_keys(dict, required=[], optional=[]):
def assert_isinstance(thing, kls):
ok_(isinstance(thing, kls), "%s is not an instance of %s" % (thing, kls))
-def assert_list_api(api, api_method, expected_class, expected_url):
+def assert_list_api(api, api_method, expected_class, expected_url, kw={}):
"""
Call an API list method, asserting that the returned class is correct
and that the called URL was correct.
@@ -33,7 +33,7 @@ def assert_list_api(api, api_method, expected_class, expected_url):
:param expected_class: Assert that returned instances are of this class.
:param expected_url: Assert that this URL was called with GET.
"""
- resource_list = api_method()
+ resource_list = api_method(**kw)
api.assert_called('GET', expected_url)
for resource in resource_list:
assert_isinstance(resource, expected_class)
@@ -121,4 +121,3 @@ def assert_update_api(api, api_method, instance, post_data, expected_url, resour
# PUT just a new instance
api_method(instance)
api.assert_called('PUT', expected_url)
-

0 comments on commit 203dee3

Please sign in to comment.