-
Notifications
You must be signed in to change notification settings - Fork 0
[25.07.18 / TASK-225] Test - 주간 뉴스레터 배치 단위 테스트 추가 #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c93b0ea
test: 주간 뉴스레터 배치 단위 테스트 추가
ooheunda ef079bd
modify: 코드래빗 리뷰 반영
ooheunda f67770a
modify: logger 모킹 추가 및 리팩토링
ooheunda 8d20845
modify: setup django 모킹 방식, date 관련 fixture 수정
ooheunda e028e4a
test: delete_old_maillogs 통합 테스트 추가
ooheunda 03bd7c6
test: 템플릿 렌더링 output 테스트 추가
ooheunda 4521442
modify: sent_at 필터 조건 주석 추가
ooheunda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import sys | ||
import uuid | ||
from datetime import date, timedelta | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
from django.conf import settings | ||
from django.contrib.admin.sites import AdminSite | ||
from django.http import HttpRequest | ||
|
||
|
@@ -13,8 +14,25 @@ | |
UserWeeklyTrend, | ||
WeeklyTrend, | ||
WeeklyTrendInsight, | ||
WeeklyUserReminder, | ||
WeeklyUserStats, | ||
WeeklyUserTrendInsight, | ||
) | ||
from insight.schemas import Newsletter | ||
from modules.mail.schemas import EmailMessage | ||
from users.models import User | ||
from utils.utils import get_previous_week_range | ||
|
||
|
||
@pytest.fixture | ||
def mock_setup_django(): | ||
"""setup_django 모듈 모킹""" | ||
sys.modules["setup_django"] = MagicMock() | ||
try: | ||
yield sys.modules["setup_django"] | ||
finally: | ||
# 테스트 후 정리 | ||
del sys.modules["setup_django"] | ||
|
||
|
||
@pytest.fixture | ||
|
@@ -26,6 +44,7 @@ def user(db): | |
refresh_token="test-refresh-token", | ||
group_id=1, | ||
email="[email protected]", | ||
username="test_user", | ||
is_active=True, | ||
) | ||
|
||
|
@@ -88,6 +107,26 @@ def sample_trending_items(): | |
] | ||
|
||
|
||
@pytest.fixture | ||
def sample_weekly_user_stats(): | ||
"""테스트용 주간 사용자 통계 데이터""" | ||
return WeeklyUserStats( | ||
posts=20, | ||
new_posts=3, | ||
views=100, | ||
likes=10, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def sample_weekly_user_reminder(): | ||
"""테스트용 주간 사용자 리마인더 데이터""" | ||
return WeeklyUserReminder( | ||
title="Django 20주년 축하하기", | ||
days_ago=12, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def sample_weekly_trend_insight(sample_trend_analysis, sample_trending_items): | ||
"""테스트용 주간 트렌드 인사이트 데이터""" | ||
|
@@ -97,14 +136,49 @@ def sample_weekly_trend_insight(sample_trend_analysis, sample_trending_items): | |
) | ||
|
||
|
||
@pytest.fixture | ||
def sample_weekly_user_trend_insight( | ||
sample_trend_analysis, | ||
sample_trending_items, | ||
sample_weekly_user_stats, | ||
sample_weekly_user_reminder, | ||
): | ||
"""테스트용 사용자 주간 트렌드 인사이트 데이터""" | ||
return WeeklyUserTrendInsight( | ||
trending_summary=sample_trending_items, | ||
trend_analysis=sample_trend_analysis, | ||
user_weekly_stats=sample_weekly_user_stats, | ||
user_weekly_reminder=sample_weekly_user_reminder, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def sample_newsletter(user): | ||
"""테스트용 뉴스레터 객체 생성""" | ||
return Newsletter( | ||
user_id=user.id, | ||
email_message=EmailMessage( | ||
to=[user.email], | ||
from_email=settings.DEFAULT_FROM_EMAIL, | ||
subject="Test Newsletter", | ||
text_body="Test content", | ||
html_body="<div>Test content</div>", | ||
), | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def sample_newsletters(sample_newsletter): | ||
"""테스트용 뉴스레터 리스트 생성""" | ||
return [sample_newsletter] | ||
|
||
|
||
@pytest.fixture | ||
def weekly_trend( | ||
db, sample_weekly_trend_insight: WeeklyTrendInsight | ||
) -> WeeklyTrend: | ||
"""주간 트렌드 생성""" | ||
today = date.today() | ||
week_start = today - timedelta(days=today.weekday()) | ||
week_end = week_start + timedelta(days=6) | ||
week_start, week_end = get_previous_week_range() | ||
|
||
return WeeklyTrend.objects.create( | ||
week_start_date=week_start, | ||
|
@@ -115,14 +189,14 @@ def weekly_trend( | |
|
||
@pytest.fixture | ||
def user_weekly_trend( | ||
db, user, sample_weekly_trend_insight: WeeklyTrendInsight | ||
db, user, sample_weekly_user_trend_insight: WeeklyUserTrendInsight | ||
) -> UserWeeklyTrend: | ||
"""사용자 주간 트렌드 생성""" | ||
today = date.today() | ||
week_start = today - timedelta(days=today.weekday()) | ||
week_end = week_start + timedelta(days=6) | ||
week_start, week_end = get_previous_week_range() | ||
|
||
insight_dict = sample_weekly_user_trend_insight.to_json_dict() | ||
insight_dict["user_weekly_reminder"] = {} # 주간 글 작성 사용자 | ||
|
||
insight_dict = sample_weekly_trend_insight.to_json_dict() | ||
# 사용자 인사이트는 제목을 조금 다르게 설정 | ||
if insight_dict["trending_summary"]: | ||
insight_dict["trending_summary"][0]["title"] = "Django 모델 최적화하기" | ||
|
@@ -138,12 +212,30 @@ def user_weekly_trend( | |
) | ||
|
||
|
||
@pytest.fixture | ||
def inactive_user_weekly_trend( | ||
db, user, sample_weekly_user_trend_insight: WeeklyUserTrendInsight | ||
): | ||
"""주간 글 미작성 사용자 주간 트렌드 생성""" | ||
week_start, week_end = get_previous_week_range() | ||
|
||
insight_dict = sample_weekly_user_trend_insight.to_json_dict() | ||
insight_dict["trending_summary"] = [] | ||
insight_dict["trend_analysis"] = {} | ||
insight_dict["user_weekly_stats"]["new_posts"] = 0 | ||
|
||
return UserWeeklyTrend.objects.create( | ||
user=user, | ||
week_start_date=week_start, | ||
week_end_date=week_end, | ||
insight=insight_dict, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def empty_insight_weekly_trend(db): | ||
"""빈 인사이트를 가진 주간 트렌드""" | ||
today = date.today() | ||
week_start = today - timedelta(days=today.weekday()) | ||
week_end = week_start + timedelta(days=6) | ||
week_start, week_end = get_previous_week_range() | ||
|
||
return WeeklyTrend.objects.create( | ||
week_start_date=week_start, week_end_date=week_end, insight={} | ||
|
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.