本文整理汇总了Python中models.Test类的典型用法代码示例。如果您正苦于以下问题:Python Test类的具体用法?Python Test怎么用?Python Test使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Test类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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'))
开发者ID:nbcesar,项目名称:sabered,代码行数:29,代码来源:views.py
示例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)
开发者ID:,项目名称:,代码行数:30,代码来源:
示例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))
开发者ID:thagat,项目名称:django-tastytools,代码行数:26,代码来源:tests.py
示例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
开发者ID:,项目名称:,代码行数:11,代码来源:
示例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
开发者ID:,项目名称:,代码行数:12,代码来源:
示例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},
})
开发者ID:,项目名称:,代码行数:12,代码来源:
示例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')
开发者ID:,项目名称:,代码行数:13,代码来源:
示例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
开发者ID:pierce403,项目名称:densando,代码行数:50,代码来源:views.py
示例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
开发者ID:adideshp,项目名称:Tutor,代码行数:34,代码来源:views.py
示例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")
开发者ID:timothyclemans,项目名称:InfluenceAPI,代码行数:14,代码来源:views.py
示例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')
开发者ID:CharlesCliff,项目名称:SC,代码行数:15,代码来源:teacherViews.py
示例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')
开发者ID:,项目名称:,代码行数:32,代码来源:
示例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)
开发者ID:sohocoke,项目名称:webkit,代码行数:26,代码来源:dashboard_handler.py
示例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
开发者ID:pierce403,项目名称:densando,代码行数:27,代码来源:views.py
示例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)
开发者ID:,项目名称:,代码行数:7,代码来源:
示例16: 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
webkitTrunk = Branch.get_by_key_name("webkit-trunk")
# FIXME: Determine popular branches, platforms, and tests
dashboard = {
"defaultBranch": "WebKit trunk",
"branchToId": {webkitTrunk.name: webkitTrunk.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)
开发者ID:,项目名称:,代码行数:27,代码来源:
示例17: post
def post(self):
self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'
try:
payload = json.loads(self.request.body)
hide = payload['hide']
except:
self.response.out.write("Failed to parse the payload: %s" % self.request.body)
return
if 'platform' in payload:
model = Platform.get_by_key_name(payload['platform'])
elif 'test' in payload:
model = Test.get_by_key_name(payload['test'])
else:
self.response.out.write('Not supported')
return
if not model:
self.response.out.write('Could not find the model')
return
model.hidden = hide
model.put()
schedule_dashboard_update()
schedule_manifest_update()
self.response.out.write('OK')
开发者ID:EQ4,项目名称:h5vcc,代码行数:28,代码来源:admin_handlers.py
示例18: test_update_incrementally
def test_update_incrementally(self):
some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
some_builder = Builder.get(Builder.create('some-builder', 'Some Builder'))
some_test = Test.update_or_insert('some-test', some_branch, some_platform)
self.assertThereIsNoInstanceOf(Runs)
timestamps = [datetime.now(), datetime.now()]
builds, results = self._create_results(some_branch, some_platform, some_builder, 'some-test', [50.0, 52.0], timestamps)
runs = Runs.update_or_insert(some_branch, some_platform, some_test)
self.assertOnlyInstance(runs)
self.assertEqual(json.loads('[' + runs.json_runs + ']'),
[[5, [4, 0, 100, None], mktime(timestamps[0].timetuple()), 50.0, 0, [], None, None],
[7, [6, 1, 101, None], mktime(timestamps[1].timetuple()), 52.0, 0, [], None, None]])
self.assertEqual(json.loads('{' + runs.json_averages + '}'), {"100": 50.0, "101": 52.0})
self.assertEqual(runs.json_min, 50.0)
self.assertEqual(runs.json_max, 52.0)
timestamps.append(datetime.now())
builds, results = self._create_results(some_branch, some_platform, some_builder, 'some-test', [48.0],
timestamps[2:], starting_revision=102)
runs.update_incrementally(builds[0], results[0])
self.assertOnlyInstance(runs)
self.assertEqual(json.loads('[' + runs.json_runs + ']'),
[[5, [4, 0, 100, None], mktime(timestamps[0].timetuple()), 50.0, 0, [], None, None],
[7, [6, 1, 101, None], mktime(timestamps[1].timetuple()), 52.0, 0, [], None, None],
[9, [8, 0, 102, None], mktime(timestamps[2].timetuple()), 48.0, 0, [], None, None]])
self.assertEqual(json.loads('{' + runs.json_averages + '}'), {"100": 50.0, "101": 52.0, "102": 48.0})
self.assertEqual(runs.json_min, 48.0)
self.assertEqual(runs.json_max, 52.0)
开发者ID:,项目名称:,代码行数:31,代码来源:
示例19: test_chart_params_with_value
def test_chart_params_with_value(self):
some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
some_builder = Builder.get(Builder.create('some-builder', 'Some Builder'))
some_test = Test.update_or_insert('some-test', some_branch, some_platform)
start_time = datetime(2011, 2, 21, 12, 0, 0)
end_time = datetime(2011, 2, 28, 12, 0, 0)
results = self._create_results(some_branch, some_platform, some_builder, 'some-test',
[50.0, 51.0, 52.0, 49.0, 48.0, 51.9, 50.7, 51.1],
[start_time + timedelta(day) for day in range(0, 8)])
# Use int despite of its impreciseness since tests may fail due to rounding errors otherwise.
def split_as_int(string):
return [int(float(value)) for value in string.split(',')]
params = Runs.update_or_insert(some_branch, some_platform, some_test).chart_params(7)
self.assertEqual(params['chxl'], '0:|Feb 21|Feb 22|Feb 23|Feb 24|Feb 25|Feb 26|Feb 27|Feb 28')
self.assertEqual(split_as_int(params['chxr']), [1, 0, 57, int(52 * 1.1 / 5 + 0.5)])
x_min, x_max, y_min, y_max = split_as_int(params['chds'])
self.assertEqual(datetime.fromtimestamp(x_min), start_time)
self.assertEqual(datetime.fromtimestamp(x_max), end_time)
self.assertEqual(y_min, 0)
self.assertEqual(y_max, int(52 * 1.1))
self.assertEqual(split_as_int(params['chg']), [int(100 / 7), 20, 0, 0])
params = Runs.update_or_insert(some_branch, some_platform, some_test).chart_params(14)
self.assertEqual(params['chxl'], '0:|Feb 14|Feb 16|Feb 18|Feb 20|Feb 22|Feb 24|Feb 26|Feb 28')
self.assertEqual(split_as_int(params['chxr']), [1, 0, 57, int(52 * 1.1 / 5 + 0.5)])
x_min, x_max, y_min, y_max = split_as_int(params['chds'])
self.assertEqual(datetime.fromtimestamp(x_min), datetime(2011, 2, 14, 12, 0, 0))
self.assertEqual(datetime.fromtimestamp(x_max), end_time)
self.assertEqual(y_min, 0)
self.assertEqual(y_max, int(52 * 1.1))
self.assertEqual(split_as_int(params['chg']), [int(100 / 7), 20, 0, 0])
开发者ID:,项目名称:,代码行数:35,代码来源:
示例20: test_to_json_with_results
def test_to_json_with_results(self):
some_branch = Branch.create_if_possible('some-branch', 'Some Branch')
some_platform = Platform.create_if_possible('some-platform', 'Some Platform')
some_builder = Builder.get(Builder.create('some-builder', 'Some Builder'))
some_test = Test.update_or_insert('some-test', some_branch, some_platform)
builds, results = self._create_results(some_branch, some_platform, some_builder, 'some-test', [50.0, 51.0, 52.0, 49.0, 48.0])
value = json.loads(Runs.update_or_insert(some_branch, some_platform, some_test).to_json())
self.assertEqualUnorderedList(value.keys(), ['test_runs', 'averages', 'min', 'max', 'unit', 'date_range', 'stat'])
self.assertEqual(value['stat'], 'ok')
self.assertEqual(value['min'], 48.0)
self.assertEqual(value['max'], 52.0)
self.assertEqual(value['unit'], None)
self.assertEqual(value['date_range'], None) # date_range is never given
self.assertEqual(len(value['test_runs']), len(results))
for i, run in enumerate(value['test_runs']):
result = results[i]
self.assertEqual(run[0], result.key().id())
self.assertEqual(run[1][1], i) # Build number
self.assertEqual(run[1][2], 100 + i) # Revision
self.assertEqual(run[1][3], None) # Supplementary revision
self.assertEqual(run[3], result.value)
self.assertEqual(run[6], some_builder.key().id())
self.assertEqual(run[7], None) # Statistics
开发者ID:,项目名称:,代码行数:25,代码来源:
注:本文中的models.Test类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论