Beispiel #1
0
 def test_create_and_save(self):
   cat_test = CatTest()
   cat_test.name = "short"
   cat_test.save()
   user = User.objects.create_user('john', '*****@*****.**', 'johnpassword')
   user.save()
   domain = Domain()
   domain.name = "Number"
   domain.create_date = datetime.datetime(2012,03,06)
   domain.save()
   item_bank = ItemBank()
   item_bank.name = "Fractions"
   item_bank.topic = "Addition"
   item_bank.domain = domain
   item_bank.question_type = QuestionType.objects.get(pk=1)
   item_bank.template = ItemBankTemplate.objects.get(pk=1)
   item_bank.save()
   user_item_bank = UserItemBank()
   user_item_bank.user = user
   user_item_bank.item_bank = item_bank
   user_item_bank.save()
   user_cat_test = UserCatTest()
   user_cat_test.user = user
   user_cat_test.item_bank = item_bank
   user_cat_test.cat_test = cat_test
   user_cat_test.time_taken = 12      
   user_cat_test.save()
   uct = UserCatTest.objects.all()[0]
   self.assertEquals(uct.user,user)
   self.assertEquals(uct.item_bank,item_bank)
   self.assertEquals(uct.cat_test,cat_test)
   self.assertEquals(uct.time_taken,12)
Beispiel #2
0
 def test_start_old_cat_view(self):
   #test that if a user has done more than one test the right one is being updated           
   user = User.objects.create_user('john', '*****@*****.**', 'johnpassword')
   user.save()
   self.client.login(username='******', password='******')
   #create structures
   cat_test = CatTest()
   cat_test.name = "Short Test"
   cat_test.save()
   domain = Domain.objects.get(pk=1)
   item_bank = ItemBank()
   item_bank.question_type = QuestionType.objects.get(pk=1)
   item_bank.name = "Fractions"
   item_bank.topic = "Addition"
   item_bank.domain = domain
   item_bank.template = ItemBankTemplate.objects.get(pk=1)
   item_bank.save()
   user_item_bank = UserItemBank()
   user_item_bank.user = user
   user_item_bank.item_bank = item_bank
   user_item_bank.save()
   user_cat_test = UserCatTest()
   user_cat_test.user = user
   user_cat_test.item_bank = item_bank
   user_cat_test.cat_test = cat_test
   user_cat_test.items = 6
   user_cat_test.save()
   user_cat_test = UserCatTest()
   response = self.client.get('/start/', {'item_bank_id': item_bank.id, 'cat_test_id':cat_test.id})
   ucts = UserCatTest.objects.filter(user=user)
   self.assertEquals(len(ucts),2)
   ucts = ucts.order_by('-id')
   self.assertEquals(ucts[0].items,0)
Beispiel #3
0
 def test_user_item_bank_link(self):
     user = User.objects.create_user("john", "*****@*****.**", "johnpassword")
     user.save()
     domain = Domain()
     domain.name = "Number"
     domain.create_date = datetime.datetime(2012, 03, 06)
     domain.save()
     item_bank = ItemBank()
     item_bank.name = "Fractions"
     item_bank.topic = "Addition"
     item_bank.domain = domain
     item_bank.create_date = datetime.datetime(2012, 03, 06)
     item_bank.save()
     item_bank = ItemBank()
     item_bank.name = "Fractions"
     item_bank.topic = "Subtraction"
     item_bank.domain = domain
     item_bank.create_date = datetime.datetime(2012, 03, 06)
     item_bank.save()
     user_item_bank = UserItemBank()
     user_item_bank.user = user
     user_item_bank.item_bank = item_bank
     user_item_bank.save()
     uibs = UserItemBank.objects.all()[0]
     self.assertEqual(uibs.item_bank, item_bank)
     self.assertEqual(uibs.user, user)
     item_banks = ItemBank.objects.filter(useritembank__user=user)
     self.assertEqual(len(item_banks), 1)
Beispiel #4
0
 def test_create_and_save(self):
     user = User.objects.create_user("john", "*****@*****.**", "johnpassword")
     user.save()
     domain = Domain.objects.get(name="Number")
     item_bank = ItemBank()
     item_bank.name = "Fractions"
     item_bank.topic = "Addition"
     item_bank.domain = domain
     item_bank.question_type = QuestionType.objects.get(pk=1)
     item_bank.template = ItemBankTemplate.objects.get(pk=1)
     item_bank.save()
     user_item_bank = UserItemBank()
     user_item_bank.user = user
     user_item_bank.item_bank = item_bank
     user_item_bank.save()
     grd = Grade.objects.get(name="A")
     thresh = Threshold()
     thresh.grade = grd
     thresh.item_bank = item_bank
     thresh.ability = -1
     thresh.save()
     probs = UserItemBankProbabilities()
     probs.user_item_bank = user_item_bank
     probs.threshold = thresh
     probs.probability = 50
     probs.save()
     probs = UserItemBankProbabilities.objects.all()[0]
     self.assertEquals(probs.probability, 50)
Beispiel #5
0
 def test_create_and_save(self):
     cat_test = CatTest()
     cat_test.name = "short"
     cat_test.save()
     user = User.objects.create_user("john", "*****@*****.**", "johnpassword")
     user.save()
     domain = Domain()
     domain.name = "Number"
     domain.create_date = datetime.datetime(2012, 03, 06)
     domain.save()
     item_bank = ItemBank()
     item_bank.name = "Fractions"
     item_bank.topic = "Addition"
     item_bank.domain = domain
     item_bank.create_date = datetime.datetime(2012, 03, 06)
     item_bank.save()
     user_item_bank = UserItemBank()
     user_item_bank.user = user
     user_item_bank.item_bank = item_bank
     user_item_bank.save()
     user_cat_test = UserCatTest()
     user_cat_test.user = user
     user_cat_test.item_bank = item_bank
     user_cat_test.cat_test = cat_test
     user_cat_test.save()
     uct = UserCatTest.objects.all()[0]
     self.assertEquals(uct.user, user)
     self.assertEquals(uct.item_bank, item_bank)
     self.assertEquals(uct.cat_test, cat_test)
