I have created test case for generating the image path and added the function in the models for generating the image path
I got the following error AssertionError: 'uploads\recipe\test-uuid.jpg' != 'uploads/recipe/test-uuid.jpg'
- uploads\recipe\test-uuid.jpg ? ^ ^
- uploads/recipe/test-uuid.jpg ? ^ ^
@patch('core.models.uuid.uuid4')
def test_recipe_file_name_uuid(self,mock_uuid):
'''test generating image path'''
uuid="test-uuid"
mock_uuid.return_value=uuid
file_path=models.recipe_image_file_path(None,"example.jpg")
self.assertEqual(file_path,f'uploads/recipe/{uuid}.jpg')
and the recipe_image_file_path in the models file is as follows
def recipe_image_file_path(instance,filename):
'''generating a file path for the new recipe image'''
ext=os.path.splitext(filename)[1]
filename=f'{uuid.uuid4()}{ext}'
return os.path.join('uploads','recipe',filename)
When I run test case I want to match the assertEqual(file_path,f'uploads/recipe/{uuid}.jpg')