Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/ai/data/CategoryRecommendationQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def __init__(self, sqs_client: boto3.client, queue_url: str):
self.sqs = sqs_client
self.queue_url = queue_url

def send_message(self, request_id: str, title: str, user_id: str):
def send_message(self, request_id: str, file_id: str, user_id: str):
try:
message_body = {
'request_type': 'category_recommendation',
'request_id': request_id,
'user_id': str(user_id),
'payload': {
'title': title
'file_id': file_id
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/ai/data/CategoryRecommendationRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def __init__(self, client: MongoClient):
self.db = client.get_database()
self.collection: Collection = self.db.get_collection('category_recommendations')

def create_recommendation_request(self, title: str, user_id: str) -> dict:
def create_recommendation_request(self, file_id: str, user_id: str) -> dict:
document = {
"title": title,
"file_id": file_id,
"user_id": user_id,
"is_completed": False,
"created_at": self.get_current_time()
Expand Down
2 changes: 1 addition & 1 deletion src/main/ai/models/CategoryRecommendation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class CategoryRecommendationRequest(BaseModel):
title: str
file_id: str


class CategoryRecommendationResponse(BaseModel):
Expand Down
4 changes: 2 additions & 2 deletions src/main/ai/router/AIPublicAPIRouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def create_category_recommendation_request(
service: CategoryRecommendationService = Depends(get_category_recommendation_service)
):
"""
자료 제목에 따른 추천 카테고리 요청
업로드한 파일에 따른 추천 카테고리 요청
"""
return service.create_recommendation_request(request, user_id)

Expand All @@ -34,7 +34,7 @@ async def get_category_recommendation_status(
service: CategoryRecommendationService = Depends(get_category_recommendation_service)
):
"""
자료 제목에 따른 추천 카테고리 조회
업로드한 파일에 따른 추천 카테고리 조회
"""
result = service.get_recommendation_status(request_id, user_id)

Expand Down
4 changes: 2 additions & 2 deletions src/main/ai/service/CategoryRecommendationService.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, repository: CategoryRecommendationRepository, queue: Category
def create_recommendation_request(self, request: CategoryRecommendationRequest, user_id: uuid.UUID) -> CategoryRecommendationResponse:
# MongoDB에 저장 - ObjectId 자동 생성
document = self.repository.create_recommendation_request(
title=request.title,
file_id=request.file_id,
user_id=str(user_id)
)

Expand All @@ -30,7 +30,7 @@ def create_recommendation_request(self, request: CategoryRecommendationRequest,
# 메시지 발행
self.queue.send_message(
request_id=request_id,
title=request.title,
file_id=request.file_id,
user_id=str(user_id)
)

Expand Down
12 changes: 6 additions & 6 deletions src/tests/ai/data/test_category_recommendation_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ def setup_method(self):
def test_send_message_success(self):
# given
request_id = "test-request-id"
title = "테스트 제목"
file_id = "67dd86ac60a0a6d929904d47"
user_id = "test-user-id"

# SQS 응답 설정
expected_response = {"MessageId": "1234567890"}
self.mock_sqs_client.send_message.return_value = expected_response

# when
result = self.queue.send_message(request_id, title, user_id)
result = self.queue.send_message(request_id, file_id, user_id)

# then
expected_message_body = {
'request_type': 'category_recommendation',
'request_id': request_id,
'user_id': user_id,
'payload': {
'title': title
'file_id': file_id
}
}

Expand All @@ -47,15 +47,15 @@ def test_send_message_success(self):
def test_send_message_with_exception(self):
# given
request_id = "test-request-id"
title = "테스트 제목"
file_id = "67dd86ac60a0a6d929904d47"
user_id = "test-user-id"

# SQS 예외 발생 설정
self.mock_sqs_client.send_message.side_effect = Exception("SQS error")

# when/then
with pytest.raises(Exception) as e:
self.queue.send_message(request_id, title, user_id)
self.queue.send_message(request_id, file_id, user_id)

assert "SQS error" in str(e.value)

Expand All @@ -64,7 +64,7 @@ def test_send_message_with_exception(self):
'request_id': request_id,
'user_id': user_id,
'payload': {
'title': title
'file_id': file_id
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/tests/ai/data/test_category_recommendation_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ def teardown_method(self):

def test_create_recommendation_request(self):
# given
title = "테스트 제목"
file_id = "67dd86ac60a0a6d929904d47"
user_id = "test-user-id"
mock_id = ObjectId("6123456789abcdef01234567")

# MongoDB insert_one의 응답 설정
self.mock_collection.insert_one.return_value = MagicMock(inserted_id=mock_id)

# when
result = self.repository.create_recommendation_request(title, user_id)
result = self.repository.create_recommendation_request(file_id, user_id)

# then
expected_doc = {
"title": title,
"file_id": file_id,
"user_id": user_id,
"is_completed": False,
"created_at": datetime(2023, 1, 1, tzinfo=timezone.utc),
Expand All @@ -61,7 +61,7 @@ def test_get_recommendation_by_id(self):
user_id = "test-user-id"
expected_result = {
"_id": ObjectId(request_id),
"title": "테스트 제목",
"file_id": "67dd86ac60a0a6d929904d47",
"user_id": user_id,
"is_completed": False,
"created_at": datetime(2023, 1, 1, tzinfo=timezone.utc)
Expand Down Expand Up @@ -102,7 +102,7 @@ def test_update_recommendation_result(self):

expected_doc = {
"_id": ObjectId(request_id),
"title": "테스트 제목",
"file_id": "67dd86ac60a0a6d929904d47",
"user_id": "test-user-id",
"is_completed": True,
"predicted_category": predicted_category,
Expand Down
8 changes: 4 additions & 4 deletions src/tests/ai/models/test_category_recommendation_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
class TestCategoryRecommendationModels:
def test_category_recommendation_request_valid(self):
# given
title = "테스트 제목"
file_id = "67dd86ac60a0a6d929904d47"

# when
model = CategoryRecommendationRequest(title=title)
model = CategoryRecommendationRequest(file_id=file_id)

# then
assert model.title == title
assert model.file_id == file_id

def test_category_recommendation_request_invalid(self):
# when/then - 제목이 없는 경우 검증 오류
# when/then - 파일 ID가 없는 경우 검증 오류
with pytest.raises(ValidationError):
CategoryRecommendationRequest()

Expand Down
18 changes: 9 additions & 9 deletions src/tests/ai/router/test_ai_public_api_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def client():
class TestAIPublicAPIRouter:
def setup_method(self):
# 테스트 공통 데이터
self.test_title = "테스트 제목"
self.test_file_id = "67dd86ac60a0a6d929904d47"
self.test_user_id = uuid.UUID("12345678-1234-5678-1234-567812345678")
self.test_request_id = "6123456789abcdef01234567"
self.test_file_id = "7123456789abcdef01234567"
self.test_check_file_id = "7123456789abcdef01234567"

def test_create_category_recommendation_request(self, client):
# given
request_data = {
"title": self.test_title
"file_id": self.test_file_id
}

# 서비스 응답 모의 설정
Expand Down Expand Up @@ -107,23 +107,23 @@ def test_get_file_duplicate_check_status_exists(self, client):
# 서비스 응답 설정
mock_service.return_value = FileDuplicateCheckStatusResponse(
request_id=self.test_request_id,
file_id=self.test_file_id,
file_id=self.test_check_file_id,
is_completed=True,
is_duplicated=False
)

# when
response = client.get(f"/ai/file-duplicate-checks?file_id={self.test_file_id}")
response = client.get(f"/ai/file-duplicate-checks?file_id={self.test_check_file_id}")

# then
assert response.status_code == 200
assert response.json() == {
"request_id": self.test_request_id,
"file_id": self.test_file_id,
"file_id": self.test_check_file_id,
"is_completed": True,
"is_duplicated": False
}
mock_service.assert_called_once_with(self.test_file_id, str(self.test_user_id))
mock_service.assert_called_once_with(self.test_check_file_id, str(self.test_user_id))

def test_get_file_duplicate_check_status_not_found(self, client):
# given
Expand All @@ -133,11 +133,11 @@ def test_get_file_duplicate_check_status_not_found(self, client):
mock_service.return_value = None

# when
response = client.get(f"/ai/file-duplicate-checks?file_id={self.test_file_id}")
response = client.get(f"/ai/file-duplicate-checks?file_id={self.test_check_file_id}")

# then
assert response.status_code == 404
assert response.json() == {
"detail": "요청을 찾을 수 없습니다. 존재하지 않는 ID입니다."
}
mock_service.assert_called_once_with(self.test_file_id, str(self.test_user_id))
mock_service.assert_called_once_with(self.test_check_file_id, str(self.test_user_id))
16 changes: 8 additions & 8 deletions src/tests/ai/service/test_category_recommendation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ def setup_method(self):
self.service = CategoryRecommendationService(self.mock_repository, self.mock_queue)

# 테스트 공통 데이터
self.test_title = "테스트 제목"
self.test_file_id = "67dd86ac60a0a6d929904d47"
self.test_user_id = uuid.UUID("12345678-1234-5678-1234-567812345678")
self.test_request_id = "6123456789abcdef01234567"
self.test_object_id = ObjectId(self.test_request_id)

def test_create_recommendation_request(self):
# given
request = CategoryRecommendationRequest(title=self.test_title)
request = CategoryRecommendationRequest(file_id=self.test_file_id)

# 리포지토리 응답 설정
mongo_document = {
"_id": self.test_object_id,
"title": self.test_title,
"file_id": self.test_file_id,
"user_id": str(self.test_user_id),
"is_completed": False,
"created_at": datetime(2023, 1, 1, tzinfo=timezone.utc)
Expand All @@ -47,13 +47,13 @@ def test_create_recommendation_request(self):

# then
self.mock_repository.create_recommendation_request.assert_called_once_with(
title=self.test_title,
file_id=self.test_file_id,
user_id=str(self.test_user_id)
)

self.mock_queue.send_message.assert_called_once_with(
request_id=self.test_request_id,
title=self.test_title,
file_id=self.test_file_id,
user_id=str(self.test_user_id)
)

Expand All @@ -65,7 +65,7 @@ def test_get_recommendation_status_exists(self):
# 리포지토리 응답 설정 - 완료되지 않은 추천
mongo_document = {
"_id": self.test_object_id,
"title": self.test_title,
"file_id": self.test_file_id,
"user_id": str(self.test_user_id),
"is_completed": False,
"created_at": datetime(2023, 1, 1, tzinfo=timezone.utc)
Expand All @@ -90,7 +90,7 @@ def test_get_recommendation_status_completed(self):
# 리포지토리 응답 설정 - 완료된 추천
mongo_document = {
"_id": self.test_object_id,
"title": self.test_title,
"file_id": self.test_file_id,
"user_id": str(self.test_user_id),
"is_completed": True,
"predicted_category": "기술",
Expand Down Expand Up @@ -134,7 +134,7 @@ def test_update_recommendation_result_success(self):
# 리포지토리 응답 설정
updated_document = {
"_id": self.test_object_id,
"title": self.test_title,
"file_id": self.test_file_id,
"user_id": str(self.test_user_id),
"is_completed": True,
"predicted_category": "기술",
Expand Down