Beispiel #6
0
 def test_start_test_view(self):
   user = User.objects.create_user('john', '*****@*****.**', 'johnpassword')
   user.save()
   self.client.login(username='******', password='******')
   #create structures
   cat_test = CatTest()
   cat_test.name = "Short Test"
   cat_test.save()
   domain = Domain.objects.get(pk=1)
   item_bank = ItemBank()
   item_bank.name = "Fractions"
   item_bank.topic = "Addition"
   item_bank.domain = domain
   item_bank.question_type = QuestionType.objects.get(pk=1)
   item_bank.template = ItemBankTemplate.objects.get(pk=1)
   item_bank.save()
   user_item_bank = UserItemBank()
   user_item_bank.user = user
   user_item_bank.item_bank = item_bank
   user_item_bank.save()
   response = self.client.get('/start/', {'item_bank_id': item_bank.id, 'cat_test_id':cat_test.id})
   #Test that page exists
   self.assertEqual(response.status_code, 200)
   #Test that is has been rendered with a template
   self.assertTemplateUsed(response, 'start_test.html')
   #Test that it displays item bank name and cat_test name
   self.assertIn('Fractions',response.content)
   self.assertIn('Addition',response.content)
   self.assertIn('Short Test',response.content)
   self.assertIn('4', response.content)
   self.assertIn('10', response.content)
Beispiel #7
0
 def test_endTest(self):
   cat_test = CatTest()
   cat_test.name = "short"
   cat_test.max_items = 10
   cat_test.save()
   user = User.objects.create_user('john', '*****@*****.**', 'johnpassword')
   user.save()
   domain = Domain()
   domain.name = "Number"
   domain.create_date = datetime.datetime(2012,03,06)
   domain.save()
   item_bank = ItemBank()
   item_bank.name = "Fractions"
   item_bank.topic = "Addition"
   item_bank.domain = domain
   item_bank.question_type = QuestionType.objects.get(pk=1)
   item_bank.template = ItemBankTemplate.objects.get(pk=1)
   item_bank.save()
   user_item_bank = UserItemBank()
   user_item_bank.user = user
   user_item_bank.item_bank = item_bank
   user_item_bank.save()
   ibq = ItemBankQuestion()
   ibq.item_bank = item_bank
   ibq.save()
   user_cat_test = UserCatTest()
   user_cat_test.user = user
   user_cat_test.item_bank = item_bank
   user_cat_test.cat_test = cat_test
   user_cat_test.items = 10
   user_cat_test.save()
   end_test = user_cat_test.endTest()
   self.assertEquals(end_test,True)
   user_cat_test.items = 9
   user_cat_test.save()
   end_test = user_cat_test.endTest()
   self.assertEquals(end_test,False)
   user_cat_test.items = 5
   user_cat_test.stand_dev = 0.1
   user_cat_test.save()
   end_test = user_cat_test.endTest()
   self.assertEquals(end_test,True)
   user_cat_test.items = 5
   user_cat_test.stand_dev = 2
   user_cat_test.save()
   end_test = user_cat_test.endTest()
   self.assertEquals(end_test,False)
   user_cat_test.items = 2
   user_cat_test.stand_dev = 0.1
   user_cat_test.save()
   end_test = user_cat_test.endTest()
   self.assertEquals(end_test,False)
Beispiel #8
0
 def test_user_item_bank_probabilities(self):
     user = User.objects.create_user("john", "*****@*****.**", "johnpassword")
     user.save()
     domain = Domain.objects.get(pk=1)
     item_bank = ItemBank()
     item_bank.name = "Fractions"
     item_bank.topic = "Addition"
     item_bank.domain = domain
     item_bank.template = ItemBankTemplate.objects.get(pk=1)
     item_bank.question_type = QuestionType.objects.get(pk=1)
     item_bank.save()
     user_item_bank = UserItemBank()
     user_item_bank.user = user
     user_item_bank.item_bank = item_bank
     user_item_bank.save()
     grd = Grade.objects.get(name="A")
     thresh = Threshold()
     thresh.grade = grd
     thresh.item_bank = item_bank
     thresh.ability = -1
     thresh.save()
     user_item_bank.probabilities()
     probs = UserItemBankProbabilities.objects.all()
     self.assertEquals(len(probs), 1)
     # Get threshold probabilities
     user_item_banks = UserItemBank.objects.filter(user=user)
     for user_item_bank in user_item_banks:
         threshes = user_item_bank.useritembankprobabilities_set.all()
         self.assertEquals(len(threshes), 1)
Beispiel #9
0
 def test_create_and_save(self):
   cat_test = CatTest()
   cat_test.name = "short"
   cat_test.save()
   user = User.objects.create_user('john', '*****@*****.**', 'johnpassword')
   user.save()
   domain = Domain()
   domain.name = "Number"
   domain.create_date = datetime.datetime(2012,03,06)
   domain.save()
   item_bank = ItemBank()
   item_bank.name = "Fractions"
   item_bank.topic = "Addition"
   item_bank.domain = domain
   item_bank.question_type = QuestionType.objects.get(pk=1)
   item_bank.template = ItemBankTemplate.objects.get(pk=1)
   item_bank.save()
   user_item_bank = UserItemBank()
   user_item_bank.user = user
   user_item_bank.item_bank = item_bank
   user_item_bank.save()
   ibq = ItemBankQuestion()
   ibq.item_bank = item_bank
   ibq.save()
   user_cat_test = UserCatTest()
   user_cat_test.user = user
   user_cat_test.item_bank = item_bank
   user_cat_test.cat_test = cat_test
   user_cat_test.save()
   cat_test_item = CatTestItem()
   cat_test_item.user_cat_test = user_cat_test
   cat_test_item.item_bank_question = ibq
   cat_test_item.time_taken = 12
   cat_test_item.save()
   answer = FractionWithConstant()
   answer.const = 1
   answer.denom = 2
   answer.num = 3
   answer.save()
   ctifa = CatTestItemFractionAnswer()
   ctifa.cat_test_item = cat_test_item
   ctifa.fraction = answer
   ctifa.save()
   ctifa = CatTestItemFractionAnswer.objects.filter(cat_test_item = cat_test_item)[0]
   self.assertEquals(ctifa.fraction,answer)
