def getExercise(test_type="", test_subtype="", test_diff="", test_index=""): ch = RappPlatformAPI() response = ch.cognitiveExerciseSelect(test_type=test_type, test_subtype=test_subtype, test_diff=test_diff, test_index=test_index) if response['error'] != '': print response['error'] sys.exit(0) for key, val in response.iteritems(): print key, val testInstance = response['test_instance'] testType = response['test_type'] testSubType = response['test_subtype'] questions = response['questions'] possibAns = response['possib_ans'] correctAns = response['correct_ans'] language = response['lang'] cogTest = CognitiveTest(testType, testSubType, testInstance, questions, possibAns, correctAns, language) if testType == 'ArithmeticCts': if testSubType == 'BasicArithmeticCts': return BasicArithmericCts(cogTest) elif testSubType == 'TimeDifferenceCts': return TimeDifferenceCts(cogTest) elif testSubType == 'TransactionChangeCts': return TransactionChangeCts(cogTest) else: return None elif testType == 'AwarenessCts': if testSubType == 'TimeDayYearCts': return TimeDayYearCts(cogTest) else: return None elif testType == 'ReasoningCts': if testSubType == 'StoryTellingCts': return StoryTellingCts(cogTest) elif testSubType == 'WordRememberingCts': return WordRememberingCts(cogTest) else: return None else: return None
def getExercise(test_type="", test_subtype="", test_diff="", test_index=""): ch = RappPlatformAPI() response = ch.cognitiveExerciseSelect(test_type=test_type, test_subtype=test_subtype, test_diff=test_diff, test_index=test_index) if response['error'] != '': print response['error'] sys.exit(0) for key, val in response.iteritems(): print key, val testInstance = response['test_instance'] testType = response['test_type'] testSubType = response['test_subtype'] questions = response['questions'] possibAns = response['possib_ans'] correctAns = response['correct_ans'] language = response['lang'] cogTest = CognitiveTest(testType, testSubType, testInstance, questions, possibAns, correctAns, language) if testType == 'ArithmeticCts': if testSubType == 'BasicArithmeticCts': return BasicArithmericCts(cogTest) elif testSubType == 'TimeDifferenceCts': return TimeDifferenceCts(cogTest) elif testSubType == 'TransactionChangeCts': return TransactionChangeCts(cogTest) else: return None elif testType == 'AwarenessCts': if testSubType == 'TimeDayYearCts': return TimeDayYearCts(cogTest) else: return None elif testType == 'ReasoningCts': if testSubType == 'StoryTellingCts': return StoryTellingCts(cogTest) elif testSubType == 'WordRememberingCts': return WordRememberingCts(cogTest) else: return None else: return None
class CognitiveTestRecordTests(unittest.TestCase): def setUp(self): self.ch = RappPlatformAPI() def test_recordReasoning(self): response = self.ch.cognitiveExerciseSelect('ReasoningCts') self.assertEqual(response['error'], u'') self.assertNotEqual(response['test_instance'], u'') instance = response['test_instance'] response = self.ch.cognitiveRecordPerformance(instance, 50) self.assertEqual( 'CognitiveTestPerformed' in response['performance_entry'], True) def test_recordAwareness(self): response = self.ch.cognitiveExerciseSelect('AwarenessCts') self.assertEqual(response['error'], u'') self.assertNotEqual(response['test_instance'], u'') instance = response['test_instance'] response = self.ch.cognitiveRecordPerformance(instance, 50) self.assertEqual( 'CognitiveTestPerformed' in response['performance_entry'], True) def test_recordArithmetic(self): response = self.ch.cognitiveExerciseSelect('ArithmeticCts') self.assertEqual(response['error'], u'') self.assertNotEqual(response['test_instance'], u'') instance = response['test_instance'] response = self.ch.cognitiveRecordPerformance(instance, 50) self.assertEqual( 'CognitiveTestPerformed' in response['performance_entry'], True) def test_recordWrongType(self): response = self.ch.cognitiveExerciseSelect('ArithmeticCts') self.assertEqual(response['error'], u'') self.assertNotEqual(response['test_instance'], u'') instance = response['test_instance'] response = self.ch.cognitiveRecordPerformance(3, 50) self.assertNotEqual(response['error'], u'') def test_recordWrongScoreType(self): response = self.ch.cognitiveExerciseSelect('ArithmeticCts') self.assertEqual(response['error'], u'') self.assertNotEqual(response['test_instance'], u'') instance = response['test_instance'] response = self.ch.cognitiveRecordPerformance(instance, '200') self.assertNotEqual(response['error'], u'') def test_recordWrongScoreValues(self): response = self.ch.cognitiveExerciseSelect('ArithmeticCts') self.assertEqual(response['error'], u'') self.assertNotEqual(response['test_instance'], u'') instance = response['test_instance'] response = self.ch.cognitiveRecordPerformance(instance, 200) self.assertNotEqual(response['error'], u'') response = self.ch.cognitiveRecordPerformance(instance, -200) self.assertNotEqual(response['error'], u'')
class CognitiveTestChooserTests(unittest.TestCase): def setUp(self): self.ch = RappPlatformAPI() # Wait till the service is up using an erroneous call for fast return counter = 0 timeout = 120 while counter < timeout: counter = counter + 1 res = self.ch.cognitiveExerciseSelect(0) if res['error'] != u'Connection Error': break time.sleep(1) print 'Waiting for service... ' + str(timeout - counter) if counter == timeout: self.assertEqual('Connection error', True) def test_selectArithmeticTest(self): res = self.ch.cognitiveExerciseSelect('ArithmeticCts', 'TransactionChangeCts', '1', '1') self.assertEqual(res['error'], u"") self.assertNotEqual(res['test_instance'], u"") self.assertNotEqual(res['test_type'], u"") self.assertNotEqual(res['test_subtype'], u"") self.assertNotEqual(res['questions'], u"") self.assertNotEqual(res['possib_ans'], u"") self.assertNotEqual(res['correct_ans'], u"") def test_selectArithmeticTest_default_params(self): res = self.ch.cognitiveExerciseSelect('ArithmeticCts') self.assertEqual(res['error'], u"") self.assertNotEqual(res['test_instance'], u"") self.assertNotEqual(res['test_type'], u"") self.assertNotEqual(res['test_subtype'], u"") self.assertNotEqual(res['questions'], u"") self.assertNotEqual(res['possib_ans'], u"") self.assertNotEqual(res['correct_ans'], u"") def test_selectAwarenessTest(self): res = self.ch.cognitiveExerciseSelect('AwarenessCts') self.assertEqual(res['error'], u"") self.assertNotEqual(res['test_instance'], u"") self.assertNotEqual(res['test_type'], u"") self.assertNotEqual(res['test_subtype'], u"") self.assertNotEqual(res['questions'], u"") self.assertNotEqual(res['possib_ans'], u"") self.assertNotEqual(res['correct_ans'], u"") def test_selectReasoningTest(self): res = self.ch.cognitiveExerciseSelect('ReasoningCts') self.assertEqual(res['error'], u"") self.assertNotEqual(res['test_instance'], u"") self.assertNotEqual(res['test_type'], u"") self.assertNotEqual(res['test_subtype'], u"") self.assertNotEqual(res['questions'], u"") self.assertNotEqual(res['possib_ans'], u"") self.assertNotEqual(res['correct_ans'], u"") def test_selectNotExistentTest(self): res = self.ch.cognitiveExerciseSelect('KoukouroukouCts') self.assertNotEqual(res['error'], u"") def test_selectWrongType_TestType(self): res = self.ch.cognitiveExerciseSelect(3) self.assertNotEqual(res['error'], u"") def test_selectWrongType_TestSubtype(self): res = self.ch.cognitiveExerciseSelect('ArithmeticCts', 3) self.assertNotEqual(res['error'], u"") def test_selectWrongType_TestDiff(self): res = self.ch.cognitiveExerciseSelect('ArithmeticCts', '', 4) self.assertNotEqual(res['error'], u"") def test_selectWrongType_TestIndex(self): res = self.ch.cognitiveExerciseSelect('ArithmeticCts', '', '1', 3) self.assertNotEqual(res['error'], u"")