diff --git a/backend/tests/test_special_value_file_format.py b/backend/tests/test_special_value_file_format.py new file mode 100644 index 0000000..749202b --- /dev/null +++ b/backend/tests/test_special_value_file_format.py @@ -0,0 +1,27 @@ +""" +TC_004 - Special value test for uploading a valid and invalid file to a workout. +""" +def test_file_upload_special_value(self): + # Creates a PDF-file + pdf_file = SimpleUploadedFile("pdf_file.pdf") + # Creates a DOCX-file + docx_file = SimpleUploadedFile("docx_file.docx") + # Creates AthleteFile object with the files + athlete_pdf_file = AthleteFile(athlete=self.user, owner=self.user, file=pdf_file) + athlete_docx_file = AthleteFile(athlete=self.user, owner=self.user, file=docx_file) + + try: + # Runs validation check for PDF-file + athlete_pdf_file.full_clean() + except ValidationError as e: + # Fails if any validation errors are raised + self.fail(f"ValidationError raised: {e}") + + try: + # Runs validation check for DOCX-file + athlete_pdf_file.full_clean() + # Fails if no validation errors are raised + self.fail("ValidationError not raised for file of format DOCX.") + except ValidationError as e: + # Passes if validation error is raised. + self.assertIn('file', e.message_dict)