示例#1
0
 def setUp(self):
     self.user1 = User.objects.create_user('bertie', '*****@*****.**', 
                                           'bertword')
     self.user1.is_active = True
     self.user1.save()    
     
     self.user2 = User.objects.create_user('flo', '*****@*****.**', 'flo')
     self.user2.is_active = True
     self.user2.save()
     
     self.course1 = Course(**course1_data)
     self.course1.instructor = self.user1
     self.course1.organiser = self.user1
     self.course1.save() 
     self.course2 = Course(**course2_data)
     self.course2.instructor = self.user1
     self.course2.organiser = self.user1
     self.course2.save()
     self.uc = UserCourse(course=self.course1, user=self.user2)
     self.uc.save()
     self.lesson = Lesson(name="Test Lesson 1", course = self.course1)
     self.lesson.save()
     self.lesson2 = Lesson(name="Test Lesson 2", course = self.course2)
     self.lesson2.save()
     self.li = LearningIntention(lesson=self.lesson, text="Intend...")
     self.li2 = LearningIntention(lesson=self.lesson2, text="Explore...")
     self.li.save()
     self.li2.save()
     self.lid = LearningIntentionDetail(
         learning_intention=self.li, 
         text ="Criterion...",
         lid_type=LearningIntentionDetail.SUCCESS_CRITERION)
     self.lid2 = LearningIntentionDetail(
         learning_intention=self.li2, 
         text ="Criterion...",
         lid_type=LearningIntentionDetail.SUCCESS_CRITERION)
     self.lid.save()
     self.lid2.save()
     self.ulid = UserLearningIntentionDetail(
         user=self.user2, learning_intention_detail=self.lid)
     self.ulid.save()
示例#2
0
    def setUp(self):
        self.user1 = User.objects.create_user('bertie', '*****@*****.**', 
                                              'bertword')
        self.user1.is_active = True
        self.user1.save()    
        self.user2 = User.objects.create_user('Van Gogh', '*****@*****.**', 'vancode')
        self.user2.is_active = True
        self.user2.save()
        self.user3 = User.objects.create_user('Chuck Norris', '*****@*****.**', 'dontask')
        self.user3.is_active = True
        self.user3.save()
        self.course1 = Course(**course1_data)
        self.course1.instructor = self.user2
        self.course1.organiser = self.user2
        self.course1.save() 

        self.uc = UserCourse(course=self.course1, user=self.user1)
        self.uc.save()
        self.lesson = Lesson(name="Test Lesson 1", course = self.course1)
        self.lesson.save() 
        self.li = LearningIntention(lesson=self.lesson, text="Intend...")
        self.li.save()
        self.uli = UserLearningIntention(user=self.user1, 
                                         learning_intention = self.li)
        self.lid1 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID A",
            lid_type=LearningIntentionDetail.SUCCESS_CRITERION)
        self.lid2 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID B",
            lid_type=LearningIntentionDetail.SUCCESS_CRITERION)
        self.lid3 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID C",
            lid_type=LearningIntentionDetail.LEARNING_OUTCOME)
        self.lid1.save()
        self.lid2.save()
        self.lid3.save()   
        self.ulid1 = UserLearningIntentionDetail(user=self.user1,
                                    learning_intention_detail=self.lid1)
        self.ulid1.save()    
        self.ulid2 = UserLearningIntentionDetail(user=self.user1,
                                    learning_intention_detail=self.lid2)
        self.ulid2.save()
        self.ulid3 = UserLearningIntentionDetail(user=self.user1,
                                    learning_intention_detail=self.lid3)
        self.ulid3.save()         
