diff --git a/v1/fixtures/test/food.jpg b/v1/fixtures/test/food.jpg new file mode 100644 index 0000000..1cda9a5 Binary files /dev/null and b/v1/fixtures/test/food.jpg differ diff --git a/v1/recipe/tests/test_create_recipe.py b/v1/recipe/tests/test_create_recipe.py index 1ab0b6f..dd1c3d4 100644 --- a/v1/recipe/tests/test_create_recipe.py +++ b/v1/recipe/tests/test_create_recipe.py @@ -1,9 +1,11 @@ #!/usr/bin/env python # encoding: utf-8 +import os from django.test import TestCase from django.contrib.auth.models import User from django.core.files.uploadedfile import SimpleUploadedFile +from django.conf import settings from rest_framework.test import APIRequestFactory from v1.recipe import views @@ -143,14 +145,13 @@ def test_simple_create_recipe(self): request = self.factory.post('/api/v1/recipe/recipes/', data=data) request.user = self.staff - with open('/code/food.jpg', 'rb') as f: + root_path = os.path.join(settings.PROJECT_PATH, 'v1', 'fixtures', 'test', 'food.jpg') + with open(root_path, 'rb') as f: request.FILES['photo'] = SimpleUploadedFile( - '/code/food.jpg', + root_path, f.read(), content_type='multipart/form-data' ) response = view(request) - print(response.data) - self.assertTrue(response.data.get('id', True))