我已经定制了save_model
管理员。
class MyModelAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
# some more question code here
obj.save()
现在,我想测试MyModelAdmin save_model
函数。我尝试发帖如下:
class MyModelAdminSaveTestCase(TestCase):
def setUp(self):
# setup code here
def test_save_model(self):
'''Test add employee
'''
my_obj = {
'name': 'Tester',
'address': '12 test Test',
'city': 'New York',
'state': 'NY',
}
self.client.login(username=self.user, password=self.pwd)
response = self.client.post(reverse('admin:mymodel_mymodel_add'), my_obj, follow=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(MyModel.objects.count(), 1)
然而,测试失败:
self.assertEqual(MyModel.objects.count(), 1)
AssertionError: 0 != 1