GeekZoneHQ / web

Software to power the Geek.Zone website and apps
http://geek.zone/web
GNU General Public License v3.0
19 stars 29 forks source link

Tests not passing locally but are in CI #633

Open SamWinterhalder opened 1 year ago

SamWinterhalder commented 1 year ago

What did you expect?

Consistency when running tests locally and in CI

What actually happened?

When running python3 manage.py test locally in WSL, it runs all 33 tests but FAILED (failures=1, errors=6)

The same tests are all passing in CircleCI.

Impact

High

Urgency

Now

What browsers are you seeing the problem on?

No response

What operating system are you using?

No response

Relevant log output

(venv) sam@TheChosenPC:~/gz/web$ python3 manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
..................EEEEEEF........
======================================================================
ERROR: test_donation_is_required_to_be_a_number (memberships.tests.test_registration_form.RegisterFormTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sam/gz/web/memberships/tests/test_registration_form.py", line 44, in test_donation_is_required_to_be_a_number
    response = self.client.post(
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 751, in post
    response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 405, in post
    post_data = self._encode_data(data, content_type)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 364, in _encode_data
    return encode_multipart(BOUNDARY, data)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 247, in encode_multipart
    raise TypeError(
TypeError: Cannot encode None for key 'password' as POST data. Did you mean to pass an empty string or omit the value?

======================================================================
ERROR: test_existing_member_cannot_reregister (memberships.tests.test_registration_form.RegisterFormTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sam/gz/web/memberships/tests/test_registration_form.py", line 141, in test_existing_member_cannot_reregister
    response = self.client.post(
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 751, in post
    response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 405, in post
    post_data = self._encode_data(data, content_type)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 364, in _encode_data
    return encode_multipart(BOUNDARY, data)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 247, in encode_multipart
    raise TypeError(
TypeError: Cannot encode None for key 'password' as POST data. Did you mean to pass an empty string or omit the value?

======================================================================
ERROR: test_member_is_logged_in_after_registration (memberships.tests.test_registration_form.RegisterFormTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sam/gz/web/memberships/tests/test_registration_form.py", line 60, in test_member_is_logged_in_after_registration
    response = self.client.post(
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 751, in post
    response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 405, in post
    post_data = self._encode_data(data, content_type)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 364, in _encode_data
    return encode_multipart(BOUNDARY, data)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 247, in encode_multipart
    raise TypeError(
TypeError: Cannot encode None for key 'password' as POST data. Did you mean to pass an empty string or omit the value?

======================================================================
ERROR: test_member_is_redirected_to_confirm_page_with_donation_when_provided (memberships.tests.test_registration_form.RegisterFormTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sam/gz/web/memberships/tests/test_registration_form.py", line 78, in test_member_is_redirected_to_confirm_page_with_donation_when_provided
    response = self.client.post(
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 751, in post
    response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 405, in post
    post_data = self._encode_data(data, content_type)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 364, in _encode_data
    return encode_multipart(BOUNDARY, data)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 247, in encode_multipart
    raise TypeError(
TypeError: Cannot encode None for key 'password' as POST data. Did you mean to pass an empty string or omit the value?

======================================================================
ERROR: test_member_is_redirected_to_confirm_page_without_donation_when_not_provided (memberships.tests.test_registration_form.RegisterFormTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sam/gz/web/memberships/tests/test_registration_form.py", line 96, in test_member_is_redirected_to_confirm_page_without_donation_when_not_provided
    response = self.client.post(
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 751, in post
    response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 405, in post
    post_data = self._encode_data(data, content_type)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 364, in _encode_data
    return encode_multipart(BOUNDARY, data)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 247, in encode_multipart
    raise TypeError(
TypeError: Cannot encode None for key 'password' as POST data. Did you mean to pass an empty string or omit the value?

======================================================================
ERROR: test_registration_rejected_on_short_common_passwords (memberships.tests.test_registration_form.RegisterFormTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sam/gz/web/memberships/tests/test_registration_form.py", line 111, in test_registration_rejected_on_short_common_passwords
    response = self.client.post(
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 751, in post
    response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 405, in post
    post_data = self._encode_data(data, content_type)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 364, in _encode_data
    return encode_multipart(BOUNDARY, data)
  File "/home/sam/.local/lib/python3.8/site-packages/django/test/client.py", line 247, in encode_multipart
    raise TypeError(
TypeError: Cannot encode None for key 'password' as POST data. Did you mean to pass an empty string or omit the value?

======================================================================
FAIL: test_signed_in_users_cannot_register (memberships.tests.test_registration_form.RegisterFormTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sam/gz/web/memberships/tests/test_registration_form.py", line 30, in test_signed_in_users_cannot_register
    self.assertEqual(response.status_code, 302)
AssertionError: 200 != 302

----------------------------------------------------------------------
Ran 33 tests in 16.276s

FAILED (failures=1, errors=6)
Destroying test database for alias 'default'...

Code of Conduct

anettleship commented 1 year ago

Hello,

I think I have this: when running locally, our readme set up instructions don't direct the user to set up environment variables for the following values in web/.env:

TEST_USER_PASSWORD TEST_USER_PASSWORD_BAD

As a result, these are null when the tests run, which prevents the tests logging in the user, and throws errors when the values are unexpectedly null.

I'd propose adding to our readme to set these values in their .env file to a valid password, and a password on the django list of common passwords:

TEST_USER_PASSWORD=LegitLong@@Pword11 TEST_USER_PASSWORD_BAD=pass

Does anyone have any other suggestions on how to resolve before I move ahead?

Adrian

anettleship commented 1 year ago

I just started a new job, so I'm going to de-assign this for now. To be continued...