示例#3
0
class UserLearningIntentionDetailModelTests(TestCase):
    """Test model behaviour of user interaction with 
    learning intention details"""

    def setUp(self):
        self.user1 = User.objects.create_user('bertie', '*****@*****.**', 
                                              'bertword')
        self.user1.is_active = True
        self.user1.save()    
        
        self.user2 = User.objects.create_user('flo', '*****@*****.**', 'flo')
        self.user2.is_active = True
        self.user2.save()
        
        self.course1 = Course(**course1_data)
        self.course1.instructor = self.user1
        self.course1.organiser = self.user1
        self.course1.save() 
        self.course2 = Course(**course2_data)
        self.course2.instructor = self.user1
        self.course2.organiser = self.user1
        self.course2.save()
        self.uc = UserCourse(course=self.course1, user=self.user2)
        self.uc.save()
        self.lesson = Lesson(name="Test Lesson 1", course = self.course1)
        self.lesson.save()
        self.lesson2 = Lesson(name="Test Lesson 2", course = self.course2)
        self.lesson2.save()
        self.li = LearningIntention(lesson=self.lesson, text="Intend...")
        self.li2 = LearningIntention(lesson=self.lesson2, text="Explore...")
        self.li.save()
        self.li2.save()
        self.lid = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="Criterion...",
            lid_type=LearningIntentionDetail.SUCCESS_CRITERION)
        self.lid2 = LearningIntentionDetail(
            learning_intention=self.li2, 
            text ="Criterion...",
            lid_type=LearningIntentionDetail.SUCCESS_CRITERION)
        self.lid.save()
        self.lid2.save()
        self.ulid = UserLearningIntentionDetail(
            user=self.user2, learning_intention_detail=self.lid)
        self.ulid.save()

    def test_cycling_first_click_on_a_LID_triggers_save(self):
        """When user first clicks on a LID, a ULID needs a primary key

        The first time a user clicks on a LID (learning intention detail),
        a ULID interaction will be created in memory by the view
        userlearningintentiondetail_cycle, having no PK. The model cycle()
        should check and save to the database if this is the first click."""


        # Enrol user on course 2:
        UserCourse(course=self.course2, user=self.user2).save()
        # Simulate first click on LID:
        ulid_mem = UserLearningIntentionDetail(
            user=self.user2, learning_intention_detail=self.lid2)
        self.assertFalse(ulid_mem.pk)
        ulid_mem.cycle()
        self.assertTrue(ulid_mem.pk)   

    def test__checkrep_passes_initial_state(self):
        """Test the internal representation checker with LID interaction"""

        self.assertTrue(self.ulid._checkrep(), "ULID _checkrep failed")
        
    def test__checkrep_picks_up_errored_initial_states(self):
        self.ulid.condition = ULIDConditions.amber #errored state
        self.assertFalse(self.ulid._checkrep())
        self.ulid.condition = ULIDConditions.green #errored state
        self.assertFalse(self.ulid._checkrep())

    def test__checkrep_picks_up_nonsense_conditions(self):
        self.ulid.condition = None
        with self.assertRaises(CheckRepError):
            self.ulid._checkrep()
        self.ulid.condition = "topaz"
        with self.assertRaises(CheckRepError):
            self.ulid._checkrep()
        
    def test_save(self):
        """Test the save functionality

        Principally, it should not save unless the user is enrolled
        on the corresponding course"""
        ulid2 = UserLearningIntentionDetail(user=self.user1,
                                    learning_intention_detail=self.lid2)
        ulid2.save()
        self.assertIsNone(ulid2.pk)	#should fail, user not on corr. course


    def test_cycle(self):
        """Check that state cycling works"""

        self.assertTrue(self.ulid._checkrep(), "Failure prior to cycle")
        self.assertEqual(self.ulid.condition, ULIDConditions.red)
        self.ulid.cycle()
        self.assertTrue(self.ulid._checkrep(), "Fail after first cycle")
        self.assertEqual(self.ulid.condition, ULIDConditions.amber)
        self.ulid.cycle()
        self.assertTrue(self.ulid._checkrep(), "Fail after second cycle")
        self.assertEqual(self.ulid.condition, ULIDConditions.green)
        self.ulid.cycle()
        self.assertTrue(self.ulid._checkrep(), "Fail after third cycle")
        self.assertEqual(self.ulid.condition, ULIDConditions.red)

    def test_cycle_history_timebar(self):
        """Test 5 minute timebar on history updates

        History of cycling events should append a new event if over 5 mins
        have elapsed since the last event, otherwise replace last history.
        """

        self.assertTrue(self.ulid._checkrep(), "Failure prior to cycle")
        #First check that rapid successive cycles don't append to history, 
        #intead, last entry should be replaced
        #NB: ulid.hist is JSON string. Count hist2list elements instead
        self.ulid.cycle()
        count1 = len(self.ulid.hist2list())  
        self.ulid.cycle()
        count2 = len(self.ulid.hist2list())
        self.assertEqual(count2, count1, "History grew when it shouldn't have")

        #Doctor the date to 10 mins prior, 
        #check that subsequent cycle does append to history        
        hist = json.loads(self.ulid.history)
        last_event = hist.pop()
        last_time = last_event[0]
        last_time = last_time - 600 #600 seconds earlier
        hist.append((last_time, last_event[1]))
        self.ulid.history = json.dumps(hist)
        self.ulid.cycle()
        count3 = len(self.ulid.hist2list())
        self.assertGreater(count3, count2, 
                           "History did not grow when it should")


    def test_hist2list(self):
        """See that history converts to list properly"""

        h2l_output = self.ulid.hist2list()
        self.assertIsInstance(h2l_output, list, "Output should be a list")
        for row in h2l_output:
            self.assertIsInstance(row, tuple, "Entry should be a tuple")
            self.assertIsInstance(row[0], datetime.datetime, 
                                  "Should be a datetime")
            self.assertTrue(is_aware(row[0]), "Datetime not TZ aware")
            self.assertIsInstance(row[1], str, "Action should be a string")

        last = h2l_output.pop()
        self.assertEqual(last[1], 'SET_RED', "Action should be SET_RED")


    def test_get_status(self):
        """Test that the correct status is returned"""

        self.assertEqual(self.ulid.get_status(), 'red', 
                         "Status should be 'red'")
        self.ulid.cycle()
        self.assertEqual(self.ulid.get_status(), 'amber', 
                         "Status should be 'amber'")
        self.ulid.cycle()
        self.assertEqual(self.ulid.get_status(), 'green', 
                         "Status should be 'green'")
        self.ulid.cycle()
        self.assertEqual(self.ulid.get_status(), 'red', 
                         "Status should be 'red'")

    def test___str__(self):
        """Test that the desired info is in the unicode method"""
        s = self.ulid.__str__()
        self.assertIn(self.ulid.user.username, s, 
                      "The username should be in the unicode")
        self.assertIn(self.ulid.learning_intention_detail.text[:10], s, 
                      "The first 10 chars of the criterion_text "
                      "should be in the unicode")

    def test___unicode__(self):
        """Test that the desired info is in the unicode method"""
        unicod = self.ulid.__unicode__()
        s = u"ULID:%s, User:%s, LID:%s" % \
            (self.ulid.pk, self.ulid.user.pk, 
             self.ulid.learning_intention_detail.pk)
        self.assertEqual(unicod, s, "Unicode output failure")