Beispiel #10
0
    def test_user_item_bank_update(self):
        user = User.objects.create_user("john", "*****@*****.**", "johnpassword")
        user.save()

        # create structures
        cat_test = CatTest()
        cat_test.name = "Short Test"
        cat_test.save()
        domain = Domain.objects.get(pk=1)
        item_bank = ItemBank()
        item_bank.name = "Fractions"
        item_bank.topic = "Addition"
        item_bank.domain = domain
        item_bank.template = ItemBankTemplate.objects.get(pk=1)
        item_bank.question_type = QuestionType.objects.get(pk=1)
        item_bank.save()
        user_item_bank = UserItemBank()
        user_item_bank.user = user
        user_item_bank.item_bank = item_bank
        user_item_bank.save()
        user_cat_test = UserCatTest()
        user_cat_test.user = user
        user_cat_test.item_bank = item_bank
        user_cat_test.cat_test = cat_test
        user_cat_test.items = 6
        user_cat_test.right = 4
        user_cat_test.time_taken = 240
        user_cat_test.save()
        user_item_bank.update(user_cat_test)
        self.assertEquals(user_item_bank.tests, 1)
        self.assertEquals(user_item_bank.questions, 6)
        self.assertEquals(user_item_bank.correct, 4)
        self.assertEquals(user_item_bank.time_taken, 240)
        self.assertEquals(user_item_bank.time_taken_str, "0:04:00")
Beispiel #11
0
    def test_simAbility(self):
      cat_test = CatTest()
      cat_test.name = "short"
      cat_test.max_items = 10
      cat_test.save()
      user = User.objects.create_user('john', '*****@*****.**', 'johnpassword')
      user.save()
      domain = Domain()
      domain.name = "Number"
      domain.create_date = datetime.datetime(2012,03,06)
      domain.save()
      item_bank = ItemBank()
      item_bank.name = "Fractions"
      item_bank.topic = "Addition"
      item_bank.domain = domain
      item_bank.question_type = QuestionType.objects.get(pk=1)
      item_bank.template = ItemBankTemplate.objects.get(pk=1)
      item_bank.save()
      user_item_bank = UserItemBank()
      user_item_bank.user = user
      user_item_bank.item_bank = item_bank
      user_item_bank.save()
      grd = Grade.objects.get(name="A")
      thresh = Threshold()
      thresh.grade = grd
      thresh.item_bank = item_bank
      thresh.ability = -1      
      thresh.save()
      user_item_bank.probabilities()      
      probs = UserItemBankProbabilities.objects.filter(user_item_bank=user_item_bank)
      self.assertEquals(len(probs),1)
      ibq = ItemBankQuestion()
      ibq.item_bank = item_bank
      ibq.save()
      user_cat_test = UserCatTest()
      user_cat_test.user = user
      user_cat_test.item_bank = item_bank
      user_cat_test.cat_test = cat_test
      user_cat_test.save()
      #Make three questions
      for i in range(1,4):
        ibq = ItemBankQuestion()
        ibq.item_bank = item_bank
        ibq.save()
      #Find first question
      user_cat_test.nextQuestion()      
      user_cat_test.simAbility()
      self.assertEquals(round(user_cat_test.ability,3),-0.337)
      self.assertEquals(round(user_cat_test.stand_dev,3),0.885)
      probs = UserItemBankProbabilities.objects.filter(user_item_bank=user_item_bank)[0]
      self.assertEquals(round(probs.probability,0),77.0)	  

      user_cat_test.nextQuestion()      
      user_cat_test.simAbility()
      self.assertEquals(round(user_cat_test.ability,3),-0.813)
      self.assertEquals(round(user_cat_test.stand_dev,3),0.829)      
Beispiel #12
0
 def test_user_item_bank_link_with_start_view(self):  
   
   #Test that link goes to start with query string picked up
   user = User.objects.create_user('john', '*****@*****.**', 'johnpassword')
   user.save()
   domain = Domain.objects.get(name="Number")
   item_bank = ItemBank()
   item_bank.name = "Fractions"
   item_bank.topic = "Addition"
   item_bank.domain = domain
   item_bank.question_type = QuestionType.objects.get(pk=1)
   item_bank.template = ItemBankTemplate.objects.get(pk=1)
   item_bank.save()
   user_item_bank = UserItemBank()
   user_item_bank.user = user
   user_item_bank.item_bank = item_bank
   user_item_bank.save()        
   self.client.login(username='******', password='******')
   response = self.client.get('/start/', {'item_bank_id': '1', 'cat_test_id': '1'})
   self.assertIn('Fractions',response.content)
   self.assertIn('Short Test',response.content)
Beispiel #13
0
    def test_user_item_bank_view(self):
        user = User.objects.create_user("john", "*****@*****.**", "johnpassword")
        user.first_name = "John"
        user.last_name = "Lennon"
        user.save()
        self.client = Client()
        response = self.client.get(ROOT + "/accounts/login/")

        # Set up two item banks and associate with user
        user = User.objects.get(pk=1)
        domain = Domain.objects.get(name="Number")
        item_bank = ItemBank()
        item_bank.name = "Fractions"
        item_bank.topic = "Addition"
        item_bank.domain = domain
        item_bank.save()
        user_item_bank = UserItemBank()
        user_item_bank.user = user
        user_item_bank.item_bank = item_bank
        user_item_bank.save()

        item_bank = ItemBank()
        item_bank.name = "Fractions"
        item_bank.topic = "Subtraction"
        item_bank.domain = domain
        item_bank.save()
        user_item_bank = UserItemBank()
        user_item_bank.user = user
        user_item_bank.item_bank = item_bank
        user_item_bank.save()

        # log in
        response = self.client.post(ROOT + "/accounts/login/", {"username": "******", "password": "******"})

        response = self.client.get(ROOT + "/welcome/")
        self.assertIn("Domain", response.content)
        self.assertIn("Fractions", response.content)
        self.assertIn("Addition", response.content)
        # Test user banks are there
        self.assertEqual(len(response.context["user_banks"]), 2)
