EduploneExam/tests testAnswers.py,1.1,1.2 testProcessResponse.py,1.1,1.2

Jens Klein <[email protected]>
Newsgroups gmane.comp.web.zope.eduplone.cvs
Message-ID <[email protected]>
Update of /cvsroot/eduplone/EduploneExam/tests
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26932/tests

Modified Files:
	testAnswers.py testProcessResponse.py 
Log Message:
started process response tests.


Index: testProcessResponse.py
===================================================================
RCS file: /cvsroot/eduplone/EduploneExam/tests/testProcessResponse.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** testProcessResponse.py	15 Dec 2004 14:37:02 -0000	1.1
--- testProcessResponse.py	15 Dec 2004 16:07:53 -0000	1.2
***************
*** 11,70 ****
  
  import common
- 
  common.installProducts()
  
! from Products.EduploneExam.registry import getAnswerTypes
! from Products.EduploneExam.userresponses import SimpleResponse
! from Products.EduploneExam import ExamFolder
  
! from Products.CMFCore.utils import getToolByName
  
  
  class TestResponse(PloneTestCase.PloneTestCase):
  
      def afterSetUp(self):
-         
          common.installWithinPortal(self.portal)
          #create examFolder to have the deliverResponse-method implemented
!         self.portal.invokeFactory('ExamFolder', 'ExamFolder')
!         examFolder=self.portal.ExamFolder
  
-         questid='dummyQuest' #()
-         examFolder.invokeFactory('MultipleChoiceQuestion', questid)
-         mchoiceQuest=examFolder[questid]
-         mcqParam={'title':'Question Title', 
-                   'maxScore':10, 
-                   'strict':'0'}
-         for p in mcqParam.keys():
-             mut=mchoiceQuest.getField(p).getMutator(mchoiceQuest)
-             mut(mcqParam[p])
-         
-    
-         mchoiceQuest.invokeFactory('MultipleChoiceAnswer', 'mcA1')
-         mchoiceQuest.invokeFactory('MultipleChoiceAnswer', 'mcA2')
-         mchoiceQuest.invokeFactory('MultipleChoiceAnswer', 'mcA3')
-         mchoiceQuest.invokeFactory('MultipleChoiceAnswer', 'mcA4')
-         mchoiceQuest.mcA1.setCorrect('1')
-         mchoiceQuest.mcA2.setCorrect('1')
-         mchoiceQuest.mcA3.setCorrect('0')
-         mchoiceQuest.mcA4.setCorrect('0')
-                             
  
-     def testMChoiceProcessAnswer(self):        
-         #self.loginPortalOwner()
-         
-         #send REQUEST.response-object to a question
-         REQresp=''
-         
-         mchoiceQuest.processResponse(REQresp)
-         
-         #get back the responseObject:
-         responseObjBack=examFolder.deliverResponse(mchoiceQuest)
-             
-    
-         #self.failUnless(responseObjIn==responseObjBack)
-             
-         #self.portal.manage_delObjects(['ExamFolder'])
-             
  
  def test_suite():
--- 11,81 ----
  
  import common
  common.installProducts()
  
! from ZPublisher.HTTPRequest import HTTPRequest
! from ZPublisher.HTTPResponse import HTTPResponse
! from ZPublisher.BaseRequest import RequestContainer
  
! def dummyrequest():
!     resp = HTTPResponse()
!     environ = {}
!     environ['SERVER_NAME']='foo'
!     environ['SERVER_PORT']='80'
!     environ['REQUEST_METHOD'] = 'POST'
!     environ['CONTENT_TYPE'] = content_type
!     req = HTTPRequest(stdin=file, environ=environ, response=resp)
!     return req
! 
! from testAnswers import alltestvalues as answervalues
  
+ questionvalues = {
+     'FillGapQuestion'       : ('BlindGap', 'ChoiceGap'),
+     'FreeTextQuestion'      : ('FreeText',),
+     'MatchingQuestion'      : ('Matching',),
+     'MathQuestion'          : ('Math',),
+     'MultipleChoiceQuestion': ('MultipleChoice',),
+     'SingleChoiceQuestion'  : ('SingleChoice',),
+     'TextTaskQuestion'      : ('TextTask',),
+     'TrueFalseQuestion'     : ('TrueFalse',),
+ }
  
  class TestResponse(PloneTestCase.PloneTestCase):
  
      def afterSetUp(self):
          common.installWithinPortal(self.portal)
          #create examFolder to have the deliverResponse-method implemented
