def get_degree_template(template_id):
    template = fetch_degree_template(template_id).to_api_json(include_courses=True)
    parent_template_id = template['parentTemplateId']
    parent_template = DegreeProgressTemplate.find_by_id(parent_template_id) if parent_template_id else None
    if parent_template:
        template['parentTemplateUpdatedAt'] = _isoformat(parent_template.updated_at)
    return tolerant_jsonify(template)
Beispiel #2
0
    def test_edit_degree_note(self, client, fake_auth, mock_note):
        """Authorized user can edit a degree note."""
        template_id = mock_note.template_id
        original_updated_at = DegreeProgressTemplate.find_by_id(
            template_id).updated_at

        fake_auth.login(coe_advisor_read_write_uid)
        body = 'Stróż pchnął kość w quiz gędźb vel fax myjń.'
        api_json = self._api_update_degree_note(client,
                                                body=body,
                                                template_id=template_id)
        assert api_json['templateId']
        assert api_json['body'] == body
        # Verify update of updated_at
        assert DegreeProgressTemplate.find_by_id(
            template_id).updated_at != original_updated_at
 def test_delete(self, client, fake_auth, mock_template):
     """COE advisor can delete degree category."""
     fake_auth.login(coe_advisor_read_write_uid)
     original_updated_at = mock_template.updated_at
     category = _api_create_category(
         category_type='Category',
         client=client,
         name='Blister in the sun',
         position=3,
         template_id=mock_template.id,
     )
     subcategory = _api_create_category(
         category_type='Subcategory',
         client=client,
         name='Gone Daddy Gone',
         parent_category_id=category['id'],
         position=3,
         template_id=mock_template.id,
     )
     course = _api_create_category(
         category_type='Course Requirement',
         client=client,
         name='Blister in the sun',
         parent_category_id=subcategory['id'],
         position=3,
         template_id=mock_template.id,
     )
     category_id = category['id']
     assert client.delete(f'/api/degree/category/{category_id}').status_code == 200
     # Verify that all were deleted.
     for object_id in (category_id, subcategory['id'], course['id']):
         assert client.get(f'/api/degree/category/{object_id}').status_code == 404
     # Verify update of updated_at
     std_commit(allow_test_environment=True)
     assert DegreeProgressTemplate.find_by_id(mock_template.id).updated_at != original_updated_at
def clone_degree_template(template_id, name=None, sid=None):
    template = DegreeProgressTemplate.find_by_id(template_id)
    if template_id and not template:
        raise ResourceNotFoundError(
            f'No template found with id={template_id}.')
    if name:
        validate_template_upsert(name=name, template_id=template_id)

    created_by = current_user.get_id()
    return clone(template, created_by, name=name, sid=sid)
Beispiel #5
0
 def test_create_batch(self, client, fake_auth, mock_template):
     """Authorized user can create a batch of degree checks."""
     fake_auth.login(coe_advisor_read_write_uid)
     student_sids = [
         coe_student_sid, '11667051', '7890123456', '9100000000'
     ]
     api_json = self._api_batch_degree_checks(client,
                                              sids=student_sids,
                                              template_id=mock_template.id)
     for sid in student_sids:
         assert api_json[sid]
         degree_check = DegreeProgressTemplate.find_by_id(api_json[sid])
         assert degree_check
         assert degree_check.student_sid == sid
def clone(template, created_by, name=None, sid=None):
    clone = DegreeProgressTemplate.create(
        advisor_dept_codes=dept_codes_where_advising(current_user),
        created_by=created_by,
        degree_name=name or template.degree_name,
        parent_template_id=template.id if sid else None,
        student_sid=sid,
    )
    unit_requirements_by_source_id = {}
    for unit_requirement in template.unit_requirements:
        source_id = unit_requirement.id
        unit_requirements_by_source_id[
            source_id] = DegreeProgressUnitRequirement.create(
                created_by=created_by,
                min_units=unit_requirement.min_units,
                name=unit_requirement.name,
                template_id=clone.id,
            )

    def _create_category(category_, parent_id):
        unit_requirement_ids = []
        for u in category_['unitRequirements']:
            source_id_ = u['id']
            cross_reference = unit_requirements_by_source_id[source_id_]
            unit_requirement_ids.append(cross_reference.id)
        return DegreeProgressCategory.create(
            category_type=category_['categoryType'],
            name=category_['name'],
            position=category_['position'],
            template_id=clone.id,
            course_units_lower=category_['unitsLower'],
            course_units_upper=category_['unitsUpper'],
            description=category_['description'],
            parent_category_id=parent_id,
            unit_requirement_ids=unit_requirement_ids,
        )

    for category in DegreeProgressCategory.get_categories(
            template_id=template.id):
        c = _create_category(category_=category, parent_id=None)
        for course in category['courseRequirements']:
            _create_category(category_=course, parent_id=c.id)
        for subcategory in category['subcategories']:
            s = _create_category(category_=subcategory, parent_id=c.id)
            for course in subcategory['courseRequirements']:
                _create_category(category_=course, parent_id=s.id)

    # TODO: Unit requirements?
    return DegreeProgressTemplate.find_by_id(clone.id)