Beispiel #14
0
 def test__login_details(self):
     user = User.objects.create_user("john", "*****@*****.**", "johnpassword")
     user.save()
     domain = Domain()
     domain.name = "Number"
     domain.create_date = datetime.datetime(2012, 03, 06)
     domain.save()
     item_bank = ItemBank()
     item_bank.name = "Fractions"
     item_bank.topic = "Addition"
     item_bank.domain = domain
     item_bank.create_date = datetime.datetime(2012, 03, 06)
     item_bank.save()
     user_item_bank = UserItemBank()
     user_item_bank.user = user
     user_item_bank.item_bank = item_bank
     user_item_bank.save()
     client = Client()
     client.login(username="******", password="******")
     response = client.get("/welcome/")
     self.assertEqual(response.templates[0].name, "user_item_banks.html")
     n = len(UserItemBank.objects.filter(user=user))
     self.assertEqual(len(response.context["user_banks"]), n)
Beispiel #15
0
 def test__login_details(self):
     user = User.objects.create_user('john', '*****@*****.**', 'johnpassword')
     user.save()
     domain = Domain()
     domain.name = "Number"
     domain.create_date = datetime.datetime(2012,03,06)
     domain.save()
     item_bank = ItemBank()
     item_bank.name = "Fractions"
     item_bank.topic = "Addition"
     item_bank.domain = domain
     item_bank.question_type = QuestionType.objects.get(pk=1)
     item_bank.template = ItemBankTemplate.objects.get(pk=1)
     item_bank.save()
     user_item_bank = UserItemBank()
     user_item_bank.user = user
     user_item_bank.item_bank = item_bank
     user_item_bank.save()        
     client = Client()
     client.login(username='******', password='******')
     response = client.get('/welcome/')         
     self.assertEqual(response.templates[0].name, 'user_item_banks.html')
     n = len(UserItemBank.objects.filter(user=user))
     self.assertEqual(len(response.context['user_banks']), n)       
Beispiel #16
0
          def test_display_user_cat_test(self):
            #Test the post functionality of the question view         
            user = User.objects.create_user('john', '*****@*****.**', 'johnpassword')
            user.save()
            self.client.login(username='******', password='******')
            
            #create structures
            cat_test = CatTest()
            cat_test.name = "Short Test"
            cat_test.save()
            domain = Domain.objects.get(pk=1)
            item_bank = ItemBank()
            item_bank.name = "Fractions"
            item_bank.topic = "Addition"
            item_bank.domain = domain
            item_bank.template = ItemBankTemplate.objects.get(pk=1)
            item_bank.question_type = QuestionType.objects.get(pk=1)
            item_bank.save()
            user_item_bank = UserItemBank()
            user_item_bank.user = user
            user_item_bank.item_bank = item_bank
            user_item_bank.save()
			#Create a threshold
            grd = Grade.objects.get(name="A")
            thresh = Threshold()
            thresh.grade = grd
            thresh.item_bank = item_bank
            thresh.ability = -1
            thresh.init_prob =50			
            thresh.save()
            user_item_bank.probabilities()
            user_cat_test = UserCatTest()
            user_cat_test.user = user
            user_cat_test.item_bank = item_bank
            user_cat_test.cat_test = cat_test
            user_cat_test.save()
            response = self.client.get('/end/')
            self.assertIn('Ability: 0',response.content)
            user_item_bank = UserItemBank.objects.get(pk=1)
            self.assertEqual(user_item_bank.tests,1)
            #Should show probabilities
            self.assertIn('50%',response.content)
Beispiel #17
0
 def test_feedback(self):
   #Test the post functionality of the question view         
   user = User.objects.create_user('john', '*****@*****.**', 'johnpassword')
   user.save()
   self.client.login(username='******', password='******')
   
   #create structures
   cat_test = CatTest()
   cat_test.name = "Short Test"
   cat_test.save()
   domain = Domain.objects.get(pk=1)
   item_bank = ItemBank()
   item_bank.name = "Fractions"
   item_bank.topic = "Addition"
   item_bank.domain = domain
   item_bank.template = ItemBankTemplate.objects.get(pk=1)
   item_bank.question_type = QuestionType.objects.get(pk=1)
   item_bank.save()
   user_item_bank = UserItemBank()
   user_item_bank.user = user
   user_item_bank.item_bank = item_bank
   user_item_bank.save()
   #Create a threshold
   grd = Grade.objects.get(name="A")
   thresh = Threshold()
   thresh.grade = grd
   thresh.item_bank = item_bank
   thresh.ability = -1      
   thresh.save()
   
   user_item_bank.probabilities()
   user_cat_test = UserCatTest()
   user_cat_test.user = user
   user_cat_test.item_bank = item_bank
   user_cat_test.cat_test = cat_test
   user_cat_test.save()
   
   #Give the test some questions
   #Create fraction question bank
   fqb = FractionQuestionBank()
   oper = Oper.objects.get(pk=1)
   n = 20
   st = 0
   en = 10
   name = "Test Bank"
   negatives_allowed = True
   fqb.generate(name,st,en,negatives_allowed,oper,n)
   #Fill item bank from fraction question bank
   item_bank.fill(fqb,"fractions")
   user_cat_test = UserCatTest()
   user_cat_test.user = user
   user_cat_test.item_bank = item_bank
   user_cat_test.cat_test = cat_test
   user_cat_test.save()
   cat_test_item = user_cat_test.nextQuestion()
   #Correct answer to question
   ibfq = ItemBankFractionQuestion.objects.filter(item_bank_question=cat_test_item.item_bank_question)
   answer = ibfq[0].fraction_bank_question.question.answer
   #Test post triggers marking process
   response = self.client.post('/question/', {'const': answer.const+1, 'num': answer.num+1, 'denom': answer.denom+1, 'time': 12})
   print answer.const, answer.num, answer.denom
   response = self.client.get('/feedback/')
   #First question right
   #Should say right or wrong
   self.assertIn('Wrong!',response.content)
   #Should give user's answer
   self.assertIn(str(answer.const+1),response.content)
   #Should give user's answer
   self.assertIn(str(answer.num+1),response.content)
   #Should give user's answer
   self.assertIn(str(answer.denom+1),response.content)
   #Should give right answer
   self.assertIn(str(answer.const),response.content)
   self.assertIn(str(answer.num),response.content)
   self.assertIn(str(answer.denom),response.content)
   #Should show user's time
   self.assertIn('12',response.content)
   #Should show probabilities
   self.assertIn('%',response.content)            
