本文整理汇总了Python中models.Test类的典型用法代码示例。如果您正苦于以下问题:Python Test类的具体用法?Python Test怎么用?Python Test使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Test类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_test
def new_test():
form = TestForm()
if form.validate_on_submit():
test = Test(
test_name=form.test_name.data,
num_mc=form.num_mc.data,
mc_answers = int(form.mc_answers.data),
num_or=form.num_or.data,
#or_points = int(form.or_points.data),
num_students=form.num_students.data,
#test_data = defaultGrid(form.num_mc.data, int(form.mc_answers.data), form.num_or.data, form.or_points.data,form.num_students.data),
mc_data = mcDetails(form.num_mc.data, int(form.mc_answers.data)),
or_data = orDetails(form.num_mc.data,form.num_or.data),
student_data = studentDetails(form.num_students.data),
added_by=session['email']
)
try:
test.put()
test_id = test.key.id()
test = Test.get_by_id(test_id)
mc_data = json.dumps(test.mc_data)
or_data = json.dumps(test.or_data)
student_data = json.dumps(test.student_data)
flash(u'Test %s successfully saved.' % test_id, 'success')
return render_template('test_details.html', test = Test.get_by_id(test_id), test_id = test_id, mc_data = mc_data, or_data = or_data, student_data = student_data)
except CapabilityDisabledError:
flash(u'App Engine Datastore is currently in read-only mode.', 'info')
return redirect(url_for('list_tests'))
return redirect(url_for('list_tests'))
示例2: test_merge
def test_merge(self):
branch, platform, builder = _create_some_builder()
some_build = _create_build(branch, platform, builder)
some_result = TestResult.get_or_insert_from_parsed_json('some-test', some_build, 50)
some_test = Test.update_or_insert('some-test', branch, platform)
other_build = _create_build(branch, platform, builder, 'other-build')
other_result = TestResult.get_or_insert_from_parsed_json('other-test', other_build, 30)
other_test = Test.update_or_insert('other-test', branch, platform)
self.assertOnlyInstances([some_result, other_result])
self.assertNotEqual(some_result.key(), other_result.key())
self.assertOnlyInstances([some_test, other_test])
self.assertRaises(AssertionError, some_test.merge, (some_test))
self.assertOnlyInstances([some_test, other_test])
some_test.merge(other_test)
results_for_some_test = TestResult.all()
results_for_some_test.filter('name =', 'some-test')
results_for_some_test = results_for_some_test.fetch(5)
self.assertEqual(len(results_for_some_test), 2)
self.assertEqual(results_for_some_test[0].name, 'some-test')
self.assertEqual(results_for_some_test[1].name, 'some-test')
if results_for_some_test[0].value == 50:
self.assertEqual(results_for_some_test[1].value, 30)
else:
self.assertEqual(results_for_some_test[1].value, 50)
示例3: test_path_or_resource
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))
示例4: _create_results
def _create_results(branch, platform, builder, test_name, values):
results = []
for i, value in enumerate(values):
build = Build(branch=branch, platform=platform, builder=builder,
buildNumber=i, revision=100 + i, timestamp=datetime.now())
build.put()
result = TestResult(name=test_name, build=build, value=value)
result.put()
Test.update_or_insert(test_name, branch, platform)
results.append(result)
return results
示例5: execute
def execute(id):
test = Test.get_by_key_name(testName)
returnValue = None
if not test:
test = Test(id=id, name=testName, key_name=testName)
returnValue = test
if branch.key() not in test.branches:
test.branches.append(branch.key())
if platform.key() not in test.platforms:
test.platforms.append(platform.key())
test.put()
return returnValue
示例6: test_value_two_platforms
def test_value_two_platforms(self):
webkit_trunk = Branch.create_if_possible('webkit-trunk', 'WebKit trunk')
some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
other_platform = Platform.create_if_possible('other-platform', 'Other Platform')
Test.update_or_insert('some-test', webkit_trunk, some_platform)
Test.update_or_insert('some-test', webkit_trunk, other_platform)
self.assertEqual(DashboardJSONGenerator().value(), {
'defaultBranch': 'WebKit trunk',
'branchToId': {'WebKit trunk': webkit_trunk.id},
'platformToId': {'Some Platform': some_platform.id, 'Other Platform': other_platform.id},
'testToId': {'some-test': Test.get_by_key_name('some-test').id},
})
示例7: test_update_or_insert_to_update
def test_update_or_insert_to_update(self):
branch = Branch.create_if_possible('some-branch', 'Some Branch')
platform = Platform.create_if_possible('some-platform', 'Some Platform')
test = Test.update_or_insert('some-test', branch, platform)
self.assertOnlyInstance(test)
other_branch = Branch.create_if_possible('other-branch', 'Other Branch')
other_platform = Platform.create_if_possible('other-platform', 'Other Platform')
test = Test.update_or_insert('some-test', other_branch, other_platform, 'ms')
self.assertOnlyInstance(test)
self.assertEqualUnorderedList(test.branches, [branch.key(), other_branch.key()])
self.assertEqualUnorderedList(test.platforms, [platform.key(), other_platform.key()])
self.assertEqualUnorderedList(test.unit, 'ms')
示例8: get
def get(self, in_test_id=None):
template_values = get_template_values( self )
user = users.get_current_user()
try:
entity = Entity.query( Entity.id == user.user_id() ).get()
if not entity.display_name: # It's only slightly possible to have a user with no display_name
self.redirect('/login')
except:
self.redirect('/login')
else:
test_query = Test.query( ancestor = ndb.Key('Entity', user.user_id() ) )
if len(test_query.fetch()) > 0:
if in_test_id:
in_query = test_query.filter( Test.id == in_test_id ).fetch(1)
try: # The test exists
template_values = add_test_to_template( template_values, in_query[0] )
except IndexError: # The test does not exist
self.redirect("/")
potential_groups = set(
itertools.chain( entity.test_groups, default_groups )
)
print potential_groups
grouped_marks = get_grouped_marks( entity.id )
# Add groups with levels for level dropdown
template_values['user_levels'] = json.dumps( grouped_marks )
# Add list of groups for group dropdown
template_values['user_groups'] = []
for group in grouped_marks:
group_test_query = Test.query( Test.group == group['group'] ).order(-Test.level).fetch()
try:
threshold = group_test_query[0]
except:
threshold = 0
print threshold
for mark in grouped_marks:
potential_groups = potential_groups - set(group['group'])
if mark['group'] == group and mark["level"] >= threshold:
template_values['user_groups'].append( group )
for group in potential_groups:
template_values['user_groups'].append( group )
if template_values["user_groups"] == []:
template_values['error'] = "You may only create a test in a new category."
path = os.path.join( os.path.dirname(__file__), os.path.join( template_dir, 'create.html' ) )
self.response.out.write( template.render( path, template_values ))
return
示例9: create_test_backup
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
示例10: save_test
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")
示例11: create_test
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')
示例12: post
def post(self):
self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'
log_id = int(self.request.get('id', 0))
log = ReportLog.get_by_id(log_id)
if not log or not log.commit:
self.response.out.write("Not processed")
return
branch = log.branch()
platform = log.platform()
build = Build.get_or_insert_from_log(log)
for test_name, result_value in log.results().iteritems():
test = Test.update_or_insert(test_name, branch, platform)
result = TestResult.get_or_insert_from_parsed_json(test_name, build, result_value)
runs = Runs.get_by_objects(branch, platform, test)
regenerate_runs = True
if runs:
runs.update_incrementally(build, result)
regenerate_runs = False
schedule_runs_update(test.id, branch.id, platform.id, regenerate_runs)
log = ReportLog.get(log.key())
log.delete()
# We need to update dashboard and manifest because they are affected by the existance of test results
schedule_dashboard_update()
schedule_manifest_update()
self.response.out.write('OK')
示例13: get
def get(self):
self.response.headers['Content-Type'] = 'application/json; charset=utf-8';
cache = memcache.get('dashboard')
if cache:
self.response.out.write(cache)
return
webkit_trunk = Branch.get_by_key_name('webkit-trunk')
# FIXME: Determine popular branches, platforms, and tests
dashboard = {
'defaultBranch': 'WebKit trunk',
'branchToId': {webkit_trunk.name: webkit_trunk.id},
'platformToId': {},
'testToId': {},
}
for platform in Platform.all():
dashboard['platformToId'][platform.name] = platform.id
for test in Test.all():
dashboard['testToId'][test.name] = test.id
result = json.dumps(dashboard)
self.response.out.write(result)
memcache.add('dashboard', result)
示例14: post
def post( self, in_test_id ):
path = urlparse.urlsplit(self.request.referrer).path
author_id = self.request.get("author_id")
test_id = self.request.get("test_id")
mark_id = self.request.get("mark_id")
address = self.request.get("mark_address")
comment = self.request.get("comment")
mark = self.request.get("mark")
author_entity = Entity.query( Entity.id == author_id ).get()
test_entity = Test.query( Test.id == test_id ).get()
mark_entity = Mark.query( ancestor = ndb.Key("Entity", mark_id) )
mark_entity = mark_entity.filter( Mark.test.id == test_id ).get()
mark_entity.marker_entity = author_entity
mark_entity.test = test_entity
mark_entity.comment = comment
mark_entity.mark = int(mark)
test_entity.total_score += mark_entity.mark
test_entity.num_marked += 1
mark_entity.modified = datetime.datetime.now()
mark_entity.complete = True
mark_entity.put()
send_email( address, test_entity, "Answer-Response")
test_entity.put()
self.redirect( path )
return
示例15: test_value_single_platform
def test_value_single_platform(self):
some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
self.assertEqual(ManifestJSONGenerator().value(), {'branchMap': {}, 'platformMap': {}, 'testMap': {}})
some_test = Test.update_or_insert('some-test', some_branch, some_platform)
self._assert_single_test(ManifestJSONGenerator().value(), some_branch, some_platform, some_test)