def test_can_fill_item_bank_with_fraction_bank(self): fixtures = ['initial_data.yaml'] #create domain domain = Domain.objects.get(name="Number") #Create item bank 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() #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) fbqs = FractionBankQuestion.objects.filter(fraction_question_bank=fqb) #Fill item bank from fraction question bank item_bank.fill(fqb,"fractions") ibqs = ItemBankQuestion.objects.filter(item_bank=item_bank) self.assertEquals(len(ibqs),len(fbqs)) ibq = ibqs[0] nme = fbqs[0].question.f1.describe() + " + " + fbqs[0].question.f2.describe() + " = " + fbqs[0].question.answer.describe() self.assertEquals(ibq.name,nme)
def test_can_edit_question_via_admin_site(self): #Set up an item bank and associate with user 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() #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") #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') # 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') #She sees a hyperlink that says "Centres" links = self.browser.find_elements_by_link_text('Item bank questions') self.assertEquals(len(links), 1) #Clicks it links[0].click() body = self.browser.find_element_by_tag_name('body') self.assertIn('/', body.text)
def test_can_create_link_btwn_item_bank_and_fraction_bank(self): fixtures = ['initial_data.yaml'] #create domain domain = Domain.objects.get(name="Number") #Create item bank 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() #Create item bank question ibq = ItemBankQuestion() ibq.item_bank = item_bank ibq.usage = 0 ibq.difficulty = 0 ibq.sd_difficulty = 0 ibq.discrimination = 1 ibq.save() #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) fbqs = FractionBankQuestion.objects.filter(fraction_question_bank=fqb) #Link item bank and question bank ibfb = ItemBankFractionQuestion() ibfb.item_bank_question = ibq ibfb.fraction_bank_question = fbqs[0] ibfb.save() ibfbs = ItemBankFractionQuestion.objects.all()[0] self.assertEquals(ibfbs.item_bank_question,ibq) self.assertEquals(ibfbs.fraction_bank_question,fbqs[0])
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 st = 0 en = 10 name = "Test Bank 20 Addition" negatives_allowed = False fqb.generate(name,st,en,negatives_allowed,oper,n) #Fill item bank from fraction question bank item_bank.fill(fqb,"fractions") item_bank = ItemBank() item_bank.name = "Fractions" item_bank.topic = "Subtraction" item_bank.domain = domain item_bank.template = ItemBankTemplate.objects.get(pk=1)
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_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)
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)