Beispiel #18
0
 def test_user_item_bank_view(self):
   user = User.objects.create_user('john', '*****@*****.**', 'johnpassword')
   user.first_name = "John"
   user.last_name = "Lennon"
   user.save()
   self.client = Client()
   response = self.client.get(ROOT + '/accounts/login/')
   #Set up a default cat_test type
   cat_test = CatTest.objects.get(pk=1)
   
   #Set up two item banks and associate with user
   user = User.objects.get(pk=1) 
   domain = Domain.objects.get(name="Number")
   item_bank = ItemBank()
   item_bank.name = "Fractions"
   item_bank.topic = "Addition"
   item_bank.domain = domain
   item_bank.question_type = QuestionType.objects.get(pk=1)
   item_bank.template = ItemBankTemplate.objects.get(pk=1)
   item_bank.save()
   user_item_bank = UserItemBank()
   user_item_bank.user = user
   user_item_bank.item_bank = item_bank
   user_item_bank.save()
   
   #add threshold
   grd = Grade.objects.get(name="C")
   thresh = Threshold()
   thresh.grade = grd
   thresh.item_bank = item_bank
   thresh.ability = 0      
   thresh.save()
   #add user probabilities
   user_item_bank.probabilities() 
   
   item_bank = ItemBank()
   item_bank.name = "Fractions"
   item_bank.topic = "Subtraction"
   item_bank.domain = domain
   item_bank.question_type = QuestionType.objects.get(pk=1)
   item_bank.template = ItemBankTemplate.objects.get(pk=1)
   item_bank.save()
   user_item_bank = UserItemBank()
   user_item_bank.user = user
   user_item_bank.item_bank = item_bank
   user_item_bank.save()
   #add threshold
   grd = Grade.objects.get(name="C")
   thresh = Threshold()
   thresh.grade = grd
   thresh.item_bank = item_bank
   thresh.ability = 0      
   thresh.save()
   #add user probabilities
   user_item_bank.probabilities()                    
   
   #log in
   response = self.client.post(ROOT + '/accounts/login/', {'username': '******', 'password': '******'})
   
   response = self.client.get(ROOT + '/welcome/')
   self.assertIn('Domain', response.content)
   self.assertIn('Fractions', response.content)
   self.assertIn('Addition', response.content)
   
   #Test threshold probababities are there          
   self.assertIn('C', response.content)
   self.assertIn('50%', response.content)
   #Test user banks are there
   self.assertEqual(len(response.context['user_banks']), 2)  
   #Test there are links to start a test
   self.assertIn('/start/?item_bank_id=1&cat_test_id=1', response.content)
Beispiel #19
0
UserItemBank.objects.all().delete()
FractionQuestionBank.objects.all().delete()
Threshold.objects.all().delete()
UserItemBankProbabilities.objects.all().delete()

#Set up an item bank and associate with user
user = User.objects.get(username="******") 
domain = Domain.objects.get(name="Number")
item_bank = ItemBank()
item_bank.name = "Fractions"
item_bank.topic = "Addition"
item_bank.domain = domain
item_bank.template = ItemBankTemplate.objects.get(pk=1)
item_bank.question_type = QuestionType.objects.get(pk=1)
item_bank.save()
user_item_bank = UserItemBank()
user_item_bank.user = user
user_item_bank.item_bank = item_bank
user_item_bank.save()

#Set thresholds
grd = Grade.objects.get(name="A")
thresh = Threshold()
thresh.grade = grd
thresh.item_bank = item_bank
thresh.ability = 1      
thresh.save()
grd = Grade.objects.get(name="C")
thresh = Threshold()
thresh.grade = grd
thresh.item_bank = item_bank
Beispiel #20
0
    def test_can_create_new_centre_via_admin_site(self):
      print("test_can_create_new_centre_via_admin_site")    
      #Admin logs in
      # Gertrude opens her web browser, and goes to the admin page
      self.browser.get(ROOT + '/admin/')

      # She sees the familiar 'Django administration' heading
      body = self.browser.find_element_by_tag_name('body')
      self.assertIn('Django administration', body.text)
      
      # She types in her username and passwords and hits return
      username_field = self.browser.find_element_by_name('username')
      username_field.send_keys('admin')

      password_field = self.browser.find_element_by_name('password')
      password_field.send_keys('adm1n')
      password_field.send_keys(Keys.RETURN)
      #print out what you see
      body = self.browser.find_element_by_tag_name('body')
      self.assertIn('Welcome', body.text)
      #She sees a hyperlink that says "Centres"
      links = self.browser.find_elements_by_link_text('Centres')
      self.assertEquals(len(links), 2)
      #Clicks it
      links[1].click()
      #Selects add link
      add_link = self.browser.find_elements_by_link_text('Add centre')
      add_link[0].click()
      #Fill in name, centre_id and create date and hit submit
      name_field = self.browser.find_element_by_name('name')
      name_field.send_keys('Test Centre')
      centre_id_field = self.browser.find_element_by_name('centre_id')
      centre_id_field.send_keys('60114') 
      date_field = self.browser.find_element_by_name('create_date_0')
      date_field.send_keys('2012-03-05')
      time_field = self.browser.find_element_by_name('create_date_1')
      time_field.send_keys('10:25:12')
      date_field.send_keys(Keys.RETURN)
      #Centre is saved and centre_id and name is displayed
      body = self.browser.find_element_by_tag_name('body')
      #returns to home page
      self.assertIn('60114 Test Centre', body.text)
      links = self.browser.find_elements_by_link_text('Home')
      links[0].click()
      #Clicks on user
      links = self.browser.find_elements_by_link_text('Users')
      links[0].click()
      
      #Clicks on Add user
      links = self.browser.find_elements_by_link_text('Add user')
      links[0].click()
      name_field = self.browser.find_element_by_name('username')
      name_field.send_keys('JRotten')
      name_field = self.browser.find_element_by_name('password1')
      name_field.send_keys('password')
      name_field = self.browser.find_element_by_name('password2')
      name_field.send_keys('password')
      name_field.send_keys(Keys.RETURN)
      body = self.browser.find_element_by_tag_name('body')
      self.assertIn('The user "JRotten" was added successfully', body.text)
      
      name_field = self.browser.find_element_by_name('first_name')
      name_field.send_keys('Johnny')
      name_field = self.browser.find_element_by_name('last_name')
      name_field.send_keys('Rotten')
      name_field.send_keys(Keys.RETURN)
      links = self.browser.find_elements_by_link_text('Home')
      links[0].click()
      
      #She sees a hyperlink that says "Candidates"
      links = self.browser.find_elements_by_link_text('Candidates')
      self.assertEquals(len(links), 1)
      #Clicks it
      links[0].click()
      #Selects add link
      body = self.browser.find_element_by_tag_name('body')
      
      add_link = self.browser.find_elements_by_link_text('Add candidate')
      add_link[0].click()
      #Fill in gender, dob, centre, user and hit submit
      name_field = self.browser.find_element_by_name('gender')
      name_field.send_keys('M')
      dob_field = self.browser.find_element_by_name('dob')
      dob_field.send_keys('1969-05-01')
      
      select = self.browser.find_elements_by_tag_name("select")
      allOptions = select[0].find_elements_by_tag_name("option")   
      for option in allOptions:
        print "Value is: " + option.get_attribute("value")
        option.click()
      
      allOptions = select[1].find_elements_by_tag_name("option")   
      for option in allOptions:
        print "Value is: " + option.get_attribute("value")
        option.click()
        
      dob_field.send_keys(Keys.RETURN)
      #Candidate is saved and name is displayed
      body = self.browser.find_element_by_tag_name('body')
      self.assertIn('The candidate "Johnny Rotten" was added successfully.', body.text)
      
      #Set up an item bank and associate with user
      user = User.objects.get(username="******") 
      domain = Domain.objects.get(name="Number")
      item_bank = ItemBank()
      item_bank.name = "Fractions"
      item_bank.topic = "Addition"
      item_bank.domain = domain
      item_bank.template = ItemBankTemplate.objects.get(pk=1)
      item_bank.question_type = QuestionType.objects.get(pk=1)
      item_bank.save()
      user_item_bank = UserItemBank()
      user_item_bank.user = user
      user_item_bank.item_bank = item_bank
      user_item_bank.save()
      
      #Set up thresholds
      #add threshold
      grd = Grade.objects.get(name="C")
      thresh = Threshold()
      thresh.grade = grd
      thresh.item_bank = item_bank
      thresh.ability = 0      
      thresh.save()
      #add user probabilities
      user_item_bank.probabilities()   
      
      #Give the test some questions
      #Create fraction question bank
      fqb = FractionQuestionBank()
      oper = Oper.objects.get(pk=1)
      n = 20
      st = 0
      en = 10
      name = "Test Bank"
      negatives_allowed = True
      fqb.generate(name,st,en,negatives_allowed,oper,n)
      #Fill item bank from fraction question bank
      item_bank.fill(fqb,"fractions")
          
      #Candidate logs in and is directed to welcome page
      self.browser.get(ROOT + '/accounts/login/')
      name_field = self.browser.find_element_by_name('username')
      name_field.send_keys('JRotten')
      dob_field = self.browser.find_element_by_name('password')
      dob_field.send_keys('password')
      name_field.send_keys(Keys.RETURN)
      
      #Candidate should now see a list of available item banks grouped into domains
      #Number - Fractions - Addition - Questions Answered - Ability - Last Access - Time
      #Each should be associated with three actions:
      #Start - Review - Reset
      body = self.browser.find_element_by_tag_name('body')
      self.assertIn('Welcome', body.text)
      self.assertIn('Number',  body.text)
      self.assertIn('Fractions',  body.text)
      self.assertIn('Addition',  body.text)
      self.assertIn('50%',  body.text)
      
      #Candidate clicks on link to start test
      links = self.browser.find_elements_by_link_text('Short Test')
      links[0].click()
      
      #Should see start test screen
      body = self.browser.find_element_by_tag_name('body')
      self.assertIn('Fractions',body.text)
      self.assertIn('Addition',body.text)
      self.assertIn('Short Test',body.text)
      self.assertIn('4', body.text)
      
      #Clicks on link to start test
      links = self.browser.find_elements_by_link_text('Start the test')
      links[0].click()
      
      body = self.browser.find_element_by_tag_name('body')
      #Should be taken to first question
      self.assertIn('Work out', body.text)
      
      #Enters answer and hits submit
      const_field = self.browser.find_element_by_name('const')
      const_field.send_keys('9')

      num_field = self.browser.find_element_by_name('num')
      num_field.send_keys('7')

      denom_field = self.browser.find_element_by_name('denom')
      denom_field.send_keys('8')

      denom_field.send_keys(Keys.RETURN)
      
      #Should see feedback that answer is wrong
      body = self.browser.find_element_by_tag_name('body')
      self.assertIn('Wrong!', body.text)
      self.assertIn('9', body.text)
      self.assertIn('7', body.text)
      self.assertIn('8', body.text)
      
      #Clicks next
      links = self.browser.find_elements_by_link_text('Next')
      links[0].click()
      
      #Get second item
      
      user_cat_test = UserCatTest.objects.filter(user=user)
      user_cat_test = user_cat_test.order_by('-id')[0]
      cat_test_item = CatTestItem.objects.filter(user_cat_test=user_cat_test)
      cat_test_item = cat_test_item.order_by('-id')[0]
      ibq = cat_test_item.item_bank_question
      
      ifq = ItemBankFractionQuestion.objects.get(item_bank_question=ibq)
      ans = ifq.fraction_bank_question.question.answer
      
      #Enters correct answer and hits submit
      const_field = self.browser.find_element_by_name('const')
      const_field.send_keys(ans.const)

      num_field = self.browser.find_element_by_name('num')
      num_field.send_keys(ans.num)

      denom_field = self.browser.find_element_by_name('denom')
      denom_field.send_keys(ans.denom)

      denom_field.send_keys(Keys.RETURN)
      
      #Should see correct
      body = self.browser.find_element_by_tag_name('body')
      self.assertIn('Correct!', body.text)
            
      #Clicks next
      links = self.browser.find_elements_by_link_text('Next')
      links[0].click()
      
      #Question 3
      denom_field = self.browser.find_element_by_name('denom')
      denom_field.send_keys(Keys.RETURN)
      
      #Doesn't answer, clicks next
      links = self.browser.find_elements_by_link_text('Next')
      links[0].click()
      
      #Question 4
      denom_field = self.browser.find_element_by_name('denom')
      denom_field.send_keys(Keys.RETURN)
      
      #Doesn't answer, clicks next
      links = self.browser.find_elements_by_link_text('End')
      links[0].click()
      
      #Should see end
      body = self.browser.find_element_by_tag_name('body')
      self.assertIn('End', body.text)
      
      #Clicks end
      links = self.browser.find_elements_by_link_text('Return')
      links[0].click()
      
      #Should see performance on item bank updated
      body = self.browser.find_element_by_tag_name('body')
      self.assertIn('-2.318', body.text)
      self.assertIn('4', body.text)
      self.assertIn('2%', body.text)
Beispiel #21
0
 def test_updateAbility(self):
     cat_test = CatTest()
     cat_test.name = "short"
     cat_test.max_items = 10
     cat_test.save()
     user = User.objects.create_user("john", "*****@*****.**", "johnpassword")
     user.save()
     domain = Domain()
     domain.name = "Number"
     domain.create_date = datetime.datetime(2012, 03, 06)
     domain.save()
     item_bank = ItemBank()
     item_bank.name = "Fractions"
     item_bank.topic = "Addition"
     item_bank.domain = domain
     item_bank.create_date = datetime.datetime(2012, 03, 06)
     item_bank.save()
     user_item_bank = UserItemBank()
     user_item_bank.user = user
     user_item_bank.item_bank = item_bank
     user_item_bank.save()
     ibq = ItemBankQuestion()
     ibq.item_bank = item_bank
     ibq.save()
     user_cat_test = UserCatTest()
     user_cat_test.user = user
     user_cat_test.item_bank = item_bank
     user_cat_test.cat_test = cat_test
     user_cat_test.save()
     # First question right
     test_pattern = [1, 1, 0]
     test_ability = [0, 0, math.log(2)]
     test_difficulty = [2, 1, -2.0 / 3.0]
     test_stand_err = [2, 2, 1.5]
     test_items = [1, 2, 3]
     test_hardness = [0, 0, 0]
     test_right = [1, 2, 2]
     # Make three questions
     for i in range(1, 4):
         ibq = ItemBankQuestion()
         ibq.item_bank = item_bank
         ibq.save()
     # Find first question
     user_cat_test.nextQuestion()
     user_cat_test.updateAbility(1)
     self.assertEquals(user_cat_test.right, 1)
     self.assertEquals(user_cat_test.items, 1)
     self.assertEquals(user_cat_test.difficulty, 2)
     self.assertEquals(user_cat_test.hardness, 0)
     self.assertEquals(user_cat_test.ability, 0)
     # Second question right
     user_cat_test.nextQuestion()
     user_cat_test.updateAbility(1)
     self.assertEquals(user_cat_test.right, 2)
     self.assertEquals(user_cat_test.items, 2)
     self.assertEquals(user_cat_test.difficulty, 1)
     self.assertEquals(user_cat_test.hardness, 0)
     self.assertEquals(user_cat_test.ability, 0)
     # Third question wrong
     user_cat_test.nextQuestion()
     user_cat_test.updateAbility(0)
     self.assertEquals(user_cat_test.right, 2)
     self.assertEquals(user_cat_test.items, 3)
     self.assertEquals(user_cat_test.difficulty, -2.0 / 3.0)
     self.assertEquals(user_cat_test.hardness, 0)
     self.assertEquals(user_cat_test.ability, math.log(2))
Beispiel #22
0
 def test_nextQuestion(self):
     cat_test = CatTest()
     cat_test.name = "short"
     cat_test.max_items = 10
     cat_test.save()
     user = User.objects.create_user("john", "*****@*****.**", "johnpassword")
     user.save()
     domain = Domain()
     domain.name = "Number"
     domain.create_date = datetime.datetime(2012, 03, 06)
     domain.save()
     item_bank = ItemBank()
     item_bank.name = "Fractions"
     item_bank.topic = "Addition"
     item_bank.domain = domain
     item_bank.create_date = datetime.datetime(2012, 03, 06)
     item_bank.save()
     user_item_bank = UserItemBank()
     user_item_bank.user = user
     user_item_bank.item_bank = item_bank
     user_item_bank.save()
     ibq = ItemBankQuestion()
     ibq.item_bank = item_bank
     ibq.save()
     user_cat_test = UserCatTest()
     user_cat_test.user = user
     user_cat_test.item_bank = item_bank
     user_cat_test.cat_test = cat_test
     user_cat_test.save()
     q = user_cat_test.nextQuestion()
     # One item in bank, one taken
     self.assertEquals(isinstance(q, CatTestItem), True)
     q = user_cat_test.nextQuestion()
     # One item in bank, try to take another, should return None
     self.assertEquals(isinstance(q, CatTestItem), False)
     # Add more questions and see if they are repeated
     for i in range(1, 11):
         ibq = ItemBankQuestion()
         ibq.item_bank = item_bank
         ibq.save()
     for i in range(1, 11):
         q = user_cat_test.nextQuestion()
         print q.item_bank_question.id
     # Add a question of perfect difficulty and see if it is chosen amongst others
     for i in range(1, 11):
         ibq = ItemBankQuestion()
         ibq.item_bank = item_bank
         ibq.save()
     user_cat_test.difficulty = 2
     user_cat_test.stand_err = 0.1
     hibq = ItemBankQuestion()
     hibq.item_bank = item_bank
     hibq.difficulty = 2
     hibq.save()
     q = user_cat_test.nextQuestion()
     self.assertEquals(q.item_bank_question, hibq)
     # Make ability different to all questions and make sure one is chosen
     user_cat_test.difficulty = 2
     user_cat_test.stand_err = 0.1
     q = user_cat_test.nextQuestion()
     self.assertEquals(isinstance(q, CatTestItem), True)
Beispiel #23
0
 def test_question_view_w_login(self):
   #Test the post functionality of the question view         
   user = User.objects.create_user('john', '*****@*****.**', 'johnpassword')
   user.save()
   self.client.login(username='******', password='******')
   
   #create structures
   cat_test = CatTest()
   cat_test.name = "Short Test"
   cat_test.save()
   domain = Domain.objects.get(pk=1)
   item_bank = ItemBank()
   item_bank.name = "Fractions"
   item_bank.topic = "Addition"
   item_bank.domain = domain
   item_bank.template = ItemBankTemplate.objects.get(pk=1)
   item_bank.question_type = QuestionType.objects.get(pk=1)
   item_bank.save()
   user_item_bank = UserItemBank()
   user_item_bank.user = user
   user_item_bank.item_bank = item_bank
   user_item_bank.save()
   user_cat_test = UserCatTest()
   user_cat_test.user = user
   user_cat_test.item_bank = item_bank
   user_cat_test.cat_test = cat_test
   user_cat_test.save()
   #Give the test some questions
   #Create fraction question bank
   fqb = FractionQuestionBank()
   oper = Oper.objects.get(pk=1)
   n = 20
   st = 0
   en = 10
   name = "Test Bank"
   negatives_allowed = True
   fqb.generate(name,st,en,negatives_allowed,oper,n)
   #Fill item bank from fraction question bank
   item_bank.fill(fqb,"fractions")      
   response = self.client.get('/question/')
   self.assertEqual(response.status_code, 200)
   #Test that is has been rendered with a template
   self.assertTemplateUsed(response, 'question.html')
   #Question needs to know how to display itself
   self.assertIn('Fractions',response.content)
   #Fractions pulls in a fractions template          
   self.assertIn('Fraction Question',response.content)
   #Increments question
   self.assertIn('Questions completed: 0',response.content)
   #Displays the correct sign for a fraction question
   self.assertIn('+',response.content)
   #Test item_bank usage has been incremented          
   cat_test_item = CatTestItem.objects.filter(user_cat_test=user_cat_test)
   self.assertEquals(len(cat_test_item),1)
   cat_test_item = cat_test_item.order_by('-id')[0]
   self.assertEquals(cat_test_item.item_bank_question.usage,1)
   #Correct answer to question
   ibfq = ItemBankFractionQuestion.objects.filter(item_bank_question=cat_test_item.item_bank_question)
   answer = ibfq[0].fraction_bank_question.question.answer
   #Test post triggers marking process
   response = self.client.post('/question/', {'const': answer.const, 'num': answer.num, 'denom': answer.denom, 'time': 12})
   user_cat_test = UserCatTest.objects.get(user=user)
   self.assertEqual(user_cat_test.items,1)
   self.assertEqual(round(user_cat_test.ability,2),0.28)
   self.assertEqual(round(user_cat_test.stand_dev,2),0.91)
   #Check that a response has now been saved to user_cat_test
   cti = CatTestItem.objects.filter(user_cat_test=user_cat_test)
   self.assertEqual(len(cti),1)
   #Check response has been saved to cti
   self.assertEqual(cti[0].correct,1)
   self.assertEqual(cti[0].time_taken,12)
   #Try another
   cat_test_item = user_cat_test.nextQuestion()
   cat_test_item = CatTestItem.objects.filter(user_cat_test=user_cat_test)
   cat_test_item = cat_test_item.order_by('-id')[0]
   ibfq = ItemBankFractionQuestion.objects.filter(item_bank_question=cat_test_item.item_bank_question)
   answer = ibfq[0].fraction_bank_question.question.answer
   #Test post triggers marking process
   response = self.client.post('/question/', {'const': answer.const, 'num': answer.num, 'denom': answer.denom, 'time': 22})
   user_cat_test = UserCatTest.objects.get(user=user)
   self.assertEqual(user_cat_test.items,2)
   self.assertEqual(round(user_cat_test.ability,2),0.75)
   self.assertEqual(round(user_cat_test.stand_dev,2),0.82)          
   #Check that a response has now been saved to user_cat_test
   cti = CatTestItem.objects.filter(user_cat_test=user_cat_test)
   cti = cti.order_by('-id')
   self.assertEqual(len(cti),2)
   #Check response has been saved to cti
   self.assertEqual(cti[0].correct,1)
   self.assertEqual(cti[0].time_taken,22)          
   #Try another
   cat_test_item = user_cat_test.nextQuestion()
   #Test post triggers marking process
   response = self.client.post('/question/', {'const': answer.const, 'num': answer.num, 'denom': answer.denom, 'time': 3})
   user_cat_test = UserCatTest.objects.get(user=user)
   self.assertEqual(user_cat_test.items,3)
   self.assertEqual(round(user_cat_test.ability,2),0.76)
   self.assertEqual(round(user_cat_test.stand_dev,2),0.71)          
   #Check that a response has now been saved to user_cat_test
   cti = CatTestItem.objects.filter(user_cat_test=user_cat_test)
   cti = cti.order_by('-id')
   self.assertEqual(len(cti),3)
   #Check response has been saved to cti
   self.assertEqual(cti[0].correct,0)
   self.assertEqual(cti[0].time_taken,3)