Skip to content

Instantly share code, notes, and snippets.

@santiagobasulto
Created September 4, 2013 14:02
Show Gist options
  • Save santiagobasulto/6437356 to your computer and use it in GitHub Desktop.
Save santiagobasulto/6437356 to your computer and use it in GitHub Desktop.
# views.py
from myproject.myfunctions import upload_profile_picture
def profile_picture(request):
# setup (checking for post, checking if the
# user is authenticated, etc.)
user = request.user
pic_file = request.FILES['profile_picture']
result_url = upload_profile_picture(pic_file)
user.profile.picture_url = result_url
user.profile.save()
# Tests...
import mock
from myproject import views
from django.test.client import RequestFactory
class TestProfileView(TestCase):
@mock.patch("myproject.views.upload_profile_picture")
def test_function_is_called(self, mock_obj):
mock_obj.return_value = "test_url"
factory = RequestFactory()
request = factory.post('/customer/details')
request.FILES = {'profile_picture': 'mocked_file'}
views.profile_picture(request)
mock_obj.assert_called_with('mocked_file')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment