def test_delete(): request = req('get') request.user = Struct(is_staff=True) assert Foo.objects.count() == 0 f = Foo.objects.create(foo=7) c = Admin.delete(request=request, app_name='tests', model_name='foo', pk=f.pk) p = c.bind(request=req('post', **{'-submit': ''})) assert p.parts.delete_tests_foo.is_valid() p.render_to_response() assert Foo.objects.count() == 0
def test_delete(mock_messages, settings): settings.ROOT_URLCONF = __name__ request = staff_req('get') assert Foo.objects.count() == 0 f = Foo.objects.create(foo=7) c = Admin.delete(request=request, app_name='tests', model_name='foo', pk=f.pk) p = c.bind(request=req('post', **{'-submit': ''})) assert p.parts.delete_tests_foo.is_valid() p.render_to_response() assert Foo.objects.count() == 0 mock_messages.add_message.assert_called_with( request, mock_messages.INFO, f'Foo {f} was deleted', fail_silently=True )