Skip to content

test: add unit tests for file_upload view#451

Open
andrianbalanesq wants to merge 1 commit into
DjangoCRM:mainfrom
andrianbalanesq:test/file-upload-view
Open

test: add unit tests for file_upload view#451
andrianbalanesq wants to merge 1 commit into
DjangoCRM:mainfrom
andrianbalanesq:test/file-upload-view

Conversation

@andrianbalanesq

Copy link
Copy Markdown

Description

Add comprehensive unit tests for the file_upload view in massmail/views/file_upload.py, as requested in #410.

Tests Added

All tests are in tests/massmail/views/test_file_upload.py and follow the existing test patterns in the project (inheriting from BaseTestCase, using @tag('TestCase'), loading project fixtures):

  1. test_anonymous_user_redirected — Verifies that anonymous users are redirected to the admin login page (302).

  2. test_non_staff_user_redirected — Verifies that authenticated non-staff users are redirected to the admin login page (302).

  3. test_staff_user_get_upload_form — Verifies that staff users receive the upload form with the correct multipart enctype and file input field on a GET request (200).

  4. test_successful_image_upload — Verifies that a POST with a valid PNG file saves the file to MEDIA_ROOT/pics/ and returns the window-close script.

  5. test_invalid_file_extension — Verifies that a POST with a disallowed file extension (.txt) is rejected with an error message.

Test Results

Found 5 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
Ran 5 tests in 0.355s

OK
Destroying test database for alias 'default'...

Closes #410

Add comprehensive tests for the massmail file_upload view:
- Anonymous user redirected to admin login
- Non-staff user redirected to admin login
- Staff user can access the upload form (GET)
- Valid image upload saves file and returns close script (POST)
- Invalid file extension is rejected with error message

Closes DjangoCRM#410
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create unit tests for the file_upload view

1 participant