0
我刚刚将所有AJAX验证代码移到了Django Forms中。我需要一些帮助来更新我的测试。我基本上有一些测试数据,声明为常量,用于所有套件。我在整个测试过程中都会重复这些数据。Django测试使用新ID创建表格
作为安装的一部分,我创建一些用户和登录我需要的用户:
def setUp(self):
self.client = Client()
create_user(username='staff', email='[email protected]',
password='staff', staff=True)
create_user(username='agent', email='[email protected]',
password='agent', staff=False)
ShiftType.objects.create(type_id='SI', description='Sales Inbox')
self.client.login(username='staff', password='staff')
推倒删除该数据(或者它使用的):
def tearDown(self):
# Clean up the DB
self.client.logout()
ShiftType.objects.all().delete()
User.objects.all().delete()
Event.objects.all().delete()
RecurrentEvent.objects.all().delete()
这是工作正常,但现在表单不会验证,因为用户给出的表单值id每次都会增加。例如:
ERROR: <ul class="errorlist"><li>employee_id<ul class="errorlist"><li>Select a valid choice. That choice is not one of the available choices.</li></ul></li></ul>
打印表格让我看到每次都增加了id。
即使我正在删除所有员工,为什么会发生这种情况?