def makeDialogSession(prefix, nPrompts=0, nHints=0, goodClosing=True, sessionCompleted=False):
     ds = DialogSession(
         userName=prefix + 'UserName',
         userID=prefix + 'UserID',
         conceptID=prefix + 'ConceptID',
         nPrompts=nPrompts,
         nHints=nHints,
         closingType=DialogSession.BAD_CLOSING if goodClosing else DialogSession.GOOD_CLOSING,
         sessionCompleted=sessionCompleted,
     )
     ds.addStudentStatement(prefix + " msg", 1.0, 1.0)
     return ds
示例#2
0
    def testRealWorldReadWrite(self):
        def makeDialogSession(prefix,
                              nPrompts=0,
                              nHints=0,
                              goodClosing=True,
                              sessionCompleted=False):
            ds = DialogSession(
                userName=prefix + 'UserName',
                userID=prefix + 'UserID',
                conceptID=prefix + 'ConceptID',
                nPrompts=nPrompts,
                nHints=nHints,
                closingType=DialogSession.BAD_CLOSING
                if goodClosing else DialogSession.GOOD_CLOSING,
                sessionCompleted=sessionCompleted,
            )
            ds.addStudentStatement(prefix + " msg", 1.0, 1.0)
            return ds

        source = StudentSessionData("TestUserID", "TestUserName")
        source.addSession("concept1", makeDialogSession("C1D1", 1, 1))
        source.addSession("concept1", makeDialogSession("C1D2", 2, 2))
        source.addSession("concept2", makeDialogSession("C2D1", 3, 3))
        source.addSession("concept2", makeDialogSession("C2D2", 4, 4))

        self.wrapper.save(source)
        copy = self.wrapper.read(source.getId())

        self.assertSerialEquals(source, copy)

        copy.addSession("concept3", makeDialogSession("C3D1", 5, 5))
        self.assertNotEquals(tokenizeObject(source), tokenizeObject(copy))

        self.wrapper.save(copy)
        copy2 = self.wrapper.read(source.getId())

        self.assertSerialEquals(copy, copy2)

        #Dialog sessions use session ID as their key, which allows us
        #to test custom key logic with our wrapper
        #ALSO - they use the decorator so we can test them separately
        ds = makeDialogSession("Standalone", 5, 5)
        ds.save()
        #Use our save/read/compare check on an already saved object
        self.assertReadWrite(ds)

        dsCopy = DialogSession.objects(_id=ds.getSessionID())[0]
        self.assertSerialEquals(ds, dsCopy)

        dsCopy = DialogSession.read(ds.getSessionID())
        self.assertSerialEquals(ds, dsCopy)
示例#3
0
 def makeDialogSession(prefix,
                       nPrompts=0,
                       nHints=0,
                       goodClosing=True,
                       sessionCompleted=False):
     ds = DialogSession(
         userName=prefix + 'UserName',
         userID=prefix + 'UserID',
         conceptID=prefix + 'ConceptID',
         nPrompts=nPrompts,
         nHints=nHints,
         closingType=DialogSession.BAD_CLOSING
         if goodClosing else DialogSession.GOOD_CLOSING,
         sessionCompleted=sessionCompleted,
     )
     ds.addStudentStatement(prefix + " msg", 1.0, 1.0)
     return ds
    def testRealWorldReadWrite(self):
        def makeDialogSession(prefix, nPrompts=0, nHints=0, goodClosing=True, sessionCompleted=False):
            ds = DialogSession(
                userName=prefix + 'UserName',
                userID=prefix + 'UserID',
                conceptID=prefix + 'ConceptID',
                nPrompts=nPrompts,
                nHints=nHints,
                closingType=DialogSession.BAD_CLOSING if goodClosing else DialogSession.GOOD_CLOSING,
                sessionCompleted=sessionCompleted,
            )
            ds.addStudentStatement(prefix + " msg", 1.0, 1.0)
            return ds

        source = StudentSessionData("TestUserID", "TestUserName")
        source.addSession("concept1", makeDialogSession("C1D1", 1, 1))
        source.addSession("concept1", makeDialogSession("C1D2", 2, 2))
        source.addSession("concept2", makeDialogSession("C2D1", 3, 3))
        source.addSession("concept2", makeDialogSession("C2D2", 4, 4))
        
        self.wrapper.save(source)
        copy = self.wrapper.read(source.getId())
        
        self.assertSerialEquals(source, copy)
        
        copy.addSession("concept3", makeDialogSession("C3D1", 5, 5))
        self.assertNotEquals(tokenizeObject(source), tokenizeObject(copy))
        
        self.wrapper.save(copy)
        copy2 = self.wrapper.read(source.getId())
        
        self.assertSerialEquals(copy, copy2)
        
        #Dialog sessions use session ID as their key, which allows us
        #to test custom key logic with our wrapper
        #ALSO - they use the decorator so we can test them separately
        ds = makeDialogSession("Standalone", 5, 5)
        ds.save()
        #Use our save/read/compare check on an already saved object
        self.assertReadWrite(ds)
        
        dsCopy = DialogSession.objects(_id=ds.getSessionID())[0]
        self.assertSerialEquals(ds, dsCopy)
        
        dsCopy = DialogSession.read(ds.getSessionID())
        self.assertSerialEquals(ds, dsCopy)