Opened 8 years ago
Last modified 8 years ago
#27184 closed Bug
django test client bug when use TemporaryFile in Mac — at Version 1
Reported by: | Joonsik,Jang | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | test TemporaryFile django client file upload |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
below code is file upload test method
This code was generated error message when I test only in Mac.
This code was ok when I test in Windows 10.
if I change TemporaryFile to NamedTemporaryFile, then It work correctly.
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'
Note:
See TracTickets
for help on using tickets.