示例#4
0
    def setUp(self):
        self.user1 = User.objects.create_user('bertie', '*****@*****.**', 
                                              'bertword')
        self.user1.is_active = True
        self.user1.save()   

        self.user2 = User.objects.create_user('flo', '*****@*****.**', 'flo')
        self.user2.is_active = True
        self.user2.save()
 
        self.course1 = Course(**course1_data)
        self.course1.instructor = self.user1
        self.course1.organiser = self.user1
        self.course1.save() 
        self.uc = UserCourse(course=self.course1, user=self.user2)
        self.uc.save()
        self.lesson = Lesson(name="Test Lesson 1", course = self.course1)
        self.lesson.save() 
        self.li = LearningIntention(lesson=self.lesson, text="Intend...")
        self.li.save()
        self.uli = UserLearningIntention(user=self.user2, 
                                         learning_intention = self.li)
        self.lid1 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID A",
            lid_type=LearningIntentionDetail.SUCCESS_CRITERION)
        self.lid2 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID B",
            lid_type=LearningIntentionDetail.SUCCESS_CRITERION)
        self.lid3 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID C",
            lid_type=LearningIntentionDetail.SUCCESS_CRITERION)
        self.lid4 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID D",
            lid_type=LearningIntentionDetail.LEARNING_OUTCOME)
        self.lid5 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID E",
            lid_type=LearningIntentionDetail.LEARNING_OUTCOME)
        self.lid6 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID F",
            lid_type=LearningIntentionDetail.LEARNING_OUTCOME)
        self.lid1.save()
        self.lid2.save()
        self.lid3.save()
        self.lid4.save()
        self.lid5.save()
        self.lid6.save()
        self.ulid1 = UserLearningIntentionDetail(user=self.user2,
                                    learning_intention_detail=self.lid1)
        self.ulid1.save()    
        self.ulid2 = UserLearningIntentionDetail(user=self.user2,
                                    learning_intention_detail=self.lid2)
        self.ulid2.save()
        self.ulid3 = UserLearningIntentionDetail(user=self.user2,
                                    learning_intention_detail=self.lid3)
        self.ulid3.save()
        self.ulid4 = UserLearningIntentionDetail(user=self.user2,
                                    learning_intention_detail=self.lid4)
        self.ulid4.save()
        self.ulid5 = UserLearningIntentionDetail(user=self.user2,
                                    learning_intention_detail=self.lid5)
        self.ulid5.save()
        self.ulid6 = UserLearningIntentionDetail(user=self.user2,
                                    learning_intention_detail=self.lid6)
        self.ulid6.save()
