'Basic test that duplicate name causes error on first submission, not on second (with warned=True)'

def test_form_duplicate_name_student_teacher(self):

    self.data['is_teacher'] = False
    user_form = FacilityUserForm(facility=self.facility, data=self.data)
    self.assertTrue(user_form.is_valid(), ('Form    must    be    valid;    instead:    errors    (%s)' % user_form.errors))
    user_form.instance.set_password(user_form.cleaned_data['password_first'])
    user_form.save()
    self.data['is_teacher'] = True
    self.data['username'] += '-different'
    user_form = FacilityUserForm(facility=self.facility, data=self.data)
    self.assertFalse(user_form.is_valid(), 'Form    must    NOT    be    valid.')
    self.assertIn('1    user(s)', user_form.errors['__all__'][0], 'Error    message    must    contain    #    of    users')
    self.data['warned'] = True
    user_form = FacilityUserForm(facility=self.facility, data=self.data)
    self.assertTrue(user_form.is_valid(), ('Form    must    be    valid;    instead:    errors    (%s)' % user_form.errors))
    user_form.instance.set_password(user_form.cleaned_data['password_first'])
    user_form.save()
