Last active
February 13, 2024 08:27
-
-
Save maddrum/ce60447f404a103d0c44b213ecc6fd71 to your computer and use it in GitHub Desktop.
Django manually assign file to model
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
def test_picture_path_is_correct(self): | |
obj = self.create_obj() | |
abs_path = os.path.join(settings.TEST_MEDIA_ASSETS_FOLDER, 'profile_picture_1280.png') | |
obj.picture.save('filename.png', ImageFile(open(abs_path, 'rb'))) # this line reads image and store it as binary | |
obj.save() | |
self.assertTrue(os.path.isfile(obj.picture.path)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment