def test_create_nonunique_unit_requirements(self, db): """Requires unit requirements in a single template to have unique names.""" coe_advisor_id = AuthorizedUser.get_id_per_uid(coe_advisor_uid) template = DegreeProgressTemplate.create( advisor_dept_codes=['COENG'], created_by=coe_advisor_id, degree_name='Celtic Studies BA 2021', ) name = 'Celtic Requirements' unit_requirement = DegreeProgressUnitRequirement.create( created_by=coe_advisor_id, min_units=70, name=name, template_id=template.id, ) assert unit_requirement with pytest.raises(IntegrityError): DegreeProgressUnitRequirement.create( created_by=coe_advisor_id, min_units=53, name=name, template_id=template.id, ) db.session.rollback()
def test_update_template(self, client, fake_auth): """Authorized user can edit a template.""" user = AuthorizedUser.find_by_uid(coe_advisor_read_write_uid) fake_auth.login(user.uid) template = DegreeProgressTemplate.create( advisor_dept_codes=get_dept_codes(user), created_by=user.id, degree_name='Boogie Down Productions', ) for index in (1, 2, 3): DegreeProgressUnitRequirement.create( created_by=user.id, min_units=index, name=f'Unit Requirement #{index}', template_id=template.id, ) updated_name = 'KRS One' api_json = self._api_clone_template(client=client, name=updated_name, template_id=template.id) assert api_json['id'] != template.id assert api_json['name'] == updated_name assert len(api_json['unitRequirements']) == 3
def delete_unit_requirement(unit_requirement_id): unit_requirement = DegreeProgressUnitRequirement.find_by_id(unit_requirement_id) if unit_requirement: DegreeProgressUnitRequirement.delete(unit_requirement_id) # Update updated_at date of top-level record DegreeProgressTemplate.refresh_updated_at(unit_requirement.template_id, current_user.get_id()) return tolerant_jsonify({'message': f'Unit requirement {unit_requirement_id} deleted'}), 200 else: raise ResourceNotFoundError(f'No unit_requirement found with id={unit_requirement_id}.')
def _create_unit_requirement(name, template_id, user, min_units=3): return DegreeProgressUnitRequirement.create( created_by=user.id, min_units=min_units, name=name, template_id=template_id, )
def test_create_unit_requirement(self): coe_advisor_id = AuthorizedUser.get_id_per_uid(coe_advisor_uid) template = DegreeProgressTemplate.create( advisor_dept_codes=['COENG'], created_by=coe_advisor_id, degree_name='Celtic Studies BA 2021', ) min_units = 45 name = 'Celtic Requirements' unit_requirement = DegreeProgressUnitRequirement.create( created_by=coe_advisor_id, min_units=min_units, name=name, template_id=template.id, ) assert unit_requirement assert unit_requirement.__repr__( ) == f"""<DegreeProgressUnitRequirement id={unit_requirement.id}, name={name}, min_units={min_units}, template_id={template.id}, created_at={unit_requirement.created_at}, created_by={coe_advisor_id}, updated_at={unit_requirement.updated_at}, updated_by={coe_advisor_id}>""" assert template.unit_requirements assert len(template.unit_requirements) == 1 assert unit_requirement.template
def mock_unit_requirement(): template = DegreeProgressTemplate.create( advisor_dept_codes=['COENG'], created_by=AuthorizedUser.get_id_per_uid(coe_advisor_read_write_uid), degree_name='Ursinology 2025', ) return DegreeProgressUnitRequirement.create( created_by=AuthorizedUser.get_id_per_uid(coe_advisor_read_write_uid), min_units=16, name='Aureum Ursi', template_id=template.id, )
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)
def update_unit_requirement(unit_requirement_id): params = request.get_json() name = params.get('name') min_units = params.get('minUnits') if not name or not min_units: raise BadRequestError('Unit requirement \'name\' and \'minUnits\' must be provided.') unit_requirement = DegreeProgressUnitRequirement.update( id_=unit_requirement_id, min_units=min_units, name=name, updated_by=current_user.get_id(), ) # Update updated_at date of top-level record DegreeProgressTemplate.refresh_updated_at(unit_requirement.template_id, current_user.get_id()) return tolerant_jsonify(unit_requirement.to_api_json())