def test_image_file_deleted_with_object(self): """Ensure that a project's image is deleted from the disk when its associated Project object is deleted. """ project = Project( name='Test Project', authors=['Author 1', 'Author 2'], description='Project description.', image=self.image, status=Project.ProjectStatus.PLANNED ) project.save() path = f'{project.image.path}' project.delete() import os if os.path.isfile(path): self.fail('Project image file was not deleted along with the model instance.')
def test_logo_path_properly_assigned(self): """Ensure that the URL and name of a project's image are properly assigned when creating a Project object. """ project = Project( name='Test Project', authors=['Author 1', 'Author 2'], description='Project description.', image=self.image, status=Project.ProjectStatus.PLANNED ) project.save() try: self.assertEqual(f'{settings.MEDIA_URL}{BASE_IMAGE_PATH}test_project/main_image.png', project.image.url) except AssertionError as e: project.delete() self.fail(e) project.delete()