示例#5
0
class UserLearningIntentionModelTests(TestCase):
    """Test model behaviour of user interaction with learning intentions"""

    def setUp(self):
        self.user1 = User.objects.create_user('bertie', '*****@*****.**', 
                                              'bertword')
        self.user1.is_active = True
        self.user1.save()   

        self.user2 = User.objects.create_user('flo', '*****@*****.**', 'flo')
        self.user2.is_active = True
        self.user2.save()
 
        self.course1 = Course(**course1_data)
        self.course1.instructor = self.user1
        self.course1.organiser = self.user1
        self.course1.save() 
        self.uc = UserCourse(course=self.course1, user=self.user2)
        self.uc.save()
        self.lesson = Lesson(name="Test Lesson 1", course = self.course1)
        self.lesson.save() 
        self.li = LearningIntention(lesson=self.lesson, text="Intend...")
        self.li.save()
        self.uli = UserLearningIntention(user=self.user2, 
                                         learning_intention = self.li)
        self.lid1 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID A",
            lid_type=LearningIntentionDetail.SUCCESS_CRITERION)
        self.lid2 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID B",
            lid_type=LearningIntentionDetail.SUCCESS_CRITERION)
        self.lid3 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID C",
            lid_type=LearningIntentionDetail.SUCCESS_CRITERION)
        self.lid4 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID D",
            lid_type=LearningIntentionDetail.LEARNING_OUTCOME)
        self.lid5 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID E",
            lid_type=LearningIntentionDetail.LEARNING_OUTCOME)
        self.lid6 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID F",
            lid_type=LearningIntentionDetail.LEARNING_OUTCOME)
        self.lid1.save()
        self.lid2.save()
        self.lid3.save()
        self.lid4.save()
        self.lid5.save()
        self.lid6.save()
        self.ulid1 = UserLearningIntentionDetail(user=self.user2,
                                    learning_intention_detail=self.lid1)
        self.ulid1.save()    
        self.ulid2 = UserLearningIntentionDetail(user=self.user2,
                                    learning_intention_detail=self.lid2)
        self.ulid2.save()
        self.ulid3 = UserLearningIntentionDetail(user=self.user2,
                                    learning_intention_detail=self.lid3)
        self.ulid3.save()
        self.ulid4 = UserLearningIntentionDetail(user=self.user2,
                                    learning_intention_detail=self.lid4)
        self.ulid4.save()
        self.ulid5 = UserLearningIntentionDetail(user=self.user2,
                                    learning_intention_detail=self.lid5)
        self.ulid5.save()
        self.ulid6 = UserLearningIntentionDetail(user=self.user2,
                                    learning_intention_detail=self.lid6)
        self.ulid6.save()

    def test___unicode__(self):
        self.assertEqual(u"ULI:%s, User:%s, LI:%s" % \
            (self.uli.pk, self.user2.pk, self.li.pk), self.uli.__unicode__())        

    def test___str__(self):
        self.assertEqual(u"User %s's data for LI:%s..." % \
            (self.user2.username, self.li.text[:10]), self.uli.__str__())

    def test_progress(self):
        self.assertEqual(self.uli.progress(), {u'SC':(0,3), u'LO':(0,3)})
        self.ulid1.cycle()
        self.assertEqual(self.uli.progress(), {u'SC':(0,3), u'LO':(0,3)})
        self.ulid1.cycle()
        self.assertEqual(self.uli.progress(), {u'SC':(1,3), u'LO':(0,3)})        
        self.ulid4.cycle()
        self.assertEqual(self.uli.progress(), {u'SC':(1,3), u'LO':(0,3)})
        self.ulid4.cycle()
        self.assertEqual(self.uli.progress(), {u'SC':(1,3), u'LO':(1,3)})
        self.ulid2.cycle()
        self.ulid2.cycle()
        self.ulid3.cycle()
        self.assertEqual(self.uli.progress(), {u'SC':(2,3), u'LO':(1,3)})
        self.ulid3.cycle()
        self.ulid4.cycle()
        self.assertEqual(self.uli.progress(), {u'SC':(3,3), u'LO':(0,3)})
        self.ulid5.cycle()
        self.ulid5.cycle()
        self.assertEqual(self.uli.progress(), {u'SC':(3,3), u'LO':(1,3)})
        self.ulid6.cycle()
        self.ulid6.cycle()
        self.assertEqual(self.uli.progress(), {u'SC':(3,3), u'LO':(2,3)})
