Ejemplo n.º 1
0
 def test__update_exercise_session_scenario4(self):
     #Delete all the bookmark records so that the exercise has no mapping to any
     Bookmark.query.delete()
     db_session.commit()
     resulting_exercise_session = UserExerciseSession.update_exercise_session(
         self.exercises[0], db_session)
     assert (None == resulting_exercise_session)
Ejemplo n.º 2
0
 def test__find_by_cohort(self):
     cohort_id = self.ex_session1.user.cohort_id
     active_sessions = UserExerciseSession.find_by_cohort(
         cohort_id,
         self.VERY_FAR_IN_THE_PAST,
         self.VERY_FAR_IN_THE_FUTURE,
         is_active=True)
     assert active_sessions
Ejemplo n.º 3
0
 def test__find_by_user_only_one_active(self):
     user = self.ex_session1.user
     active_sessions = UserExerciseSession.find_by_user(
         user.id,
         self.VERY_FAR_IN_THE_PAST,
         self.VERY_FAR_IN_THE_FUTURE,
         is_active=True)
     assert len(active_sessions) == 1
Ejemplo n.º 4
0
    def test__find_by_user_two_inactive(self):
        # WHEN: we have two sessions, and both are not active
        user = self.ex_session1.user

        self.ex_session1.is_active = False

        self.ex_session2 = ExerciseSessionRule().exercise_session
        self.ex_session2.user_id = user.id
        self.ex_session2.is_active = False

        # THEN: we find both of them
        all_sessions = UserExerciseSession.find_by_user(
            user.id, self.VERY_FAR_IN_THE_PAST, self.VERY_FAR_IN_THE_FUTURE)
        assert len(all_sessions) == 2
Ejemplo n.º 5
0
    def setUp(self):
        super().setUp()
        exercise_session_rule = ExerciseSessionRule()
        self.ex_session1 = exercise_session_rule.exercise_session
        self.user = exercise_session_rule.user
        self.bookmark = exercise_session_rule.bookmark
        self.exercises = Exercise.find(user_id=self.user.id)

        self.exercise_session_timeout = UserExerciseSession.get_exercise_session_timeout(
        )
        self.VERY_FAR_IN_THE_PAST = '2000-01-01T00:00:00'
        self.VERY_FAR_IN_THE_FUTURE = '2030-01-01T00:00:00'
        self.CURRENT_TIME = datetime.now()
        self.TIMEOUT_SECONDS_IN_THE_PAST = datetime.now() - timedelta(
            seconds=self.exercise_session_timeout)
        self.SOME_TIME_AGO = datetime.now() - timedelta(
            seconds=self.exercise_session_timeout * 20)
        self.A_BIT_LATER_THAN_SOME_TIME_AGO = datetime.now() - timedelta(
            seconds=self.exercise_session_timeout * 30)
Ejemplo n.º 6
0
    def _create_model_object(self):
        user_rule = UserRule()

        cohort = CohortRule()
        user = cohort.student1

        #UserRule and CohortRule give different user.id, therefore we equalize them so that all the information refers
        #to the same user
        user = user_rule.user

        start_time = datetime.now() - timedelta(minutes=randint(0, 7200))

        bookmark_rules = user_rule.add_bookmarks(bookmark_count=3,
                                                 exercises_count=3)
        self.user = user_rule.user
        self.bookmark = bookmark_rules[0].bookmark

        exercise_session = UserExerciseSession(user.id, start_time)

        return exercise_session
Ejemplo n.º 7
0
from zeeguu_core.model.exercise import Exercise
from zeeguu_core.model.user_exercise_session import UserExerciseSession

import zeeguu_core
'''
    Script that loops through all the exercises in the database, and recomputes the history of
    exercise sessions. 

    NOTE: It clears and recreates the table
'''

db_session = zeeguu_core.db.session

#Clear table before starting
UserExerciseSession.query.delete()
db_session.commit()

data = Exercise.find()

for user_exercise in data:

    #Skip misleading records
    if user_exercise.solving_speed < 2147483647 and user_exercise.solving_speed > 0:

        UserExerciseSession.update_exercise_session(user_exercise, db_session)
        print(user_exercise.id)
Ejemplo n.º 8
0
 def test__update_exercise_session_scenario3(self):
     self.ex_session1.is_active = False
     resulting_exercise_session = UserExerciseSession.update_exercise_session(
         self.exercises[0], db_session)
     assert resulting_exercise_session != self.ex_session1
Ejemplo n.º 9
0
 def test__update_exercise_session_scenario2(self):
     self.ex_session1.last_action_time = self.SOME_TIME_AGO
     self.exercises[0].time = self.CURRENT_TIME
     resulting_exercise_session = UserExerciseSession.update_exercise_session(
         self.exercises[0], db_session)
     assert resulting_exercise_session != self.ex_session1
Ejemplo n.º 10
0
 def test__update_exercise_session_scenario1(self):
     self.ex_session1.last_action_time = self.TIMEOUT_SECONDS_IN_THE_PAST
     self.exercises[0].time = self.CURRENT_TIME
     updated_session = UserExerciseSession.update_exercise_session(
         self.exercises[0], db_session)
     assert updated_session == self.ex_session1
Ejemplo n.º 11
0
 def test__is_not_same_exercise_session(self):
     new_exercise_session = UserExerciseSession(self.ex_session1.user_id,
                                                datetime.now())
     new_exercise_session.last_action_time = self.SOME_TIME_AGO
     new_exercise_session.start_time = self.A_BIT_LATER_THAN_SOME_TIME_AGO
     assert (False == new_exercise_session._is_still_active())
Ejemplo n.º 12
0
 def test__get_exercise_session2(self):
     self.ex_session2 = ExerciseSessionRule().exercise_session
     self.ex_session2.user_id = self.ex_session1.user_id
     resulting_exercise_session = UserExerciseSession._find_most_recent_session(
         self.ex_session1.user_id, db_session)
     assert resulting_exercise_session.is_active
Ejemplo n.º 13
0
 def test__get_exercise_session1(self):
     #Since the ex_session1 rule saves the exercise_session in the DB, we expect to find it there
     assert UserExerciseSession._find_most_recent_session(
         self.ex_session1.user_id, db_session)