Beispiel #7
0
 def test_assign_and_unassign_course(self, client, fake_auth):
     """User can assign and unassign a course."""
     advisor = AuthorizedUser.find_by_uid(coe_advisor_read_write_uid)
     fake_auth.login(advisor.uid)
     sid = '11667051'
     # Set up
     degree_check = DegreeProgressTemplate.create(
         advisor_dept_codes=['COENG'],
         created_by=advisor.id,
         degree_name=f'Degree check for {sid}',
         student_sid=sid,
     )
     original_updated_at = degree_check.updated_at
     category = DegreeProgressCategory.create(
         category_type='Category',
         name=f'Category for {sid}',
         position=1,
         template_id=degree_check.id,
     )
     std_commit(allow_test_environment=True)
     # Assign
     api_json = _api_get_degree(client, degree_check_id=degree_check.id)
     course_id = api_json['courses']['unassigned'][-1]['id']
     course = _api_assign_course(category_id=category.id,
                                 client=client,
                                 course_id=course_id)
     # Verify assignment
     api_json = _api_get_degree(client, degree_check_id=degree_check.id)
     assert course['categoryId'] == category.id
     assert course_id in [c['id'] for c in api_json['courses']['assigned']]
     assert course_id not in [
         c['id'] for c in api_json['courses']['unassigned']
     ]
     # Unassign
     _api_assign_course(category_id=None,
                        client=client,
                        course_id=course_id)
     api_json = _api_get_degree(client, degree_check_id=degree_check.id)
     assert course_id not in [
         c['id'] for c in api_json['courses']['assigned']
     ]
     assert course_id in [
         c['id'] for c in api_json['courses']['unassigned']
     ]
     # Verify update of updated_at
     assert DegreeProgressTemplate.find_by_id(
         degree_check.id).updated_at != original_updated_at
Beispiel #8
0
def get_students(template_id):
    params = request.get_json()
    sids = get_param(params, 'sids')
    if not sids:
        raise BadRequestError('sids is required.')
    template = DegreeProgressTemplate.find_by_id(template_id)
    if not template:
        raise ResourceNotFoundError('Degree template not found')
    degree_checks = DegreeProgressTemplate.get_student_degree_checks_by_parent_template_id(
        template_id, sids)
    sids = [d.student_sid for d in degree_checks]
    students = get_basic_student_data(sids)

    def _to_api_json(student):
        return {
            'sid': student['sid'],
            'uid': student['uid'],
            'firstName': student['first_name'],
            'lastName': student['last_name'],
        }

    return tolerant_jsonify([_to_api_json(student) for student in students])
def fetch_degree_template(template_id):
    template = DegreeProgressTemplate.find_by_id(template_id)
    if not template:
        raise ResourceNotFoundError(
            f'No template found with id={template_id}.')
    return template
Beispiel #10
0
    def test_assign_and_unassign_course(self, app, client, fake_auth):
        """User can assign and unassign a course."""
        advisor = AuthorizedUser.find_by_uid(coe_advisor_read_write_uid)
        fake_auth.login(advisor.uid)
        sid = '11667051'
        # Set up
        degree_check = DegreeProgressTemplate.create(
            advisor_dept_codes=['COENG'],
            created_by=advisor.id,
            degree_name=f'Degree check for {sid}',
            student_sid=sid,
        )
        original_updated_at = degree_check.updated_at
        category = DegreeProgressCategory.create(
            category_type='Category',
            name=f'Category for {sid}',
            position=1,
            template_id=degree_check.id,
        )
        std_commit(allow_test_environment=True)
        # Assign
        api_json = _api_get_degree(client, degree_check_id=degree_check.id)
        course_id = api_json['courses']['unassigned'][-1]['id']
        course = _api_assign_course(category_id=category.id,
                                    client=client,
                                    course_id=course_id)
        original_grade = course['grade']
        assert original_grade == 'P'

        # Verify assignment
        api_json = _api_get_degree(client, degree_check_id=degree_check.id)
        assert course['categoryId'] == category.id
        assert course_id in [c['id'] for c in api_json['courses']['assigned']]
        assert course_id not in [
            c['id'] for c in api_json['courses']['unassigned']
        ]

        # Modify grade in data lake and verify that assigned course receives the update
        modified_grade = 'C+'
        _change_grade_in_data_loch(
            app=app,
            grade=modified_grade,
            section_id=course['sectionId'],
            sid=sid,
            term_id=course['termId'],
        )
        api_json = _api_get_degree(client, degree_check_id=degree_check.id)
        assigned_course = api_json['courses']['assigned'][0]
        assert assigned_course['id'] == course_id
        assert assigned_course['grade'] == modified_grade
        _change_grade_in_data_loch(
            app=app,
            grade=original_grade,
            section_id=course['sectionId'],
            sid=sid,
            term_id=course['termId'],
        )

        # Unassign
        _api_assign_course(category_id=None,
                           client=client,
                           course_id=course_id)
        api_json = _api_get_degree(client, degree_check_id=degree_check.id)
        assert course_id not in [
            c['id'] for c in api_json['courses']['assigned']
        ]
        unassigned_course = api_json['courses']['unassigned'][-1]
        assert unassigned_course['id'] == course_id
        assert unassigned_course['grade'] == original_grade
        # Verify update of updated_at
        assert DegreeProgressTemplate.find_by_id(
            degree_check.id).updated_at != original_updated_at