Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

self.pos with attachments files #74

Open
Cubillosxy opened this issue Mar 27, 2018 · 0 comments
Open

self.pos with attachments files #74

Cubillosxy opened this issue Mar 27, 2018 · 0 comments

Comments

@Cubillosxy
Copy link

Cubillosxy commented Mar 27, 2018

Hello, I am trying to test my . view

 def view(request):   
     request.FILES ..

but i can`t make the correct request ,

# normal test

 response = self.client.post(
     reverse('admin_file'),
     {'name': 'fred', 'file[]': get_test_image()},
     enctype='multipart/form-data'
 )

#with test plus

response = self.post(
    'admin_file',
    {'name': 'fred', 'file[]': get_test_image()},
    enctype='multipart/form-data'
)
Traceback (most recent call last):
  File "/code/app/tests/tests_views.py", line 159, in test_upload_file
    enctype='multipart/form-data'
  File "/usr/local/lib/python3.6/site-packages/test_plus/test.py", line 142, in post
    return self.request('post', url_name, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/test_plus/test.py", line 131, in request
    self.last_response = method(reverse(url_name, args=args, kwargs=kwargs), data=data, follow=follow, **extra)
  File "/usr/local/lib/python3.6/site-packages/django/urls/base.py", line 88, in reverse
    return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
  File "/usr/local/lib/python3.6/site-packages/django/urls/resolvers.py", line 562, in _reverse_with_prefix
    raise ValueError("Don't mix *args and **kwargs in call to reverse()!")
ValueError: Don't mix *args and **kwargs in call to reverse()!

#with reverse the same answer

response = self.post(
    reverse('admin_file'),
    {'name': 'fred', 'file[]': get_test_image()},
    enctype='multipart/form-data'
)
ValueError: Don't mix *args and **kwargs in call to reverse()!

#without reverse and file in data

response = self.post(
   'admin_file',
    data={'name': 'fred', 'file[]': get_test_image()},
    enctype='multipart/form-data'
)
<HttpResponseNotFound status_code=404, "text/html; charset=utf-8">

# with reverse works

response = self.post(
    reverse('admin_file'),
    data={'name': 'fred', 'file[]': get_test_image()},
    enctype='multipart/form-data'
)

Then why does not work without reverse ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant