• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uw-it-aca / canvas-sis-provisioner / 4147136751

pending completion
4147136751

Pull #754

github

GitHub
Merge f4e8d5f13 into 58b7dd6e7
Pull Request #754: Develop

128 of 128 new or added lines in 6 files covered. (100.0%)

4322 of 7781 relevant lines covered (55.55%)

0.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

31.25
/sis_provisioner/views/course/expiration.py
1
# Copyright 2023 UW-IT, University of Washington
2
# SPDX-License-Identifier: Apache-2.0
3

4

5
from sis_provisioner.dao.course import (
1✔
6
    valid_academic_course_sis_id, valid_adhoc_course_sis_id,
7
    valid_canvas_course_id)
8
from sis_provisioner.models.course import Course
1✔
9
from sis_provisioner.views.admin import OpenRESTDispatch
1✔
10
from sis_provisioner.exceptions import CoursePolicyException
1✔
11
from django.utils.timezone import localtime
1✔
12
from logging import getLogger
1✔
13

14

15
logger = getLogger(__name__)
1✔
16

17

18
class CourseExpirationView(OpenRESTDispatch):
1✔
19
    """ Open API to return Course expiration_date at
20
            /api/v1/course/<course id>/expiration.
21
        GET returns 200 with Course expiration date.
22
    """
23
    def get(self, request, *args, **kwargs):
1✔
24
        try:
×
25
            course_id = kwargs['course_id']
×
26
            course_ref = self._normalize(course_id)
×
27
            course = Course.objects.get(**course_ref)
×
28
            expiration_date = course.expiration_date if (
×
29
                course.expiration_date) else course.default_expiration_date
30

31
            return self.json_response({
×
32
                "course_id": course_id,
33
                "expiration_date": localtime(
34
                    expiration_date).isoformat() if (
35
                        expiration_date is not None) else None})
36

37
        except CoursePolicyException as ex:
×
38
            return self.error_response(404, "{}".format(ex))
×
39
        except Course.DoesNotExist:
×
40
            return self.error_response(404, "Course not found")
×
41

42
    def _normalize(self, course):
1✔
43
        """ normalize course id case
44
        """
45
        course_key = 'course_id'
×
46
        course = course.strip()
×
47
        try:
×
48
            valid_academic_course_sis_id(course)
×
49
        except CoursePolicyException:
×
50
            try:
×
51
                valid_adhoc_course_sis_id(course)
×
52
                course = course.lower()
×
53
            except CoursePolicyException:
×
54
                valid_canvas_course_id(course)
×
55
                course_key = 'canvas_course_id'
×
56

57
        return {course_key: course}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc