def do_start(self, f, **kwargs): 'run tests of basic startup of new FSM instance' fsmData = dict(unit=self.unit, foo='bar') request = FakeRequest(self.user) fsmStack = fsm.FSMStack(request) self.assertIsNone(fsmStack.state) try: result = fsmStack.push(request, 'invalid', stateData=fsmData, **kwargs) except FSM.DoesNotExist: pass else: raise AssertionError('failed to catch bad FSM query') result = fsmStack.push(request, 'test', stateData=fsmData, **kwargs) self.assertEqual(request.session['fsmID'], fsmStack.state.pk) self.assertEqual(fsmStack.state.load_json_data(), fsmData) self.assertEqual(fsmStack.state.fsmNode.name, 'MID') self.assertEqual(fsmStack.state.fsmNode.path, 'ct:about') self.assertEqual( fsmStack.state.fsmNode.get_path(fsmStack.state, request), '/ct/about/') self.assertEqual(result, '/ct/about/') return fsmStack
def test_trivial_plugin(self): 'check trivial plugin import and call' f = FSM.save_graph(fsmDict, nodeDict, edgeDict, 'jacob') request = FakeRequest(self.user) fsmStack = fsm.FSMStack(request) fsmStack.state = FSMState(user=self.user, fsmNode=f.startNode) self.assertEqual(f.startNode.event(fsmStack, 0, 'start'), '/ct/about/') self.assertEqual(f.startNode.get_path(0, 0), '/ct/some/where/else/')
def test_bad_fsmID(self): 'make sure FSMStack silently handles bad fsmID' request = FakeRequest(self.user, dict(fsmID=99)) fsmStack = fsm.FSMStack(request) self.assertEqual(request.session, {}) self.assertIsNone(fsmStack.state)
def test_randomtrial(self): 'basic randomized trial' self.assertEqual(self.ulQ.order, 0) from ct.fsm_plugin.lessonseq import get_specs f = get_specs()[0].save_graph(self.user.username) # load FSM spec from ct.fsm_plugin.randomtrial import get_specs f = get_specs()[0].save_graph(self.user.username) # load FSM spec self.assertEqual(ActivityLog.objects.count(), 0) request = FakeRequest(self.user) request.session = self.client.session fsmStack = fsm.FSMStack(request) fsmData = dict(testFSM='lessonseq', treatmentFSM='lessonseq', treatment1=self.ulQ.unit, treatment2=self.ulQ.unit, testUnit=self.ulQ2.unit, course=self.course) result = fsmStack.push(request, 'randomtrial', fsmData, dict(trialName='test')) request.session.save() self.assertEqual(self.client.session['fsmID'], fsmStack.state.pk) self.assertEqual(result, '/ct/nodes/%d/' % f.startNode.pk) self.assertEqual(ActivityLog.objects.count(), 1) # rt FSM start page response = self.client.get(result) self.assertEqual(response.status_code, 200) self.assertContains(response, 'answer a few preliminary questions') url = '/ct/courses/%d/units/%d/lessons/%d/ask/' \ % (self.course.pk, self.ulQ2.unit.pk, self.ulQ2.pk) self.check_post_get(result, dict(fsmtask='next'), url, 'Scary Question') # pretest Q postdata = dict(text='i dunno', confidence=Response.GUESS) url = self.check_post_get(url, postdata, '/assess/', 'write an answer') # pretest assess assessPOST = dict(selfeval=Response.CORRECT, status=DONE_STATUS, liked='') url2 = '/ct/courses/%d/units/%d/lessons/%d/ask/' \ % (self.course.pk, self.ulQ.unit.pk, self.ulQ.pk) self.check_post_get(url, assessPOST, url2, 'your quest') # treatment Q postdata = dict(text='i like rats', confidence=Response.GUESS) url = self.check_post_get(url2, postdata, '/assess/', 'write an answer') # treatment assess url2 = '/ct/courses/%d/units/%d/lessons/%d/ask/' \ % (self.course.pk, self.ulQ2.unit.pk, self.ulQ2.pk) self.check_post_get(url, assessPOST, url2, 'Scary Question') # posttest Q postdata = dict(text='i still dunno', confidence=Response.GUESS) url = self.check_post_get(url2, postdata, '/assess/', 'write an answer') # posttest assess url2 = '/ct/courses/%d/units/%d/tasks/' \ % (self.course.pk, self.ulQ.unit.pk) self.check_post_get(url, assessPOST, url2, 'Next Step to work on') self.assertEqual( Response.objects.filter(activity__isnull=False, confidence=Response.GUESS).count(), 3) # check responses logged to RT activity