Skip to content

Commit

Permalink
feat: first unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolan committed Mar 26, 2025
1 parent 97c6e61 commit fe407a6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions backend/tests/test_workout_file_upload.py
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)

0 comments on commit fe407a6

Please sign in to comment.