def test_create_without_data(mommy, serializer):
    mommy.make.return_value = Mock(pk=1)
    view = TestDataModelRestView()
    view.data = None
    view.model = Mock()
    view.post(None)
    mommy.make.assert_called_once_with(view.model)
    view.model.objects.get.assert_called_once_with(pk=1)
    serializer.serialize.assert_called_once_with([view.model.objects.get()])
def test_create(mommy, get_data, serializer):
    get_data.side_effect = lambda data: data
    mommy.make.return_value = Mock(pk=1)
    view = TestDataModelRestView()
    view.data = {'test_data': 'test'}
    view.model = Mock()
    view.post(None)
    mommy.make.assert_called_once_with(view.model, test_data='test')
    view.model.objects.get.assert_called_once_with(pk=1)
    serializer.serialize.assert_called_once_with([view.model.objects.get()])
示例#3
0
# pylint: disable=no-value-for-parameter
from django.conf.urls import patterns, url

from rest_test_data.views import TestDataModelRestView, TestDataDetailRestView, TestDataSearchRestView

urlpatterns = patterns(
    "",
    url(r"^(?P<app>[^/]+)/(?P<model>[^/]+)/$", TestDataModelRestView.as_view(), name="objects"),
    url(r"^(?P<app>[^/]+)/(?P<model>[^/]+)/search/$", TestDataSearchRestView.as_view(), name="search"),
    url(r"^(?P<app>[^/]+)/(?P<model>[^/]+)/(?P<pk>\d+)/$", TestDataDetailRestView.as_view(), name="object"),
)
def test_delete_all_failure():
    view = TestDataModelRestView()
    view.model = Mock()
    view.model.objects.all().delete.side_effect = Exception
    assert_equal(view.delete(None), False)
    view.model.objects.all().delete.assert_called_once_with()
def test_delete_all():
    view = TestDataModelRestView()
    view.model = Mock()
    view.model.objects.all().count.return_value = 4
    assert_equal(view.delete(None), 4)
    view.model.objects.all().delete.assert_called_once_with()
def test_get_all(serializer):
    view = TestDataModelRestView()
    view.model = Mock()
    view.get(None)
    view.model.objects.all.assert_called_once_with()
    serializer.serialize.assert_called_once_with(view.model.objects.all())