-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jolan
committed
Mar 26, 2025
1 parent
97c6e61
commit fe407a6
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import os | ||
| from users.models import User | ||
| from django.core.files.uploadedfile import SimpleUploadedFile | ||
| from django.test import TestCase | ||
| from myapp.models import WorkoutFile # Replace with the actual model import | ||
| from django.urls import reverse | ||
|
|
||
|
|
||
| class TestWorkoutFileUpload(TestCase): | ||
| def setUp(self): | ||
| self.url = reverse('workout-file-list') # Use 'workout-file-list' from urls.py | ||
| self.user = User.objects.create_user( | ||
| username='testuser', password='password' | ||
| ) | ||
| self.client.login(username='testuser', password='password') | ||
|
|
||
| def test_upload_multiple_valid_pdf_files(self): | ||
| # Create mock PDF files under 2MB | ||
| files = {} | ||
| for i in range(8): # 8 files | ||
| # Creating a mock PDF file of size < 2MB (e.g., 1MB each) | ||
| file_content = b'%PDF-1.4 example PDF content' * 1024 # Creating a simple PDF-like content | ||
| files[f'file{i}'] = SimpleUploadedFile( | ||
| f'file{i}.pdf', file_content, content_type='application/pdf' | ||
| ) | ||
|
|
||
| # Make the POST request with files | ||
| response = self.client.post(self.url, files, format='multipart') | ||
|
|
||
| # Check if the response is successful | ||
| self.assertEqual(response.status_code, 201) # 201 means created | ||
|
|
||
| # Optionally, check that the files have been created in the database | ||
| workout_files = WorkoutFile.objects.all() | ||
| self.assertEqual(workout_files.count(), 8) |