def test_upload_returns_json_with_expected_args(self): req = self.factory.post( '', dict(auth_token=settings.UPLOAD_AUTH_TOKEN, screenshot=open(SAMPLE_IMG, 'rb'))) def fake_upload_to_flickr(some_request, static_page_url): self.assertTrue(static_page_url is None) self.assertTrue(some_request is req) return '5688591650' response = views.upload(req, upload_to_flickr=fake_upload_to_flickr) self.assertEqual(response['content-type'], 'application/json') obj = json.loads(response.content) self.assertEqual(obj['photo_id'], '5688591650') self.assertEqual(obj['short_url'], 'http://flic.kr/p/9EFw7o')
def test_upload_returns_json_with_expected_args(self): req = self.factory.post('', dict( auth_token=settings.UPLOAD_AUTH_TOKEN, screenshot=open(SAMPLE_IMG, 'rb') )) def fake_upload_to_flickr(some_request, static_page_url): self.assertTrue(static_page_url is None) self.assertTrue(some_request is req) return '5688591650' response = views.upload(req, upload_to_flickr=fake_upload_to_flickr) self.assertEqual(response['content-type'], 'application/json') obj = json.loads(response.content) self.assertEqual(obj['photo_id'], '5688591650') self.assertEqual(obj['short_url'], 'http://flic.kr/p/9EFw7o')
def uploadPython(request,text): if request.is_ajax() and request.method == 'POST': upload(text)
def test_upload_without_screenshot_returns_400(self): req = self.factory.post('', dict(auth_token=settings.UPLOAD_AUTH_TOKEN, )) response = views.upload(req) self.assertEqual(response.status_code, 400)
def test_upload_returns_forbidden_with_bad_auth_token(self): req = self.factory.post('', dict(auth_token='no u')) response = views.upload(req) self.assertEqual(response.status_code, 403)
def test_upload_without_screenshot_returns_400(self): req = self.factory.post('', dict( auth_token=settings.UPLOAD_AUTH_TOKEN, )) response = views.upload(req) self.assertEqual(response.status_code, 400)
def projectForOther(request,projectid,form): form['offer_finished']=False project=Project.objects.get(id=projectid) employer=User.objects.get(id=project.employer_id) offerlist=Offering.objects.filter(project=project) #account=userprofile.account casesforemployer=[] app = get_app('project') for model in get_models(app): if model._meta.db_table=="project_rankforemployer": for name in model._meta.get_all_field_names(): if name !="id" and name!="project" and name!="totalRank" and name!="employee" and name!="count": casesforemployer.append(name) if request.method == 'POST': if not request.user.is_authenticated(): return render_to_response('alert.html', {'error':"لطفا ابتدا وارد شوید",'address':'/login/'}) userprofile=UserProfile.objects.get(id=request.user.id) if not userprofile.is_designer : return render_to_response('alert.html', {'error':"برای ثبت پیشنهاد باید به عنوان طراح ثبت نام کرده و وارد سایت شوید!"}) if 'upload' in request.POST: return views.upload(request,project.id) if request.POST.get('accept'): return acceptOfferByEmployee(project) if request.POST.get('cancel'): return cancelOfferByEmployee(project) if request.POST.get('message'): dis = Discussion(project=project,userprofile=userprofile,message=request.POST.get('message'),date=datetime.datetime.now().replace(tzinfo=utc)) dis.save() #contactFilter(dis.message,"Discussion",dis.id) #mail(userId=project.employer.id,kind="discussion",text='http://www.zirend.ir/project/'+str(project.id)) string='/project/'+str(project.id)+'/discussiontab/' return HttpResponseRedirect(string) else: if not userprofile.is_designer : return render_to_response('alert.html', {'error':"برای ثبت پیشنهاد باید به عنوان طراح ثبت نام کرده و وارد سایت شوید!"}) if project.is_running or project.is_failed or project.is_finished or project.is_canceled or project.is_wait_for_employee or request.user.id==project.employer.id: return render_to_response('alert.html', {'error':"زمان ثبت پیشنهاد به اتمام رسیده است",'address':'-1'}) else: seconds=datetime.timedelta(hours=project.hourTimeForOffer)+project.offerTime-datetime.datetime.now().replace(tzinfo=utc) seconds=seconds.total_seconds() if seconds < 0: return render_to_response('alert.html', {'error':"زمان ثبت پیشنهاد به اتمام رسیده است",'address':'-1'}) for offer in Offering.objects.filter(project=project): if offer.offerer == userprofile: return render_to_response('alert.html', {'error':"شما قبلا برای این پروژه پیشنهاد ثبت کرده اید",'address':'-1'}) else: continue try: int(request.POST.get('value')) int(request.POST.get('totallValue')) int(request.POST.get('offerDay')) except: return render_to_response('alert.html', {'error':"اطلاعات وارد شده صحیح نمیباشد",'address':'-1'}) try: bayane=int(request.POST.get('bayane')) except: bayane=0 value=request.POST.get('value') totallValue=request.POST.get('totallValue') offerDay=request.POST.get('offerDay') image_url=request.POST.get('image') #image_name=os.path.basename(image_url) #extension = os.path.splitext(image_url)[1] #copyfile(image_url, '/static/offeringfiles') #image=str(project.id) + str(offer.id) + extension #os.rename('/static/offeringfiles/' + image_name, image) if int(offerDay)<0 or int(bayane)<0 : return render_to_response('alert.html', {'error':"اطلاعات وارد شده صحیح نمیباشد",'address':'-1'}) else: pass text=request.POST.get('text') try: int(value) int(totallValue) except: address = '/project/'+str(project.id) return render_to_response('alert.html', {'error':"اطلاعات وارد شده صحیح نمیباشد",'address':address}) if int(value)<0 or int(totallValue)<0: address = '/project/'+str(project.id) return render_to_response('alert.html', {'error':"اطلاعات وارد شده صحیح نمیباشد",'address':address}) else: offer=Offering(bayane=bayane,offerer=userprofile,project=project,text=text,offerTime=datetime.datetime.now().replace(tzinfo=utc),offerDay=offerDay,value=value,totallValue=totallValue,image=image_url) notif=Notification(sender="admin",receiver=project.employer,text=u'برای پروژه شما پیشنهاد جدیدی ثبت شده است.',sentTime=datetime.datetime.now().replace(tzinfo=utc)) notif.save() offer.save() #if Offering.objects.filter(project=project).count()==1: #mail(userId=1,kind="contact",text='offer Project.id='+str(project.id)) #contactFilter(offer.text,"offer",offer.id) related=relatedProjects(is_crowd=False,project_id=project.id,is_employer=False) related.save() userprofile.relatedProjects.add(related) userprofile.save() form['offered']=True string= "/project/"+str(project.id) return render_to_response('alert.html', {'error':"پیشنهاد شما با موفقیت ذخیره شد.شما میتوانید در صورت نیاز پیشنهاد خود را در همین قسمت ویرایش کنید.",'address':string}) elif request.method == 'GET': try: projectFile = ProjectFile.objects.get(project=project) form['attachedUrl'] = '/static/files/project/'+str(projectFile.id)+'.zip' except: pass try: UserProfile.objects.get(id=request.user.id) except: seconds=datetime.timedelta(hours=project.hourTimeForOffer)+project.offerTime-datetime.datetime.now().replace(tzinfo=utc) #print "times"+str(project.hourTimeForOffer) seconds=seconds.total_seconds() timediff = str(datetime.timedelta(seconds=seconds)) form['time_remain']=timediff[:timediff.find('.')] form['seconds_remain']=seconds if (seconds>0): form['is_time_remain']=True else: form['is_time_remain']=False form['offerlist']=offerlist form['offered']=False s = 0 count=0 for offer in offerlist: s = s + offer.totallValue count = count + 1 try: if request.user.userprofile == offer.offerer: form['offered']=True form['youroffer']=offer except: form['offered']=False if count: form['averageOfferValue'] = s/count else: form['averageOfferValue'] = 0 if project.is_wait_for_employee: offer=Offering.objects.get(id=project.choosedOffer_id) form['choosedOffer']=offer discussions = Discussion.objects.filter(project=project) return render_to_response('projectForOthers.html', {'form': form , 'discussions':discussions ,'login':False },context_instance=RequestContext(request)) userprofile=UserProfile.objects.get(id=request.user.id) discussions = Discussion.objects.filter(project=project) form['offerlist']=offerlist if project.employee: if project.employee.userprofile==userprofile: for offer in offerlist: if request.user.userprofile == offer.offerer: form['youroffer']=offer yourofferimages=offer.image if offer.is_accepted_by_employee: form['offer_finished']=True form['images']=yourofferimages.split(',') valueCases={} form['cases']=casesforemployer form['is_employer']=False form['project']=project form['valueCases']=valueCases files=project.files.all().order_by('uploadTime').reverse() form['files']=files return render_to_response('projectForEmployeeAfterStart.html', {'form': form , 'login':True , 'user':request.user } ,context_instance=RequestContext(request)) else: return render_to_response('projectForOthers.html', {'login':True, 'user':request.user , 'form': form,'discussions':discussions},context_instance=RequestContext(request)) else: seconds=datetime.timedelta(hours=project.hourTimeForOffer)+project.offerTime-datetime.datetime.now().replace(tzinfo=utc) #print datetime.datetime.now().replace(tzinfo=utc).replace(tzinfo=utc) #print project.hourTimeForOffer seconds=seconds.total_seconds() timediff = str(datetime.timedelta(seconds=seconds)) form['time_remain']=timediff[:timediff.find('.')] form['seconds_remain']=seconds if (seconds>0): form['is_time_remain']=True else: form['is_time_remain']=False form['offerlist']=offerlist form['offered']=False s = 0. count=0 for offer in offerlist: s = s + offer.totallValue count = count + 1 if request.user.userprofile == offer.offerer: form['offered']=True form['youroffer']=offer if count: form['averageOfferValue'] = s/count else: form['averageOfferValue'] = 0 if project.is_wait_for_employee: offer=Offering.objects.get(id=project.choosedOffer_id) form['choosedOffer']=offer discussions = Discussion.objects.filter(project=project) return render_to_response('projectForOthers.html', {'form': form ,'login':True, 'user':request.user , 'discussions':discussions },context_instance=RequestContext(request))