!         self.loginPortalOwner()
!         self.folder.invokeFactory('ExamFolder', 'examfolder')
!         self.examfolder=self.folder.examfolder
! 
!     def makeQuestionsAnswers(self):
!         #set up questions
!         for questionkey in questionvalues:
!             self.examfolder.invokeFactory(questionkey, questionkey)
!             question=self.examfolder[questionkey]
!             # set up answers
!             for answertype in questionvalues[questionkey]:
!                 answers=answervalues[answertype]
!                 for answerkey in answers:
!                     answervalue = answers[answerkey]
!                     question.invokeFactory(answervalue['typ'], answerkey)
!                     answer=question[answerkey]
!                     for field in answervalue['param']:
!                         mut=answer.getField(field).getMutator(answer)
!                         mut(answervalue['param'][field])
! 
!     def buildResponse(self,question):
!         req = dummyrequest()
!         for question in self.examfolder.objectValues():
!             for answer in question.objectValues():
!                 pass
! 
!     def testProcessResponse(self):
!         self.makeQuestionsAnswers()
!         response=self.buildresponse()
!         for question in alltestvalues:
!             pass
  
  
  
  def test_suite():

Index: testAnswers.py
===================================================================
RCS file: /cvsroot/eduplone/EduploneExam/tests/testAnswers.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** testAnswers.py	14 Dec 2004 20:00:22 -0000	1.1
--- testAnswers.py	15 Dec 2004 16:07:53 -0000	1.2
***************
*** 17,108 ****
  from Products.CMFCore.utils import getToolByName
  
