Ejemplo n.º 1
0
 def get_upcoming_assignments(self, assignments, now):
     for assignment in assignments:
         date = datetime.strptime(assignment['_date'], "%m/%d/%Y")
         name = assignment['assignment_description']
         assignment_type = assignment['assignment_type']
         try:
             points_earned = Decimal(assignment['raw_score'])
         except InvalidOperation:
             points_earned = None
         points_possible = int(assignment['points_possible'])
         if date >= now:
             if self.is_weighted:
                 self.upcoming_assignments.append(
                     Assignment(name,
                                date,
                                category=assignment_type,
                                weighted=True))
             else:
                 self.upcoming_assignments.append(
                     Assignment(name,
                                date,
                                category=assignment_type,
                                points_earned=points_earned,
                                points_possible=points_possible,
                                weighted=False))
 def test_score_is_same_as_score_on_exercise_if_there_is_only_one_exercise(
         self):
     assignment = Assignment()
     exercise = MagicMock()
     exercise.score = 50
     assignment.add_exercise(exercise)
     assert assignment.score == 50
 def test_can_remove_exercise(self):
     assignment = Assignment()
     exercise = MagicMock()
     assignment.add_exercise(exercise)
     assignment.remove_exercise(exercise)
     number_of_exercises = len(assignment.exercises)
     assert number_of_exercises == 0
 def test_score_can_not_exceed_one_hundred_by_adding_exercises(self):
     with self.assertRaisesRegexp(ValueError, '110'):
         assignment = Assignment()
         first_exercise = MagicMock()
         first_exercise.score = 55 
         second_exercise = MagicMock()
         second_exercise.score = 55 
         assignment.add_exercise(first_exercise)
         assignment.add_exercise(second_exercise)
 def test_score_is_a_sum_of_all_the_added_exercises(self):
     assignment = Assignment()
     first_exercise = MagicMock()
     second_exercise = MagicMock()
     first_exercise.score = 10
     second_exercise.score = 10
     assignment.add_exercise(first_exercise)
     assignment.add_exercise(second_exercise)
     assert assignment.score == 20
 def test_score_is_updated_when_exercises_are_removed(self):
     assignment = Assignment()
     exercise = MagicMock()
     exercise.score = 30
     exercise_to_be_removed = MagicMock()
     exercise_to_be_removed.score = 10
     assignment.add_exercise(exercise)
     assignment.add_exercise(exercise_to_be_removed)
     assignment.remove_exercise(exercise_to_be_removed)
     assert assignment.score == 30
Ejemplo n.º 7
0
 def get_nti_assignments(self):
     assignments = []
     ntis = self.grade_detail.find_all(
         'tr',
         attrs={'class': lambda l: l and l.endswith('bad_assignment')})
     for assignment in ntis:
         name = assignment.find('td', attrs={
             'class': 'assignment text'
         }).text.rstrip(' ')
         date = assignment.find('td', attrs={
             'class': 'due_date text'
         }).string.split()
         parsed_date = Assignment.parse_date(date)
         category = assignment.parent.get('class')[0].replace('_',
                                                              ' ').title()
         assignments.append(
             Assignment(name, parsed_date, category=category,
                        weighted=True))
     return assignments
 def test_score_is_updated_when_exercises_are_removed(self):
     assignment = Assignment()
     exercise = MagicMock()
     exercise.score = 30 
     exercise_to_be_removed = MagicMock()
     exercise_to_be_removed.score = 10 
     assignment.add_exercise(exercise)
     assignment.add_exercise(exercise_to_be_removed)
     assignment.remove_exercise(exercise_to_be_removed)
     assert assignment.score == 30
 def test_can_remove_exercise(self):
     assignment = Assignment()
     exercise = MagicMock()
     assignment.add_exercise(exercise)
     assignment.remove_exercise(exercise)
     number_of_exercises = len(assignment.exercises)
     assert number_of_exercises == 0
 def test_score_is_a_sum_of_all_the_added_exercises(self):
     assignment = Assignment()
     first_exercise = MagicMock()
     second_exercise = MagicMock()
     first_exercise.score = 10
     second_exercise.score = 10
     assignment.add_exercise(first_exercise)
     assignment.add_exercise(second_exercise)
     assert assignment.score == 20
 def test_score_can_not_exceed_one_hundred_by_adding_exercises(self):
     with self.assertRaisesRegexp(ValueError, '110'):
         assignment = Assignment()
         first_exercise = MagicMock()
         first_exercise.score = 55
         second_exercise = MagicMock()
         second_exercise.score = 55
         assignment.add_exercise(first_exercise)
         assignment.add_exercise(second_exercise)
Ejemplo n.º 12
0
    def __init__(self, canvas_course: canvasapi.course.Course, canvas_user: canvasapi.user.User, canvas_api: canvasapi.Canvas):
        self.course = canvas_course
        self.user = canvas_user
        self.api = canvas_api

        self.id = self.course.id
        self.name = self.course.name
        self.start_date = self.course.start_at
        self.end_date = self.course.end_at
        self.created_date = self.course.created_at

        self.modules = [Module(module, self.course) for module in self.course.get_modules()]
        self.assignments = [Assignment(assignment, self.user, self.api) for assignment in self.course.get_assignments()]

        self.files = FileSystem(self.course)
        print(self.files)
Ejemplo n.º 13
0
 def get_assignments(self):
     assignments = []
     if self.is_weighted:
         assignments_table = self.grade_detail.find(
             'table', attrs={'class': 'data_table grades'})
         assignment_sections = assignments_table.find_all('tbody')
         for section in assignment_sections:
             category = section.get('class')[0].replace('_', ' ').title()
             for assignment in section.find_all(
                     'tr',
                     attrs={'class': lambda l: l and l.startswith('row_')}):
                 name = assignment.find('td',
                                        attrs={
                                            'class': 'assignment text'
                                        }).text[:-1]
                 assignment_grade = assignment.find('td',
                                                    attrs={
                                                        'class':
                                                        'grade number'
                                                    }).string
                 if "Incomplete" in assignment_grade:
                     parsed_assignment_grade = 0
                 else:
                     parsed_assignment_grade = Decimal(
                         assignment_grade.strip('%'))
                 assignment_date = assignment.find('td',
                                                   attrs={
                                                       'class':
                                                       'due_date text'
                                                   }).string.split()
                 parsed_assignment_date = Assignment.parse_date(
                     assignment_date)
                 assignments.append(
                     Assignment(name,
                                parsed_assignment_date,
                                category=category,
                                grade=parsed_assignment_grade,
                                weighted=True))
     else:
         assignments_container = self.grade_detail.find(
             'div', attrs={'id': 'assignments'})
         assignment_list = assignments_container.find_all(
             'tr', attrs={'class': lambda l: l and l.startswith('row_')})
         for assignment in assignment_list:
             name = assignment.find('td',
                                    attrs={
                                        'class': 'assignment text'
                                    }).text[:-1]
             assignment_date = assignment.find('td',
                                               attrs={
                                                   'class': 'due_date text'
                                               }).string.split()
             points_earned = Decimal(
                 assignment.find('td',
                                 attrs={
                                     'class': 'points_earned number'
                                 }).string)
             points_possible = Decimal(
                 assignment.find('td',
                                 attrs={
                                     'class': 'points_possible number'
                                 }).string)
             assignments.append(
                 Assignment(name,
                            Assignment.parse_date(assignment_date),
                            points_earned=points_earned,
                            points_possible=points_possible,
                            weighted=False))
     return assignments
 def test_error_is_raised_if_same_exercise_is_added_twice(self):
     with self.assertRaises(DuplicateExerciseError):
         assignment = Assignment()
         exercise = MagicMock()
         assignment.add_exercise(exercise)
         assignment.add_exercise(exercise)
 def test_score_is_same_as_score_on_exercise_if_there_is_only_one_exercise(self):
     assignment = Assignment()
     exercise = MagicMock()
     exercise.score = 50
     assignment.add_exercise(exercise)
     assert assignment.score == 50
 def test_can_get_exercise(self):
     assignment = Assignment()
     exercise = MagicMock()
     assignment.add_exercise(exercise)
     retrieved_exercise = assignment.get_exercise(1)
     assert retrieved_exercise == exercise
 def test_has_zero_exercises_by_default(self):
     assignment = Assignment()
     number_of_exercises = len(assignment.exercises)
     assert number_of_exercises == 0
 def test_assignment_number_is_none_by_default(self):
     assert Assignment().number == None
 def test_assignment_number_must_be_a_number(self):
     with self.assertRaisesRegexp(ValueError, 'integer'):
         assignment = Assignment(number="two")
 def test_assignment_number_can_not_be_negative(self):
     with self.assertRaisesRegexp(ValueError, 'positive'):
         assignment = Assignment(number=-5)
 def test_error_is_raised_if_same_exercise_is_added_twice(self):
     with self.assertRaises(DuplicateExerciseError):
         assignment = Assignment()
         exercise = MagicMock()
         assignment.add_exercise(exercise)
         assignment.add_exercise(exercise)
 def test_has_a_default_score_of_zero(self):
     assignment = Assignment()
     assert assignment.score == 0
 def test_can_get_exercise(self):
     assignment = Assignment()
     exercise = MagicMock()
     assignment.add_exercise(exercise)
     retrieved_exercise = assignment.get_exercise(1)
     assert retrieved_exercise == exercise