def test_get_volunteer_resume_file_url(self): u1 = User.objects.create_user('John') v1 = Volunteer( first_name="John", last_name="Doe", address="7 Alpine Street", city="Maplegrove", state="Wyoming", country="USA", phone_number="23454545", email="*****@*****.**", resume_file="MyResume.pdf", user=u1 ) v1.save() # test typical cases self.assertIsNotNone(get_volunteer_resume_file_url(v1.id)) self.assertEqual( get_volunteer_resume_file_url(v1.id), v1.resume_file.url ) # test non-existant cases self.assertNotEqual(get_volunteer_resume_file_url(v1.id), "resumes/DifferentResume.pdf" ) self.assertNotEqual(get_volunteer_resume_file_url(v1.id), "resumes/AnotherResume.pdf" )
def test_get_volunteer_resume_file_url(self): self.v1.resume_file = "MyResume.pdf" self.v1.save() # test typical cases self.assertIsNotNone(get_volunteer_resume_file_url(self.v1.id)) self.assertEqual(get_volunteer_resume_file_url(self.v1.id), self.v1.resume_file.url) # test non-existant cases self.assertNotEqual(get_volunteer_resume_file_url(self.v1.id), "resumes/DifferentResume.pdf") self.assertNotEqual(get_volunteer_resume_file_url(self.v1.id), "resumes/AnotherResume.pdf")
def test_get_volunteer_resume_file_url(self): self.v1.resume_file = "MyResume.pdf" self.v1.save() # test typical cases self.assertIsNotNone(get_volunteer_resume_file_url(self.v1.id)) self.assertEqual( get_volunteer_resume_file_url(self.v1.id), self.v1.resume_file.url) # test non-existant cases self.assertNotEqual( get_volunteer_resume_file_url(self.v1.id), "resumes/DifferentResume.pdf") self.assertNotEqual( get_volunteer_resume_file_url(self.v1.id), "resumes/AnotherResume.pdf")
def download_resume(request, volunteer_id): user = request.user if int(user.volunteer.id) == int(volunteer_id): if request.method == 'POST': basename = get_volunteer_resume_file_url(volunteer_id) if basename: filename = settings.MEDIA_ROOT + '/..' + basename wrapper = FileWrapper(open(filename, 'rb')) response = HttpResponse(wrapper) response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(filename) response['Content-Length'] = os.path.getsize(filename) return response else: raise Http404 else: return HttpResponse(status=403)
def download_resume(request, volunteer_id): user = request.user if int(user.volunteer.id) == int(volunteer_id): if request.method == 'POST': basename = get_volunteer_resume_file_url(volunteer_id) if basename: filename = settings.MEDIA_ROOT + basename wrapper = FileWrapper(file(filename)) response = HttpResponse(wrapper) response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(filename) response['Content-Length'] = os.path.getsize(filename) return response else: raise Http404 else: return HttpResponse(status=403)