{{{
def test_ChunkedSampleFile(self):
"""
ChunkedSampleFileList, ChunkedSampleFileDetail View Test
"""
with TemporaryFile() as test_file:
for count in range(100000):
test_file.write(('test_data %s' % count).encode())
test_file.seek(0)
hash_md5 = hashlib.md5()
for chunk in iter(lambda: test_file.read(4096), b""):
hash_md5.update(chunk)
etag = hash_md5.hexdigest()
test_file.seek(0)
#post
response = self.client.post('%s/chunked_sample_files' %
URL_PREFIX,
data={'file': test_file, 'name': 'test.vcf',
'sample_file_meta':
self.sample_file_meta_id,
'file_seq': 1, 'etag': etag},
**{AUTH_TOKEN_HEADER_NAME: 'Token %s' %
self.testuserfastqc1_token} )
self.assertEqual(response.status_code,
status.HTTP_201_CREATED, response.content)
file_id = response.json()['id']
}}}
Error Message
ERROR: test_ChunkedSampleFile (analysis_files.tests.AnalysisFilesTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File
"/Users/joonsik/git/ngenebio_webapi/ngenebio_webapi/analysis_files/tests.py",
line 174, in test_ChunkedSampleFile
**{AUTH_TOKEN_HEADER_NAME: 'Token %s' % self.testuserfastqc1_token} )
File "/Users/joonsik/venv_ngenebio_webapi/lib/python3.4/site-
packages/django/test/client.py", line 515, in post
secure=secure, **extra)
File "/Users/joonsik/venv_ngenebio_webapi/lib/python3.4/site-
packages/django/test/client.py", line 311, in post
post_data = self._encode_data(data, content_type)
File "/Users/joonsik/venv_ngenebio_webapi/lib/python3.4/site-
packages/django/test/client.py", line 275, in _encode_data
return encode_multipart(BOUNDARY, data)
File "/Users/joonsik/venv_ngenebio_webapi/lib/python3.4/site-
packages/django/test/client.py", line 171, in encode_multipart
lines.extend(encode_file(boundary, key, value))
File "/Users/joonsik/venv_ngenebio_webapi/lib/python3.4/site-
packages/django/test/client.py", line 200, in encode_file
filename = os.path.basename(file.name) if hasattr(file, 'name') else
''
File "/Users/joonsik/venv_ngenebio_webapi/lib/python3.4/posixpath.py",
line 139, in basename
i = p.rfind(sep) + 1
AttributeError: 'int' object has no attribute 'rfind'
--
Ticket URL: <https://code.djangoproject.com/ticket/27184>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
New description:
--
--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:1>
* stage: Unreviewed => Accepted
Comment:
I'm not sure if this should/can work, but if not, it would be nice to have
a friendlier message rather than a crash.
--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:2>
* version: 1.9 => master
* easy: 0 => 1
Comment:
This should be relatively easy to fix by testing the type of file.name.
--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:3>
* owner: nobody => thomas-scrace
* status: new => assigned
Comment:
Fixed with https://github.com/django/django/pull/7230
This is my first django contribution. I've tried to follow the guidelines,
but please let me know if anything is wrong!
Thanks,
Tom
--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:4>
* needs_better_patch: 0 => 1
Comment:
Thanks! Comments added in the PR. Uncheck `patch needs improvement` after
you update the patch.
--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:5>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:6>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
Comment:
Improved patch is available at https://github.com/django/django/pull/7230
and should be ready to be merged.
Federico
--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"5549e89b847beb89e8c8b85b6fd6924028d991c3" 5549e89b]:
{{{
#!CommitTicketReference repository=""
revision="5549e89b847beb89e8c8b85b6fd6924028d991c3"
Fixed #27184 -- Allowed uploading TemporaryFile with the test client.
Thanks Federico Capoano for finishing the patch.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:8>
Comment (by Tim Graham <timograham@…>):
In [changeset:"8db6a6c0a1c73bf08e71e00d4ab8c4af3c5f0cb8" 8db6a6c]:
{{{
#!CommitTicketReference repository=""
revision="8db6a6c0a1c73bf08e71e00d4ab8c4af3c5f0cb8"
Refs #27184 -- Fixed unclosed file ResourceWarning in test_client test.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:9>