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)
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)
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)
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)
def test_create_and_save(self): grd = Grade.objects.get(name="A") 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() thresh = Threshold() thresh.grade = grd thresh.item_bank = item_bank thresh.ability = -1 thresh.init_prob = 50 thresh.save() thresh = Threshold.objects.all()[0] self.assertEquals(thresh.ability,-1) self.assertEquals(thresh.grade.name,"A") self.assertEquals(thresh.item_bank.name,"Fractions") self.assertEquals(thresh.init_prob,50)
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 thresh.ability = -1 thresh.save() user_item_bank.probabilities() #Give the test some questions #Create fraction question bank fqb = FractionQuestionBank() oper = Oper.objects.get(pk=1) n = 10
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)
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)
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)