django-ajax-uploader - 由于AssertionError,单元测试失败

时间:2012-01-08 19:33:15

标签: python ajax django image upload

我正在使用以下应用: https://github.com/GoodCloud/django-ajax-uploader

现在,我写了一些测试来检查文件上传是否成功。一切正常,直到达到以下代码示例。

https://github.com/GoodCloud/django-ajax-uploader/blob/master/ajaxuploader/views.py#L53

success = backend.upload(upload, filename, is_raw)

通过运行我收到以下错误:

AssertionError: Cannot read more than the available bytes from the HTTP incoming data.

在调试中我发现,通过在那一点停止测试并调用...

request.POST

...测试工作正常,没有出现错误,文件已上传。什么......? 也许文件只在停止测试并等到加载后上传?

我的追溯:

AssertionError: Cannot read more than the available bytes from the HTTP incoming data.
Datei "/home/tobi/Projects/academic/src/webapps/django/project/manage.py", Zeile 14, in <module>
  execute_manager(settings)
Datei "/home/tobi/Envs/academic/lib/python2.7/site-packages/django/core/management/__init__.py", Zeile 438, in execute_manager
  utility.execute()
Datei "/home/tobi/Envs/academic/lib/python2.7/site-packages/django/core/management/__init__.py", Zeile 379, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
Datei "/home/tobi/Envs/academic/lib/python2.7/site-packages/django/core/management/base.py", Zeile 191, in run_from_argv
  self.execute(*args, **options.__dict__)
Datei "/home/tobi/Envs/academic/lib/python2.7/site-packages/django/core/management/base.py", Zeile 220, in execute
  output = self.handle(*args, **options)
Datei "/home/tobi/Envs/academic/lib/python2.7/site-packages/south/management/commands/test.py", Zeile 8, in handle
  super(Command, self).handle(*args, **kwargs)
Datei "/home/tobi/Envs/academic/lib/python2.7/site-packages/django/core/management/commands/test.py", Zeile 37, in handle
  failures = test_runner.run_tests(test_labels)
Datei "/home/tobi/Envs/academic/lib/python2.7/site-packages/django/test/simple.py", Zeile 360, in run_tests
  result = self.run_suite(suite)
Datei "/home/tobi/Envs/academic/lib/python2.7/site-packages/django/test/simple.py", Zeile 316, in run_suite
  return unittest.TextTestRunner(verbosity=self.verbosity, failfast=self.failfast).run(suite)
Datei "/usr/lib/python2.7/unittest/runner.py", Zeile 151, in run
  test(result)
Datei "/usr/lib/python2.7/unittest/suite.py", Zeile 70, in __call__
  return self.run(*args, **kwds)
Datei "/usr/lib/python2.7/unittest/suite.py", Zeile 108, in run
  test(result)
Datei "/home/tobi/Envs/academic/lib/python2.7/site-packages/django/test/testcases.py", Zeile 299, in __call__
  super(TransactionTestCase, self).__call__(result)
Datei "/usr/lib/python2.7/unittest/case.py", Zeile 391, in __call__
  return self.run(*args, **kwds)
Datei "/usr/lib/python2.7/unittest/case.py", Zeile 327, in run
  testMethod()
Datei "/home/tobi/Envs/academic/src/ajaxuploader/ajaxuploader/tests/default_storage_backend.py", Zeile 51, in test_upload_raw_post_local_backend
  HTTP_X_REQUESTED_WITH='XMLHttpRequest')
Datei "/home/tobi/Envs/academic/lib/python2.7/site-packages/django/test/client.py", Zeile 449, in post
  response = super(Client, self).post(path, data=data, content_type=content_type, **extra)
Datei "/home/tobi/Envs/academic/lib/python2.7/site-packages/django/test/client.py", Zeile 259, in post
  return self.request(**r)
Datei "/home/tobi/Envs/academic/lib/python2.7/site-packages/django/test/client.py", Zeile 381, in request
  response = self.handler(environ)
Datei "/home/tobi/Envs/academic/lib/python2.7/site-packages/django/test/client.py", Zeile 84, in __call__
  response = self.get_response(request)
Datei "/home/tobi/Envs/academic/lib/python2.7/site-packages/django/core/handlers/base.py", Zeile 111, in get_response
  response = callback(request, *callback_args, **callback_kwargs)
Datei "/home/tobi/Envs/academic/src/ajaxuploader/ajaxuploader/views.py", Zeile 15, in __call__
  return self._ajax_upload(request)
Datei "/home/tobi/Envs/academic/src/ajaxuploader/ajaxuploader/views.py", Zeile 53, in _ajax_upload
  success = backend.upload(upload, filename, is_raw)
Datei "/home/tobi/Envs/academic/src/ajaxuploader/ajaxuploader/backends/base.py", Zeile 27, in upload
  chunk = uploaded.read(self.BUFFER_SIZE)
Datei "/home/tobi/Envs/academic/lib/python2.7/site-packages/django/http/__init__.py", Zeile 301, in read
  return self._stream.read(*args, **kwargs)
Datei "/home/tobi/Envs/academic/lib/python2.7/site-packages/django/test/client.py", Zeile 51, in read
  assert self.__len >= num_bytes, "Cannot read more than the available bytes from the HTTP incoming data."

0 个答案:

没有答案