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