Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rca committed Jul 19, 2013
1 parent 6e0da89 commit b31559f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions resourceful/tests.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from django.core.exceptions import ObjectDoesNotExist
from flexmock import flexmock

from django.core.handlers.wsgi import WSGIRequest
from django.test import TestCase

from resourceful.views import ResourceView


class RoutingTestCase(TestCase):
def test_index(self):
request = WSGIRequest({
Expand All @@ -23,8 +25,9 @@ def test_index_json_with_xmlhttprequest(self):
'wsgi.input': '',
'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest',
})
request.user = flexmock()

model = flexmock(objects=flexmock(all=lambda: []))
model = flexmock(objects=flexmock(all=lambda: [], filter_for_user=flexmock()))

flexmock(ResourceView).should_receive("render_json").once()

Expand All @@ -38,7 +41,11 @@ def test_index_json_with_format(self):
'QUERY_STRING': '_format=json',
})

model = flexmock(objects=flexmock(all=lambda: []))
request.user = flexmock()

model = flexmock(
objects=flexmock(all=lambda: [], filter_for_user=flexmock())
)

flexmock(ResourceView).should_receive("render_json").once()

Expand All @@ -54,8 +61,8 @@ def test_view_with_different_model(self):
'QUERY_STRING': '_format=json',
})

view1 = ResourceView.as_view(model_class=flexmock(objects=flexmock(get=lambda *args, **kwargs: 'view1')))
view2 = ResourceView.as_view(model_class=flexmock(objects=flexmock(get=lambda *args, **kwargs: 'view2')))
view1 = ResourceView.as_view(model_class=flexmock(objects=flexmock(get=lambda *args, **kwargs: 'view1'), DoesNotExist=ObjectDoesNotExist))
view2 = ResourceView.as_view(model_class=flexmock(objects=flexmock(get=lambda *args, **kwargs: 'view2'), DoesNotExist=ObjectDoesNotExist))

response1 = view1(request, resource='foo', id='1', action='')
response2 = view2(request, resource='foo', id='1', action='')
Expand Down

0 comments on commit b31559f

Please sign in to comment.