コード例 #1
0
 def MakeCompletedResults(userkey):
     all_answers = [
         model.TestAnswer(user=userkey, expected=word, got='grapes')
         for word in word_categories.keys()
     ]
     result = model.TestResult(parent=userkey, answers=all_answers)
     self.assertTrue(result.AllWordsAnswered())
     return result
コード例 #2
0
ファイル: test_report_actions.py プロジェクト: rekab/papt
 def PutTestResult(self, user_key, flavor, answers):
     result = model.TestResult(id=flavor, parent=user_key, flavor=flavor)
     for answer in answers:
         result.answers.append(
             model.TestAnswer(user=user_key,
                              expected=answer[0],
                              got=answer[1],
                              test_flavor=flavor))
     return result.put()
コード例 #3
0
ファイル: test_actions.py プロジェクト: rekab/papt
def start():
    user, posted_json = validate_json(['test_flavor'])
    flavor = posted_json['test_flavor']
    key = ndb.Key(model.TestResult, flavor, parent=user.key)
    test_result = key.get()
    if not test_result:
        model.TestResult(id=flavor, parent=user.key, flavor=flavor).put()
    else:
        # TODO: should this be an error? Support resuming a test?
        logging.error('Started a test that already existed? %d', posted_json)
    return jsonify(message='ok')
コード例 #4
0
    def testAnswersAreComplete(self):
        user1 = model.User(name=model.UserName('user-1'))

        # Test a result with only one answer.
        result = model.TestResult(parent=user1.key,
                                  answers=[
                                      model.TestAnswer(user=user1.key,
                                                       expected='pair',
                                                       got='pair')
                                  ])
        self.assertFalse(result.AllWordsAnswered())

        # Add all the answers.
        for word in model.WordCategorizer.GetTestWords():
            result.answers.append(
                model.TestAnswer(user=user1.key, expected=word))

        # Verify all words accounted for.
        self.assertTrue(result.AllWordsAnswered())
コード例 #5
0
    def testGroup1Answers(self):
        user1 = model.User(name=model.UserName('user-1'))
        user1.put()

        answer = model.TestAnswer(user=user1.key, expected='pair', got='pair')
        result = model.TestResult(parent=user1.key, answers=[answer])
        result.put()
        # Expect that "pair" for a user in group 1 to be categorized as "dm-imm".
        # See static/data/word-categories.json.
        self.assertEqual('dm-imm', result.answers[0].category)
        self.assertTrue(result.answers[0].correct)

        answer = model.TestAnswer(user=user1.key,
                                  expected='save',
                                  got='recover')
        result.answers.append(answer)
        result.put()

        readback = result.key.get()
        self.assertEqual('dm-imm', readback.answers[0].category)
        self.assertTrue(readback.answers[0].correct)
        self.assertEqual('nt-imm', readback.answers[1].category)
        self.assertFalse(readback.answers[1].correct)