示例#6
0
class UserLearningIntentionViewTests(TestCase):
    """Test views for learning intention interaction"""

    def setUp(self):
        self.user1 = User.objects.create_user('bertie', '*****@*****.**', 
                                              'bertword')
        self.user1.is_active = True
        self.user1.save()    
        self.user2 = User.objects.create_user('Van Gogh', '*****@*****.**', 'vancode')
        self.user2.is_active = True
        self.user2.save()
        self.user3 = User.objects.create_user('Chuck Norris', '*****@*****.**', 'dontask')
        self.user3.is_active = True
        self.user3.save()
        self.course1 = Course(**course1_data)
        self.course1.instructor = self.user2
        self.course1.organiser = self.user2
        self.course1.save() 

        self.uc = UserCourse(course=self.course1, user=self.user1)
        self.uc.save()
        self.lesson = Lesson(name="Test Lesson 1", course = self.course1)
        self.lesson.save() 
        self.li = LearningIntention(lesson=self.lesson, text="Intend...")
        self.li.save()
        self.uli = UserLearningIntention(user=self.user1, 
                                         learning_intention = self.li)
        self.lid1 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID A",
            lid_type=LearningIntentionDetail.SUCCESS_CRITERION)
        self.lid2 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID B",
            lid_type=LearningIntentionDetail.SUCCESS_CRITERION)
        self.lid3 = LearningIntentionDetail(
            learning_intention=self.li, 
            text ="LID C",
            lid_type=LearningIntentionDetail.LEARNING_OUTCOME)
        self.lid1.save()
        self.lid2.save()
        self.lid3.save()   
        self.ulid1 = UserLearningIntentionDetail(user=self.user1,
                                    learning_intention_detail=self.lid1)
        self.ulid1.save()    
        self.ulid2 = UserLearningIntentionDetail(user=self.user1,
                                    learning_intention_detail=self.lid2)
        self.ulid2.save()
        self.ulid3 = UserLearningIntentionDetail(user=self.user1,
                                    learning_intention_detail=self.lid3)
        self.ulid3.save()         

    def test_userlearningintention_cycle_redirect_not_enrolled(self):
        """If user not enrolled, can't cycle learning intentions"""

        not_enrolled_user = self.user3
        course = self.course1
        lid = self.lid1
        self.client.login(username='******', password='******')
        
        cycle_url = "/interaction/learningintentiondetail/{0}/cycle/" \
            .format(lid.pk)
        response = self.client.get(cycle_url)
        parsed_json = json.loads(response.content)
        self.assertEqual(parsed_json['authenticated'], True)
        self.assertEqual(parsed_json['enrolled'], False)
        self.assertEqual(parsed_json['course_pk'], 1)
   
    def test_userlearningintention_cycle_context(self):
        """Ensure correct context variables present for enrolled user"""

        enrolled_user = self.user1
        course = self.course1
        lid = self.lid1
        self.client.login(username="******", password="******")
        cycle_url = "/interaction/learningintentiondetail/{0}/cycle/" \
            .format(lid.pk)
        response = self.client.get(cycle_url)
        self.assertEqual(response.status_code, 200)
        parsed_json = json.loads(response.content)
        self.assertEqual(parsed_json['authenticated'], True)
        self.assertEqual(parsed_json['enrolled'], True)
        self.assertEqual(parsed_json['progress'], {u'SC': [0, 2], u'LO': [0, 1]})
        self.assertEqual(parsed_json['condition'], 1)
        

    def test_userlearningintention_progress_bar(self):
        """View returns correct data for AJAX call"""

        #self.fail("fix");
        #Not logged in
        response = self.client.get('/interaction/learningintentiondetail'\
                                    '/1/progress/')
        self.assertEqual(response.status_code, 302)

        #Now logged in
        self.client.login(username='******', password='******')
        #current implementation will not record progress without an 
        #initial cycle
        self.client.get('/interaction/learningintentiondetail/{0}/cycle/'\
            .format(self.lid1.pk))
        response = self.client.get(
            '/interaction/learningintentiondetail/{0}/progress/'\
            .format(self.lid1.pk))
        self.assertEqual(response.status_code, 200)