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 = 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 fsm_state(user, fsm, course, unit, unit_lesson_canvas): request_data = {'session': {}, 'user': user} request = namedtuple('Request', request_data.keys())(*request_data.values()) stateData = { 'course': course, 'unit': unit, } stack = FSMStack(request) stack.push(request, fsm.name, stateData, unitLesson=unit_lesson_canvas) return stack.state
def push_state(self, chat, request, name, start_args=None): fsm_stack = FSMStack(request) course_unit = chat.enroll_code.courseUnit fsm_stack.push(request, name, stateData={'unit': course_unit.unit, 'course': course_unit.course}, startArgs=start_args) fsm_stack.state.parentState = chat.state fsm_stack.state.save() chat.state = fsm_stack.state chat.save()
def fsm_state(user, fsm, course, unit, unit_lesson_canvas): request_data = {'session': {}, 'user': user} request = namedtuple('Request', list( request_data.keys()))(*list(request_data.values())) stateData = { 'course': course, 'unit': unit, } stack = FSMStack(request) stack.push(request, fsm.name, stateData, unitLesson=unit_lesson_canvas) return stack.state
def push_state(self, chat, request, name, start_args=None): fsm_stack = FSMStack(request) course_unit = chat.enroll_code.courseUnit fsm_stack.push(request, name, stateData={ 'unit': course_unit.unit, 'course': course_unit.course }, startArgs=start_args) fsm_stack.state.parentState = chat.state fsm_stack.state.save() chat.state = fsm_stack.state chat.save()
def push_state(self, chat, request, name, start_args=None, **kwargs): fsm_stack = FSMStack(request) linkState = kwargs.get('linkState') course_unit = kwargs.get('courseUnit', chat.enroll_code.courseUnit) fsm_stack.push(request, name, stateData={'unit': course_unit.unit, 'course': course_unit.course}, startArgs=start_args, isLiveSession=True, linkState=linkState) fsm_stack.state.parentState = chat.state fsm_stack.state.save() chat.state = fsm_stack.state chat.save()
def push_state(self, chat, request, name, start_args=None, **kwargs): fsm_stack = FSMStack(request) linkState = kwargs.get('linkState') course_unit = kwargs.get('courseUnit', chat.enroll_code.courseUnit) fsm_stack.push(request, name, stateData={ 'unit': course_unit.unit, 'course': course_unit.course }, startArgs=start_args, isLiveSession=True, linkState=linkState) fsm_stack.state.parentState = chat.state fsm_stack.state.save() chat.state = fsm_stack.state chat.save()
def get_fsm_request(self, fsmName, stateData, startArgs=None, user=None, **kwargs): """ Create request, fsmStack and start specified FSM. """ startArgs = startArgs or {} request = FakeRequest(user) request.session = self.client.session fsmStack = FSMStack(request) result = fsmStack.push(request, fsmName, stateData, startArgs, **kwargs) request.session.save() return request, fsmStack, result
def get_fsm_request(self, fsmName, stateData, startArgs=None, **kwargs): """ Create request, fsmStack and start specified FSM. """ startArgs = startArgs or {} request = FakeRequest(self.user) request.session = self.client.session fsmStack = FSMStack(request) result = fsmStack.push(request, fsmName, stateData, startArgs, **kwargs) request.session.save() return request, fsmStack, result
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 = 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