| from sqlalchemy import create_engine |
| from sqlalchemy.orm import sessionmaker |
| from models.assessment import Assessment |
| from models.job import Job |
| from models.user import User |
| from models.base import Base |
| from config import settings |
| from schemas.assessment import AssessmentCreate, AssessmentQuestion, AssessmentQuestionOption |
| from services.assessment_service import create_assessment |
| from uuid import uuid4 |
|
|
| |
| engine = create_engine(settings.database_url, connect_args={"check_same_thread": False}) |
| TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) |
|
|
| def test_create_assessment_with_questions(): |
| """ |
| Test creating an assessment with questions |
| """ |
| |
| Base.metadata.create_all(bind=engine) |
| |
| |
| db = TestingSessionLocal() |
| |
| |
| test_job = Job( |
| id=str(uuid4()), |
| title="Software Engineer", |
| seniority="mid", |
| description="Test job for assessment", |
| skill_categories='["programming", "python", "fastapi"]' |
| ) |
| db.add(test_job) |
| db.commit() |
| |
| |
| sample_questions = [ |
| AssessmentQuestion( |
| id=str(uuid4()), |
| text="What is Python?", |
| weight=3, |
| skill_categories=["programming", "python"], |
| type="choose_one", |
| options=[ |
| AssessmentQuestionOption(text="A snake", value="a"), |
| AssessmentQuestionOption(text="A programming language", value="b"), |
| AssessmentQuestionOption(text="An IDE", value="c") |
| ], |
| correct_options=["b"] |
| ), |
| AssessmentQuestion( |
| id=str(uuid4()), |
| text="What is FastAPI?", |
| weight=4, |
| skill_categories=["web development", "python"], |
| type="text_based", |
| options=[], |
| correct_options=[] |
| ) |
| ] |
| |
| |
| assessment_data = AssessmentCreate( |
| title="Python Programming Skills Assessment", |
| passing_score=70, |
| questions=sample_questions, |
| additional_note="This is a test assessment" |
| ) |
| |
| |
| created_assessment = create_assessment(db, test_job.id, assessment_data) |
| |
| |
| print(f"Created assessment ID: {created_assessment.id}") |
| print(f"Assessment title: {created_assessment.title}") |
| print(f"Assessment passing score: {created_assessment.passing_score}") |
| print(f"Questions stored: {created_assessment.questions}") |
| |
| |
| db.close() |
| |
| print("\nTest completed successfully!") |
|
|
| if __name__ == "__main__": |
| test_create_assessment_with_questions() |