Skip to content

Testcases and outcomes

Lance-Ly edited this page Apr 17, 2023 · 17 revisions

Test case 1 - 5

class ProfileFormTests(TestCase): def test_valid_form(self): form = ProfileForm({ 'username': 'testuser', 'email': '[email protected]', 'password1': 'testpass', 'password2': 'testpass', 'account_type': 'B', 'location': 'New York' })

def test_missing_required_field(self):
    form = ProfileForm({
        'username': 'testuser',
        'email': '',
        'password1': 'testpass',
        'password2': 'testpass',
        'account_type': 'B',
        'location': 'New York'
    })
    self.assertFalse(form.is_valid())
    self.assertEqual(form.errors['email'], ['This field is required.'])

def test_invalid_email_format(self):
    form = ProfileForm({
        'username': 'testuser',
        'email': 'test',
        'password1': 'testpass',
        'password2': 'testpass',
        'account_type': 'B',
        'location': 'New York'
    })
    self.assertFalse(form.is_valid())
    self.assertEqual(form.errors['email'], ['Enter a valid email address.'])

def test_passwords_do_not_match(self):
    form = ProfileForm({
        'username': 'testuser',
        'email': '[email protected]',
        'password1': 'testpass',
        'password2': 'wrongpass',
        'account_type': 'B',
        'location': 'New York'
    })
    self.assertFalse(form.is_valid())
    self.assertEqual(form.errors['password2'], ['The two password fields didn’t match.'])

def test_invalid_account_type_choice(self):
    form = ProfileForm({
        'username': 'testuser',
        'email': '[email protected]',
        'password1': 'testpass',
        'password2': 'testpass',
        'account_type': 'X',
        'location': 'New York'
    })
    self.assertFalse(form.is_valid())
    self.assertEqual(form.errors['account_type'], ['Select a valid choice. X is not one of the available choices.'])

These test cases cover some common scenarios such as valid form submission, missing required fields, invalid email format, passwords that do not match, and an invalid choice for the account type field. You can customize them as needed to fit your specific requirements.

=========================================================================================================================================================

Clone this wiki locally