GatorIncubator / gatorgrouper

:busts_in_silhouette: Automated Group Formation Tool Enabling Effective Team Work
GNU General Public License v3.0
20 stars 20 forks source link

Fix skipped valid form test in `test_form.py` #280

Closed Michionlion closed 5 years ago

Michionlion commented 5 years ago

Fix skipped test

There is currently a skipped test on master that must be fixed. Below is some correspondence that occurred on PR #279 about this issue. It is related to test_forms.py.

Comment by @Michionlion on #279:

@sutterj, it seems that the problem below may be created from the fact that there was no initial password field in the given form, although I'm not positive.

The valid form seems to be <CustomUserChangeForm bound=True, valid=True, fields=(email;first_name;last_name;password)>

self = <tests.test_forms.TestCustomUserChangeForm object at 0x7f526e212160>
    def test_valid_data(self):
        """undocumented"""
        form = CustomUserChangeForm(
            {
                "email": "testuserl@test.com",
                "first_name": "Spencer",
                "last_name": "Huang",
                "password1": "testpassword1",
                "password2": "testpassword1",
            }
        )
>       assert form.is_valid() is True
tests/test_forms.py:48: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.venv/lib/python3.7/site-packages/django/forms/forms.py:185: in is_valid
    return self.is_bound and not self.errors
.venv/lib/python3.7/site-packages/django/forms/forms.py:180: in errors
    self.full_clean()
.venv/lib/python3.7/site-packages/django/forms/forms.py:381: in full_clean
    self._clean_fields()
.venv/lib/python3.7/site-packages/django/forms/forms.py:402: in _clean_fields
    value = getattr(self, 'clean_%s' % name)()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <CustomUserChangeForm bound=True, valid=True, fields=(email;first_name;last_name;password)>
    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
>       return self.initial["password"]
E       KeyError: 'password'
.venv/lib/python3.7/site-packages/django/contrib/auth/forms.py:152: KeyError

Comment by @sutterj on #279:

That is what it seemed like to me as well. There is just email, first, and last in the form.py file and not password, but I wasn't sure if the part where it called the user model somehow deals with the password.

Comment by @Michionlion on #279:

I think that error is perhaps best solved by one of the people who originally developed that test case. I think @enpuyou would know who that was. In the mean time, I think that if that test is skipped and the rest of the tests pass, we should be good to merge to master. I'll make a quick annotation so that they can work on fixing it.

Comment by @enpuyou on #279:

@sutterj, it seems that the problem below may be created from the fact that there was no initial password field in the given form, although I'm not positive. the valid form seems to be

@Michionlion, I think you are right about that. This test case was first created attempting to test when this form is used in the views.py where registering account requires two password to be put in. I will work on fixing this now and it should be a easy fix.

Assigned Developers

@enpuyou