! 
! class TestAnswers(PloneTestCase.PloneTestCase):
! 
!     def afterSetUp(self):
!         
!         common.installWithinPortal(self.portal)
!         
!         qtypes = getAnswerTypes()
!         tt = self.portal.portal_types
!         for t in qtypes:
!             ti=tt[qtypes[t].meta_type]
!             ti.global_allow=True
! 
!         
! 
!     def testTrueFalseAnswer(self):
!        
!         testValues=(\
!         
!             {'typ':'TrueFalseAnswer', \
!              'param':\
!                  {'correct':'1', \
!                   #caseSensitive:True, \
                   },
!              'inValue':'False', \
!              'expectedValue':False,\
!             }, \
!             
!             {'typ':'TrueFalseAnswer', \
!              'param':\
!                  {'correct':'0', \
!                   #caseSensitive:True, \
                   },
!              'inValue':'False', \
!              'expectedValue':True,\
!             }, \
!         )
!         self.runAnswerTest(testValues)
!             
!             
!     def testSingleChoiceAnswer(self):        
!         
!         testValues=(\
!             {'typ':'SingleChoiceAnswer', \
!              'param':\
!                  {'correct':'1', \
!                   #caseSensitive:True, \
                   },
!              'inValue':'False', \
!              'expectedValue':False,\
!             }, \
!             {'typ':'SingleChoiceAnswer', \
!              'param':\
!                  {'correct':'1', \
!                   #caseSensitive:True, \
                   },
!              'inValue':'on', \
!              'expectedValue':True,\
!             }, \
!         )
!         self.runAnswerTest(testValues)
!             
!     def testMultipleChoiceAnswer(self):
!         testValues=(           
!             {'typ':'MultipleChoiceAnswer', \
!              'param':\
!                  {'correct':'1', \
                   },
!              'inValue':'on', \
!              'expectedValue':True,\
!             }, \
!             {'typ':'MultipleChoiceAnswer', \
               'param':\
!                  {'correct':'0', \
!                   #caseSensitive:True, \
                   },
!              'inValue':'on', \
!              'expectedValue':False,\
!             }, \
!         )
!         
!         self.runAnswerTest(testValues)
!         
!             
!             
!     def testBlindGapAnswer(self):
! 
!         testValues=(              
              {'typ':'BlindGapAnswer', \
               'param':\
--- 17,77 ----
  from Products.CMFCore.utils import getToolByName
  
! alltestvalues = {
!     'TrueFalse' : {
!         'TrueFalse1':
!             {'typ':'TrueFalseAnswer',
!              'param':
!                  {'correct':'1',
                   },
!              'inValue':'False',
!              'expectedValue':False,
!             },
!         'TrueFalse2':
!             {'typ':'TrueFalseAnswer',
!              'param':
!                  {'correct':'0',
                   },
!              'inValue':'False',
!              'expectedValue':True,
!             },
!         },
!     'SingleChoice': {
!         'SingleChoice1':
!             {'typ':'SingleChoiceAnswer',
!              'param':
!                  {'correct':'1',
                   },
!              'inValue':'False',
!              'expectedValue':False,
!             },
!         'SingleChoice2':
!             {'typ':'SingleChoiceAnswer',
!              'param':
!                  {'correct':'1',
                   },
!              'inValue':'on',
!              'expectedValue':True,
!             },
!         },
!     'MultipleChoice': {
!         'MultipleChoice1':
!             {'typ':'MultipleChoiceAnswer',
!              'param':
!                  {'correct':'1',
                   },
!              'inValue':'on',
!              'expectedValue':True,
!             },
!         'MultipleChoice2':
!             {'typ':'MultipleChoiceAnswer',
               'param':\
!                  {'correct':'0',
                   },
!              'inValue':'on',
!              'expectedValue':False,
!             },
!         },
!     'BlindGap': {
!         'BlindGap1':
              {'typ':'BlindGapAnswer', \
               'param':\
***************
*** 112,116 ****
               'inValue':'i want a hirsch-schnitzel', \
               'expectedValue':False,\
!             }, \
              {'typ':'BlindGapAnswer', \
               'param':\
--- 81,86 ----
               'inValue':'i want a hirsch-schnitzel', \
               'expectedValue':False,\
!             },
!         'BlindGap2':
              {'typ':'BlindGapAnswer', \
               'param':\
***************
*** 120,124 ****
               'inValue':'i want a hirsch-schnitzel', \
               'expectedValue':True,\
!             }, \
              {'typ':'BlindGapAnswer', \
               'param':\
--- 90,95 ----
               'inValue':'i want a hirsch-schnitzel', \
               'expectedValue':True,\
!             },
!         'BlindGap3':
              {'typ':'BlindGapAnswer', \
               'param':\
***************
*** 128,132 ****
               'inValue':'Brutzel', \
               'expectedValue':False,\
!             }, \
              {'typ':'BlindGapAnswer', \
               'param':\
--- 99,104 ----
               'inValue':'Brutzel', \
               'expectedValue':False,\
!             },
!         'BlindGap4':
              {'typ':'BlindGapAnswer', \
               'param':\
***************
*** 137,148 ****
               'expectedValue':True,\
              }, \
!         )
!         
!         self.runAnswerTest(testValues)
!         
!  
!     def testTextTaskAnswer(self):           
! 
!         testValues=(            
              {'typ':'TextTaskAnswer', \
               'param':\
--- 109,115 ----
               'expectedValue':True,\
              }, \
!         },
!     'TextTask':{
!         'TextTask1':
              {'typ':'TextTaskAnswer', \
               'param':\
***************
*** 153,156 ****
--- 120,124 ----
               'expectedValue':True,\
              }, \
+         'TextTask2':
              {'typ':'TextTaskAnswer', \
               'param':\
***************
*** 160,164 ****
               'inValue':'schnitzel', \
               'expectedValue':False,\
!             }, \
              {'typ':'TextTaskAnswer', \
               'param':\
--- 128,133 ----
               'inValue':'schnitzel', \
               'expectedValue':False,\
!             },
!         'TextTask3':
              {'typ':'TextTaskAnswer', \
               'param':\
***************
*** 169,179 ****
               'expectedValue':False,\
              }, \
!         )
!         
!         self.runAnswerTest(testValues)
!             
!     def testChoiceGapAnswer(self):           
! 
!         testValues=(            
              {'typ':'ChoiceGapAnswer', \
               'param':\
--- 138,144 ----
               'expectedValue':False,\
              }, \
!         },
!     'ChoiceGap':{
!         'ChoiceGap1':
              {'typ':'ChoiceGapAnswer', \
               'param':\
***************
*** 182,186 ****
               'inValue':'Schnitzel', \
               'expectedValue':True,\
!             }, \
              {'typ':'ChoiceGapAnswer', \
               'param':\
--- 147,152 ----
               'inValue':'Schnitzel', \
               'expectedValue':True,\
!             },
!         'ChoiceGap2':
              {'typ':'ChoiceGapAnswer', \
               'param':\
***************
*** 190,200 ****
               'expectedValue':False,\
              }, \
!         )
!         
!         self.runAnswerTest(testValues)
!             
!     def testMatchingAnswer(self):           
! 
!         testValues=(            
              {'typ':'MatchingAnswer', \
               'param':\
--- 156,162 ----
               'expectedValue':False,\
              }, \
!         },
!     'Matching':{
!         'Matching1':
              {'typ':'MatchingAnswer', \
               'param':\
***************
*** 203,207 ****
               'inValue':'Schnitzel', \
               'expectedValue':True,\
!             }, \
              {'typ':'MatchingAnswer', \
               'param':\
--- 165,170 ----
               'inValue':'Schnitzel', \
               'expectedValue':True,\
!             },
!         'Matching2':
              {'typ':'MatchingAnswer', \
               'param':\
***************
*** 211,222 ****
               'expectedValue':False,\
              }, \
!         )
!         
!         self.runAnswerTest(testValues)
!                  
! 
!     def testMathAnswer(self):           
! 
!         testValues=(            
              {'typ':'MathAnswer', \
               'param':\
--- 174,180 ----
               'expectedValue':False,\
              }, \
!         },
!     'Math': {
!         'Math1':
              {'typ':'MathAnswer', \
               'param':\
***************
*** 225,229 ****
               'inValue':5, \
               'expectedValue':False,\
!             }, \
              {'typ':'MathAnswer', \
               'param':\
--- 183,188 ----
               'inValue':5, \
               'expectedValue':False,\
!             },
!         'Math2':
              {'typ':'MathAnswer', \
               'param':\
***************
*** 232,236 ****
               'inValue':9, \
               'expectedValue':True,\
!             }, \
              {'typ':'MathAnswer', \
               'param':\
--- 191,196 ----
               'inValue':9, \
               'expectedValue':True,\
!             },
!         'Math3':
              {'typ':'MathAnswer', \
               'param':\
***************
*** 240,263 ****
               'expectedValue':True,\
              }, \
!         )
!         
          self.runAnswerTest(testValues)
-             
  
!     def runAnswerTest(self, testValues):        
          self.loginPortalOwner()
!         for o in testValues:
!             self.portal.invokeFactory(o['typ'], 'TestObject')
!             obj=self.portal.TestObject
!             for p in o['param'].keys():
!                 mut=obj.getField(p).getMutator(obj)
!                 mut(o['param'][p])
!             
              #testing:
!             r=obj.processValue(o['inValue'])
!             self.failUnless(r==o['expectedValue'])
!             
!             self.portal.manage_delObjects(['TestObject'])
!             
  
  def test_suite():
--- 200,263 ----
               'expectedValue':True,\
              }, \
!         }
! }
! 
! class TestAnswers(PloneTestCase.PloneTestCase):
! 
!     def afterSetUp(self):
! 
!         common.installWithinPortal(self.portal)
! 
!         qtypes = getAnswerTypes()
!         tt = self.portal.portal_types
!         for t in qtypes:
!             ti=tt[qtypes[t].meta_type]
!             ti.global_allow=True
! 
!     def testTrueFalseAnswer(self):
!         testValues=alltestvalues['TrueFalse']
          self.runAnswerTest(testValues)
  
