Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ...
- if (request.method == 'POST'):
- if request.FILES.has_key('file'):
- file = request.FILES['file']
- with open(settings.destfolder+'/%s' % file.name, 'wb+') as dest:
- for chunk in file.chunks():
- dest.write(chunk)
- c = Client()
- with open('wishlist.doc') as fp:
- c.post('/customers/wishes/', {'name': 'fred', 'attachment': fp})
- from django.core.files.uploadedfile import SimpleUploadedFile
- def test_upload_video(self):
- video = SimpleUploadedFile("file.mp4", "file_content", content_type="video/mp4")
- self.client.post(reverse('app:some_view'), {'video': video})
- # some important assertions ...
- def upload_file_to_location(request, location=None): # Can use the default configured
- import tempfile, csv, os
- class UploadPaperTest(TestCase):
- def generate_file(self):
- try:
- myfile = open('test.csv', 'wb')
- wr = csv.writer(myfile)
- wr.writerow(('Paper ID','Paper Title', 'Authors'))
- wr.writerow(('1','Title1', 'Author1'))
- wr.writerow(('2','Title2', 'Author2'))
- wr.writerow(('3','Title3', 'Author3'))
- finally:
- myfile.close()
- return myfile
- def setUp(self):
- self.user = create_fuser()
- self.profile = ProfileFactory(user=self.user)
- self.event = EventFactory()
- self.client = Client()
- self.module = ModuleFactory()
- self.event_module = EventModule.objects.get_or_create(event=self.event,
- module=self.module)[0]
- add_to_admin(self.event, self.user)
- def test_paper_upload(self):
- response = self.client.login(username=self.user.email, password='foz')
- self.assertTrue(response)
- myfile = self.generate_file()
- file_path = myfile.name
- f = open(file_path, "r")
- url = reverse('registration_upload_papers', args=[self.event.slug])
- # post wrong data type
- post_data = {'uploaded_file': i}
- response = self.client.post(url, post_data)
- self.assertContains(response, 'File type is not supported.')
- post_data['uploaded_file'] = f
- response = self.client.post(url, post_data)
- import_file = SubmissionImportFile.objects.all()[0]
- self.assertEqual(SubmissionImportFile.objects.all().count(), 1)
- #self.assertEqual(import_file.uploaded_file.name, 'files/registration/{0}'.format(file_path))
- os.remove(myfile.name)
- file_path = import_file.uploaded_file.path
- os.remove(file_path)
- TypeError: sequence item 4: expected bytes, bytearray, or an object with the buffer interface, str found
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement