예제 #1
0
 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
예제 #2
0
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
예제 #3
0
 def test_trivial_plugin(self):
     """
     Check trivial plugin import and call.
     """
     f = FSM.save_graph(self.fsmDict, self.nodeDict, self.edgeDict, "jacob")
     request = FakeRequest(self.user)
     fsmStack = FSMStack(request)
     fsmStack.state = FSMState(user=self.user, fsmNode=f.startNode)
     self.assertEqual(f.startNode.event(fsmStack, request, "start"), "/ct/about/")
     self.assertEqual(f.startNode.get_path(fsmStack.state, request), "/ct/some/where/else/")
예제 #4
0
 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
예제 #5
0
 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()
예제 #6
0
 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
예제 #7
0
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
예제 #8
0
 def test_trivial_plugin(self):
     """
     Check trivial plugin import and call.
     """
     f = FSM.save_graph(self.fsmDict, self.nodeDict, self.edgeDict, 'jacob')
     request = FakeRequest(self.user)
     fsmStack = FSMStack(request)
     fsmStack.state = FSMState(user=self.user, fsmNode=f.startNode)
     self.assertEqual(f.startNode.event(fsmStack, request, 'start'),
                      '/ct/about/')
     self.assertEqual(f.startNode.get_path(fsmStack.state, request),
                      '/ct/some/where/else/')
예제 #9
0
 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()
예제 #10
0
 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()
예제 #11
0
 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()
예제 #12
0
 def test_bad_fsmID(self):
     """
     Make sure FSMStack silently handles bad fsmID.
     """
     request = FakeRequest(self.user, dict(fsmID=99))
     fsmStack = FSMStack(request)
     self.assertEqual(request.session, {})
     self.assertIsNone(fsmStack.state)
예제 #13
0
 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