feat(academic): allow subjects to be associated with multiple careers (v3.8.21)
This commit is contained in:
@@ -7,7 +7,7 @@ from typing import Any
|
||||
from database import db, get_db, engine, SessionLocal, session
|
||||
from config.config import Config
|
||||
|
||||
__version__ = "3.8.20"
|
||||
__version__ = "3.8.21"
|
||||
|
||||
class DummyContext:
|
||||
def __enter__(self):
|
||||
|
||||
+12
-10
@@ -311,10 +311,6 @@ async def update_subject(
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
|
||||
if 'career_id' in data:
|
||||
c_id = data['career_id']
|
||||
subject.career_id = int(c_id) if c_id else None
|
||||
|
||||
if 'career_ids' in data:
|
||||
career_ids = data.get('career_ids')
|
||||
if isinstance(career_ids, str):
|
||||
@@ -326,14 +322,20 @@ async def update_subject(
|
||||
if c_id_list:
|
||||
c_objs = Career.query.filter(Career.id.in_(c_id_list)).all()
|
||||
subject.careers = c_objs
|
||||
if c_objs and not subject.career_id:
|
||||
subject.career_id = c_objs[0].id
|
||||
if not subject.career_id or subject.career_id not in c_id_list:
|
||||
subject.career_id = c_objs[0].id if c_objs else None
|
||||
else:
|
||||
subject.careers = []
|
||||
subject.career_id = None
|
||||
elif 'career_id' in data:
|
||||
c_id = data['career_id']
|
||||
subject.career_id = int(c_id) if c_id else None
|
||||
if subject.career_id:
|
||||
c_obj = Career.query.get(subject.career_id)
|
||||
if c_obj:
|
||||
subject.careers = [c_obj]
|
||||
else:
|
||||
subject.careers = []
|
||||
elif 'career_id' in data and subject.career_id:
|
||||
c_obj = Career.query.get(subject.career_id)
|
||||
if c_obj and c_obj not in subject.careers:
|
||||
subject.careers = [c_obj]
|
||||
|
||||
if 'description' in data:
|
||||
subject.description = (data['description'] or '').strip()
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name="edu-space-admin",
|
||||
version="3.8.20",
|
||||
version="3.8.21",
|
||||
description="Administrative interface for Edu-Space Classroom Management System (FastAPI ASGI Core)",
|
||||
author="Edu-Space Development Team",
|
||||
author_email="admin@edu-space.com",
|
||||
|
||||
@@ -228,3 +228,59 @@ def test_system_reset_success_preserves_users(client, auth_headers):
|
||||
assert len(reset_logs) == 1
|
||||
assert reset_logs[0].user_email == 'admin_abm@unicaba.edu.ar'
|
||||
|
||||
|
||||
def test_subject_multiple_careers_create_and_update(client, auth_headers):
|
||||
from app.models.career import Career
|
||||
|
||||
# 1. Crear carreras
|
||||
c1 = Career(name='Licenciatura en Ciencia de Datos', code='DATOS')
|
||||
c2 = Career(name='Tecnicatura en Videojuegos', code='VJ')
|
||||
c3 = Career(name='Tecnicatura en Desarrollo Digital', code='TEC-DIG')
|
||||
db.session.add_all([c1, c2, c3])
|
||||
db.session.commit()
|
||||
|
||||
# 2. Crear una materia con múltiples carreras asociadas (c1 y c2)
|
||||
payload_create = {
|
||||
'code': 'SUBJ-MULTI-1',
|
||||
'name': 'Programación Interactiva Avanzada',
|
||||
'credits': 4,
|
||||
'career_ids': [c1.id, c2.id],
|
||||
'department': 'Tecnología',
|
||||
'description': 'Materia compartida entre Datos y Videojuegos'
|
||||
}
|
||||
res_create = client.post('/api/v1/subjects', headers=auth_headers, json=payload_create)
|
||||
assert res_create.status_code == 201
|
||||
data_create = res_create.get_json()
|
||||
assert data_create['status'] == 'success'
|
||||
subj_data = data_create['subject']
|
||||
assert subj_data['code'] == 'SUBJ-MULTI-1'
|
||||
assert len(subj_data['careers']) == 2
|
||||
career_names = [c['name'] for c in subj_data['careers']]
|
||||
assert 'Licenciatura en Ciencia de Datos' in career_names
|
||||
assert 'Tecnicatura en Videojuegos' in career_names
|
||||
|
||||
subj_id = subj_data['id']
|
||||
|
||||
# 3. Actualizar la materia para asociarla a c2 y c3
|
||||
payload_update = {
|
||||
'career_ids': [c2.id, c3.id],
|
||||
'description': 'Actualizada a Videojuegos y Desarrollo Digital'
|
||||
}
|
||||
res_update = client.put(f'/api/v1/subjects/{subj_id}', headers=auth_headers, json=payload_update)
|
||||
assert res_update.status_code == 200
|
||||
data_update = res_update.get_json()
|
||||
subj_updated = data_update['subject']
|
||||
assert len(subj_updated['careers']) == 2
|
||||
updated_career_names = [c['name'] for c in subj_updated['careers']]
|
||||
assert 'Tecnicatura en Videojuegos' in updated_career_names
|
||||
assert 'Tecnicatura en Desarrollo Digital' in updated_career_names
|
||||
assert 'Licenciatura en Ciencia de Datos' not in updated_career_names
|
||||
|
||||
# 4. Verificar que GET /subjects lista la materia con sus carreras
|
||||
res_get = client.get('/api/v1/subjects', headers=auth_headers)
|
||||
assert res_get.status_code == 200
|
||||
all_subjects = res_get.get_json()['subjects']
|
||||
found = next((s for s in all_subjects if s['id'] == subj_id), None)
|
||||
assert found is not None
|
||||
assert len(found['careers']) == 2
|
||||
|
||||
|
||||
Reference in New Issue
Block a user