My assertion error fails:
AssertionError: 'Rev0_2020-06-09_L123_My_Document_63ExUTF.docx' != 'Rev0_2020-06-09_L123_My_Document.docx'- Rev0_2020-06-09_L123_My_Document_63ExUTF.docx? --------+ Rev0_2020-06-09_L123_My_Document.docx
class DocumentTestCase(TestCase):
def create_document(self, **kwargs):
if 'file' not in kwargs:
kwargs['file'] = self.get_test_file()
return Document.objects.create(**kwargs)
def _create_file(self):
f = tempfile.NamedTemporaryFile(suffix=self.TEST_FILE_EXTENSION, delete=False)
with open(f.name, mode='wb'):
f.write(b"NA")
return open(f.name, mode='rb')
TEST_FILE_EXTENSION = ".docx"
def setUp(self):
super().setUp()
settings.MEDIA_ROOT = MEDIA_ROOT
def get_test_file(self):
file = self._create_file()
return File(file, name=file.name)
def test_rename_file_after_upload(self):
d1 = self.create_document(title="My Document", number="L123")
title = d1.title.replace(" ", "_")
extension = Path(d1.file.path).suffix
new_name = f"Rev{d1.revision}_{d1.revision_date}_{d1.number}_{title}{extension}"
self.assertEqual(Path(d1.file.name).name, new_name)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cbc812fc-6d5e-4afb-ab64-6bc0fad303a3o%40googlegroups.com.
Thank you so much for that! It was due to duplicate file names.
I had a tearDownClass method that was deleting my temp files after the test was completed. It should have been a tearDown method that occurred at the end of every test.
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/7bwtdfURlSk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMKMUjsSKYU3FyD4SL%3DxumDc3spfM74KmnFhpRBbFniNe5ex2w%40mail.gmail.com.