Exemple #1
0
    def test_user_cannot_submit_unchanged_form(self):
        """Ensures that a user cannot submit an unchanged form"""

        # Create form
        form = forms.GameEditForm(self.inputs, initial=self.game.get_change_model())

        # Form should not be valid since no changes were made
        self.assertFalse(form.is_valid())
        self.assertIn('You have not changed anything', str(form.errors))
Exemple #2
0
    def test_user_cannot_submit_invalid_changed_form(self):
        """Ensures that a user cannot submit invalid changes"""

        # Prepare the change to be suggested (which is invalid here)
        self.inputs['name'] = ''

        # Create form
        form = forms.GameEditForm(self.inputs, initial=self.game.get_change_model())

        # Assert that form is invalid since the name must not be empty
        self.assertFalse(form.is_valid())
        self.assertIn('This field is required', str(form.errors['name']))
Exemple #3
0
    def test_user_can_submit_valid_changed_form(self):
        """Ensures that a user can submit valid changes"""

        # Prepare the change to be suggested
        self.inputs['name'] = 'Corrected Game Title'

        # Needed for the foreign key of the change row
        change_for = self.game.get_change_model()

        # Create form
        form = forms.GameEditForm(self.inputs, initial=change_for)

        # Assert that form is valid since the change is valid
        self.assertTrue(form.is_valid())

        # Persist changes
        change_suggestion = form.save(commit=False)
        change_suggestion.change_for = self.game
        change_suggestion.save()
        form.save_m2m()

        # Assert that the changes are in the model
        self.assertEqual(change_suggestion.name, 'Corrected Game Title')

        # Finally, verify the diff (did only the name change?)
        diff = change_suggestion.get_changes()

        # Count should be 1 since only one change was made
        self.assertEqual(len(diff), 1)

        # Untie
        (diff_name, diff_old, diff_new) = diff[0]

        # Verify diff
        self.assertEqual(diff_name, 'name')
        self.assertEqual(diff_old, 'Horribly Misspelled Game Title')
        self.assertEqual(diff_new, 'Corrected Game Title')