!     def testSingleChoiceAnswer(self):
!         testValues=alltestvalues['SingleChoice']
!         self.runAnswerTest(testValues)
! 
!     def testMultipleChoiceAnswer(self):
!         testValues=alltestvalues['MultipleChoice']
!         self.runAnswerTest(testValues)
! 
!     def testBlindGapAnswer(self):
!         testValues=alltestvalues['BlindGap']
!         self.runAnswerTest(testValues)
! 
!     def testTextTaskAnswer(self):
! 
!         testValues=alltestvalues['TextTask']
!         self.runAnswerTest(testValues)
! 
!     def testChoiceGapAnswer(self):
!         testValues=alltestvalues['ChoiceGap']
!         self.runAnswerTest(testValues)
! 
!     def testMatchingAnswer(self):
!         testValues=alltestvalues['Matching']
!         self.runAnswerTest(testValues)
! 
!     def testMathAnswer(self):
!         testValues=alltestvalues['Math']
!         self.runAnswerTest(testValues)
! 
!     def runAnswerTest(self, testValues):
          self.loginPortalOwner()
!         for answerkey in testValues:
!             self.portal.invokeFactory(testValues[answerkey]['typ'], answerkey)
!             answer=self.portal[answerkey]
!             for field in testValues[answerkey]['param']:
!                 mut=answer.getField(field).getMutator(answer)
!                 mut(testValues[answerkey]['param'][field])
! 
              #testing:
!             r=answer.processValue(testValues[answerkey]['inValue'])
!             self.failUnless(r==testValues[answerkey]['expectedValue'])
  
  def test_suite():



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.