def test_path_or_resource(self): c = Client() obj = TestModel() obj.test = "TESTING" obj.save() resource = resources1.Test_1_1_Resource() list_path = resource.get_resource_list_uri() object_path = resource.get_resource_uri(obj) result = c._path_or_resource(list_path) expected = list_path self.assertEqual(result, expected, "Bare path.\nResult:%s\nExpected:%s" % (result, expected)) result = c._path_or_resource(list_path, obj) expected = list_path self.assertEqual(result, expected, "Bare path w/obj.\nResult:%s\nExpected:%s" % (result, expected)) result = c._path_or_resource(resource) expected = list_path self.assertEqual(result, expected, "Empty resource.\nResult:%s\nExpected:%s" % (result, expected)) result = c._path_or_resource(resource, obj) expected = object_path self.assertEqual(result, expected, "Populated resource.\nResult:%s\nExpected:%s" % (result, expected))
def test_path_or_resource(self): c = Client() obj = TestModel() obj.test = 'TESTING' obj.save() resource = resources1.Test_1_1_Resource() list_path = resource.get_resource_list_uri() object_path = resource.get_resource_uri(obj) result = c._path_or_resource(list_path) expected = list_path self.assertEqual( result, expected, "Bare path.\nResult:%s\nExpected:%s" % (result, expected)) result = c._path_or_resource(list_path, obj) expected = list_path self.assertEqual( result, expected, "Bare path w/obj.\nResult:%s\nExpected:%s" % (result, expected)) result = c._path_or_resource(resource) expected = list_path self.assertEqual( result, expected, "Empty resource.\nResult:%s\nExpected:%s" % (result, expected)) result = c._path_or_resource(resource, obj) expected = object_path self.assertEqual( result, expected, "Populated resource.\nResult:%s\nExpected:%s" % (result, expected))
def create_test_backup(request): test_obj = json.loads(request.body) test = Test() #import pdb; pdb.set_trace() if request.user.is_authenticated(): owner = User_Profile.objects.filter(user=request.user) test.owner = owner[0] test.test_name = test_obj['PRE_TEST']['test_name'] #test.subject = test_obj['PRE_TEST'].subject #test.target_exam = test_obj['PRE_TEST'].target_exam #test.topics = test_obj['PRE_TEST'].topics_included test.total_time = test_obj['PRE_TEST']['total_time'] test.pass_criteria = test_obj['PRE_TEST']['pass_criteria'] test.assoicated_class = Class.objects.get(pk=test_obj['CLASS_INFO']) test.save() try: for item in test_obj['QUESTIONS']: question = Question() question.question_text = item['question_text'] question.explanation = item['explanation'] question.options = json.dumps(item['options']) question.hint = item['hint'] question.difficulty = item['difficulty_level'] question.points = item['points'] question.owner = owner[0] #question.target_exam = test.target_exam #question.subject = test.subject #question.topic = item.topic question.save() test.questions.add(question) data = {"status": "success"} return JsonResponse(data) except Exception, e: raise e
def create_test_backup(request): test_obj = json.loads(request.body) test = Test() #import pdb; pdb.set_trace() if request.user.is_authenticated(): owner = User_Profile.objects.filter(user = request.user) test.owner = owner[0] test.test_name = test_obj['PRE_TEST']['test_name'] #test.subject = test_obj['PRE_TEST'].subject #test.target_exam = test_obj['PRE_TEST'].target_exam #test.topics = test_obj['PRE_TEST'].topics_included test.total_time = test_obj['PRE_TEST']['total_time'] test.pass_criteria = test_obj['PRE_TEST']['pass_criteria'] test.assoicated_class = Class.objects.get(pk=test_obj['CLASS_INFO']) test.save() try: for item in test_obj['QUESTIONS']: question = Question() question.question_text = item['question_text'] question.explanation = item['explanation'] question.options = json.dumps(item['options']) question.hint = item['hint'] question.difficulty = item['difficulty_level'] question.points = item['points'] question.owner = owner[0] #question.target_exam = test.target_exam #question.subject = test.subject #question.topic = item.topic question.save() test.questions.add(question) data = {"status" : "success"} return JsonResponse(data) except Exception, e: raise e
def tests(id=None): if request.method == 'GET': if id is not None: test = Test.query.get(id) if test: return jsonify(test.serialize()), 200 else: return jsonify({"error": "Test doesn't exist"}), 404 else: tests = Test.query.all() tests = list(map(lambda test: test.serialize(), tests)) return jsonify(tests), 200 if request.method == 'POST': name = request.json.get("name") email = request.json.get("email") phone = request.json.get("phone") test = Test() test.name = name test.email = email test.phone = phone test.save() return jsonify(test.serialize()), 201 if request.method == 'PUT': name = request.json.get("name") email = request.json.get("email") phone = request.json.get("phone") test = Test.query.get(id) test.name = name test.email = email test.phone = phone test.update() return jsonify(test.serialize()), 200 if request.method == 'DELETE': name = request.json.get("name") email = request.json.get("email") phone = request.json.get("phone") test = Test.query.get(id) test.name = name test.email = email test.phone = phone test.delete() return jsonify(test.serialize()), 200
def save_test(request): print 'POST: ', request.POST rule = None if request.POST['pattern']: rule = Rule(pattern=request.POST['pattern'], replacement=request.POST['replacement']) rule.save() if rule: test = Test(input=request.POST['input'], output=request.POST['output'], rule=rule) else: test = Test(input=request.POST['input'], output=request.POST['output']) test.save() response_data = {} return HttpResponse(simplejson.dumps(response_data), mimetype="application/json")
def create_test(request): c=None if request.method=='POST': testname = request.POST.get('testname','') number = request.POST.get('q_number','') if 'course' in request.session: c = Course.objects.get(name=request.session['course']) if c : t = Test(name=testname,course = c.id ,question_number=number) t.save() c.number_test+=1 c.save() return HttpResponseRedirect(reverse('teacher_course',args=(c.name,))) else : return HttpResponse('wrong method')
def login(request): if request.method == "POST": form = testForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] studentnum = form.cleaned_data['studentnum'] studentmajor = form.cleaned_data['studentmajor'] test = Test() test.username = username test.studentnum = studentnum test.studentmajor = studentmajor test.save() return render(request, 'login.html') else: form = testForm() return render(request, 'login.html')
def send_presses(request, instance_name): instance = get_object_or_404(ExperimentInstance, name=instance_name) sessions = Session.objects.filter(instance=instance) searched_session = 0 _dict = request.POST.copy() for session in sessions: tests = Test.objects.filter(session=session) if len(tests) < instance.definition.session_length: searched_session = session new_test = Test(session=searched_session, number=_dict['config']) new_test.save() del(_dict['config']) print _dict for i in _dict: new_press = Press(test=new_test, key_number=int(i), time=int(_dict[i]), correct=True) new_press.save() return JsonResponse({'ok': 'ok'})
def test4031(request): data = json.loads(request.body) group = data["group"] score = data["score"] if group == None or score == None: return HttpResponse("Missing fields: group or score.") test = Test(name = "4031", group = group, score = score) test.save() text = "Vous avez eu " + str(score) + " nombres.</br>" text += "<a href='https://github.com/melodieverroeulst/psy'>Code Source</a>" return HttpResponse(json.dumps({ "title": "Merci!", "text": text, "html": True, "redirectTo": "/" }))
def test(id=None): if request.method == 'GET': if id is not None: test = Test.query.get( id) # None por defecto si no consigue el registro if test: return jsonify(test.serialize()), 200 return jsonify({"msg": "Test not found"}), 404 else: tests = Test.query.all() tests = list(map(lambda test: test.serialize(), tests)) return jsonify(tests), 200 if request.method == 'POST': name = request.json.get("name", None) email = request.json.get("email", None) if not name: return jsonify({"msg": "Name is required"}), 400 if not email: return jsonify({"msg": "Email is required"}), 400 test = Test() test.name = name test.email = email profile = Profile() profile.bio = request.json.get("bio", "") profile.facebook = request.json.get("facebook", "") profile.twitter = request.json.get("twitter", "") test.profile = profile test.save() #db.session.add(test) #db.session.commit() return jsonify(test.serialize()), 201 if request.method == 'PUT': return jsonify({"msg": "Ingresando por el metodo PUT"}), 200 if request.method == 'DELETE': return jsonify({"msg": "Ingresando por el metodo DELETE"}), 200
def send_presses(request, instance_name): instance = get_object_or_404(ExperimentInstance, name=instance_name) sessions = Session.objects.filter(instance=instance) searched_session = 0 _dict = request.POST.copy() for session in sessions: tests = Test.objects.filter(session=session) if len(tests) < instance.definition.session_length: searched_session = session new_test = Test(session=searched_session, number=_dict['config']) new_test.save() del (_dict['config']) print _dict for i in _dict: new_press = Press(test=new_test, key_number=int(i), time=int(_dict[i]), correct=True) new_press.save() return JsonResponse({'ok': 'ok'})
def post(self, request): form = UploadFileForm(request.POST, request.FILES) msg = '' if form.is_valid(): test = Test( start_time = convert_time(form.cleaned_data['start']), end_time = convert_time(form.cleaned_data['end']), author_id = UserProfile.objects.get(user__id=request.user.id), time = int(form.cleaned_data['time']) ) test.save() try: test.room = Room.objects.get(id=form.cleaned_data.get('room')) except: test.room = None finally: test.save() try: self.handle_uploaded_file(test.id, request.FILES['file']) except: test.delete() msg = {'error': 'Wystąpił konflikt terminów. Test nie został dodany.'} return render(request, self.template_name, {'form': form, 'msg': msg}) else: test.name = self.get_test_name_from_file(test.id) test.save() return HttpResponseRedirect(reverse('tests')) else: msg = {'error': u'Wystąpił błąd podczas ładowania pliku.'} form = UploadFileForm() return render(request, self.template_name, {'form': form, 'msg': msg})
def upload_text(request): if request.POST.get('txt'): m = Test(upl_text=request.POST.get('txt')) m.save() return HttpResponseRedirect('/success')
def dbinsert(request): test1 = Test(name='mimi', age=8) test1.save() return HttpResponse("<p>数据添加成功!</p>")
def testdb(request): test1 = Test(name='runoob') test1.save() return HttpResponse("<p>data add success!</p>")
def testdb(request): test1 = Test(name="runoob") test1.save() return HttpResponse("Save data success")
def createRecord(request): test1 = Test(name='runoob') test1.save() return HttpResponse("<p>数据添加成功!</p>")
def parse(self): t = Test(name="aaaaaaaasd", type="yxc") t.save() return t.name