diff --git a/insight/tasks/weekly_newsletter_batch.py b/insight/tasks/weekly_newsletter_batch.py index 8201da8..add0cbf 100644 --- a/insight/tasks/weekly_newsletter_batch.py +++ b/insight/tasks/weekly_newsletter_batch.py @@ -145,8 +145,8 @@ def _get_weekly_trend_html(self) -> str: # 템플릿 렌더링이 제대로 되지 않은 경우 배치 종료 if ( - "이 주의 트렌딩 글" not in weekly_trend_html - or "트렌드 분석" not in weekly_trend_html + "이번 주의 트렌딩 글" not in weekly_trend_html + or "주간 트렌드 분석" not in weekly_trend_html ): logger.error( f"Failed to build weekly trend HTML for newsletter #{weekly_trend['id']}" diff --git a/insight/tests/conftest.py b/insight/tests/conftest.py index e0941a8..cc936b2 100644 --- a/insight/tests/conftest.py +++ b/insight/tests/conftest.py @@ -160,9 +160,9 @@ def sample_newsletter(user): email_message=EmailMessage( to=[user.email], from_email=settings.DEFAULT_FROM_EMAIL, - subject="Test Newsletter", - text_body="Test content", - html_body="
Test content
", + subject="벨로그 대시보드 주간 뉴스레터 #1", + text_body="Weekly Report Test content", + html_body="
Weekly Report
Velog Dashboard
활동 리포트
대시보드 보러가기
", ), ) diff --git a/insight/tests/tasks/test_weekly_newsletter_batch.py b/insight/tests/tasks/test_weekly_newsletter_batch.py index c33df5e..794c9ab 100644 --- a/insight/tests/tasks/test_weekly_newsletter_batch.py +++ b/insight/tests/tasks/test_weekly_newsletter_batch.py @@ -196,6 +196,8 @@ def test_build_newsletters_success( assert len(newsletters) == 1 assert newsletters[0].user_id == user.id assert newsletters[0].email_message.to[0] == user.email + # 제목 포맷 검증 + assert "벨로그 대시보드 주간 뉴스레터" in newsletters[0].email_message.subject @patch("insight.tasks.weekly_newsletter_batch.logger") def test_send_newsletters_success( diff --git a/insight/tests/tasks/test_weekly_newsletter_template.py b/insight/tests/tasks/test_weekly_newsletter_template.py index b798558..fef2aa4 100644 --- a/insight/tests/tasks/test_weekly_newsletter_template.py +++ b/insight/tests/tasks/test_weekly_newsletter_template.py @@ -61,8 +61,9 @@ def test_get_weekly_trend_html_success( assert trending_summary[0]["title"] in weekly_trend_html assert trend_analysis["insights"] in weekly_trend_html - assert "이 주의 트렌딩 글" in weekly_trend_html - assert "트렌드 분석" in weekly_trend_html + assert "벨로그 주간 트렌드" in weekly_trend_html + assert "이번 주의 트렌딩 글" in weekly_trend_html + assert "주간 트렌드 분석" in weekly_trend_html @patch("insight.tasks.weekly_newsletter_batch.logger") @pytest.mark.django_db @@ -124,12 +125,11 @@ def test_get_user_weekly_trend_html_success( assert trending_summary[0]["title"] in user_weekly_trend_html assert trend_analysis["insights"] in user_weekly_trend_html - assert ( - f'{user_weekly_stats["new_posts"]}개의 글을 작성' - in user_weekly_trend_html - ) + assert f'{user_weekly_stats["new_posts"]}개의 글' in user_weekly_trend_html assert "마지막으로 글을 작성하신지" not in user_weekly_trend_html assert user.username in user_weekly_trend_html + assert "이번주에 작성한 글" in user_weekly_trend_html + assert "주간 내 활동 분석" in user_weekly_trend_html @patch("insight.tasks.weekly_newsletter_batch.logger") def test_get_user_weekly_trend_html_inactive_user( @@ -147,13 +147,16 @@ def test_get_user_weekly_trend_html_inactive_user( insight_data = inactive_user_weekly_trend.insight user_weekly_reminder = insight_data.get("user_weekly_reminder") - assert "이번주에 쓴 글" not in user_weekly_trend_html - assert "내 글을 분석해보면?" not in user_weekly_trend_html - assert "글을 작성하지 않으셨네요" in user_weekly_trend_html - assert ( - f'마지막으로 글을 작성하신지 {user_weekly_reminder["days_ago"]}일이 지났어요' - in user_weekly_trend_html - ) + assert "이번주에 작성한 글" not in user_weekly_trend_html + assert "주간 내 활동 분석" not in user_weekly_trend_html + # days_ago가 있는 경우와 없는 경우 모두 처리 + if user_weekly_reminder.get("days_ago"): + assert ( + f'😭 마지막으로 글을 작성하신지 {user_weekly_reminder["days_ago"]}일이 지났어요!' + in user_weekly_trend_html + ) + else: + assert "😭 글을 작성하지 않으셨네요!" in user_weekly_trend_html @patch("insight.tasks.weekly_newsletter_batch.logger") def test_get_user_weekly_trend_html_exception( @@ -193,6 +196,8 @@ def test_get_newsletter_html_success(self, mock_logger, newsletter_batch): assert weekly_trend_html in newsletter_html assert user_weekly_trend_html in newsletter_html assert "대시보드 보러가기" in newsletter_html + assert "Weekly Report" in newsletter_html + assert "Velog Dashboard" in newsletter_html @patch("insight.tasks.weekly_newsletter_batch.logger") def test_get_newsletter_html_expired_token_user( @@ -210,10 +215,12 @@ def test_get_newsletter_html_expired_token_user( ) # 템플릿 렌더링 검증 - assert "토큰이 만료" in newsletter_html + assert "🚨 잠시만요, 토큰이 만료된 것 같아요!" in newsletter_html + assert "토큰이 만료되어 정상적으로 통계를 수집할 수 없었어요" in newsletter_html assert weekly_trend_html in newsletter_html assert user_weekly_trend_html not in newsletter_html assert "대시보드 보러가기" in newsletter_html + assert "활동 리포트" in newsletter_html @patch("insight.tasks.weekly_newsletter_batch.logger") def test_get_newsletter_html_exception( diff --git a/templates/insights/index.html b/templates/insights/index.html index 2edd712..74a2751 100644 --- a/templates/insights/index.html +++ b/templates/insights/index.html @@ -1,74 +1,159 @@ - - - - - Velog Dashboard Weekly - - - - -
- - - - + + + +
-
-

- Velog Dashboard Weekly -

-

- {{s_date}} ~ {{e_date}} 사이의 트렌드를 전달해드려요. -

-
+ + + + + Velog Dashboard Weekly Report + + + + + - -
+ + + + +
+ +
+
+

+ Velog Dashboard +

+

+ Weekly Report +

+
+

+ {{s_date}} ~ {{e_date}} 사이의 트렌드를 전달해드려요 +

+
- + + -
- {% if is_expired_token_user %} -
-

- 🚨 잠깐, 토큰이 만료 되신 것 같아요! -

-

- 토큰이 만료되면 더 이상 통계를 수집할 수 없어요. 토큰을 재발급 받으시려면 - 여기에서 재로그인 해주세요. -

-
- {% endif %} +
+ {% if weekly_trend_html %} + {{weekly_trend_html}} + {% endif %} + + {% if not is_expired_token_user and user_weekly_trend_html %} + {{user_weekly_trend_html}} + {% endif %} - {% if weekly_trend_html %} - {{weekly_trend_html}} - {% endif %} - - {% if not is_expired_token_user and user_weekly_trend_html %} - {{user_weekly_trend_html}} - {% endif %} -
+ {% if is_expired_token_user %} + +
+

+ {% if user.username %} + {{user.username}}님의 활동 리포트 + {% else %} + 활동 리포트 + {% endif %} +

+
+

+ 🚨 잠시만요, 토큰이 만료된 것 같아요! +

+

+ 토큰이 만료되어 정상적으로 통계를 수집할 수 없었어요.
+ 토큰을 재발급받으시려면 + + 여기 + + 에서 다시 로그인해주세요. +

+
+
+ {% endif %} -
+
+
- -
-
- - \ No newline at end of file + + diff --git a/templates/insights/insight_preview.html b/templates/insights/insight_preview.html index 0bcf46f..a114327 100644 --- a/templates/insights/insight_preview.html +++ b/templates/insights/insight_preview.html @@ -1,7 +1,7 @@
{% if user and insight.user_weekly_stats %} -

사용자 주간 통계

-
+

사용자 주간 통계

+

전체 게시글 수: {{ insight.user_weekly_stats.posts }}

새 게시글 수: {{ insight.user_weekly_stats.new_posts }}

조회수 증가: {{ insight.user_weekly_stats.views }}

@@ -10,8 +10,8 @@

사용자 주간 통계

{% endif %} {% if insight.trend_analysis %} -

트렌드 분석

-
+

트렌드 분석

+
{% if insight.trend_analysis.hot_keywords %}

핵심 키워드

{{ insight.trend_analysis.hot_keywords|join:", " }}

@@ -21,42 +21,42 @@

핵심 키워드

{% if insight.trend_analysis.title_trends %}

제목 트렌드

-

{{ insight.trend_analysis.title_trends }}

+

{{ insight.trend_analysis.title_trends }}

{% endif %} {% if insight.trend_analysis.content_trends %}

콘텐츠 트렌드

-

{{ insight.trend_analysis.content_trends }}

+

{{ insight.trend_analysis.content_trends }}

{% endif %} {% if insight.trend_analysis.insights %}

인사이트

-

{{ insight.trend_analysis.insights }}

+

{{ insight.trend_analysis.insights }}

{% endif %}
{% endif %} {% if insight.trending_summary %} -

{% if user %}작성 게시글 요약{% else %}트렌딩 요약{% endif %}

+

{% if user %}작성 게시글 요약{% else %}트렌딩 요약{% endif %}

{% for item in insight.trending_summary %} -
-

{{ forloop.counter }}. {{ item.title }}

-

{{ item.summary }}

+
+

{{ forloop.counter }}. {{ item.title }}

+

{{ item.summary }}

{% if item.key_points %}

핵심 키워드: {{ item.key_points|join:", " }}

{% endif %}

작성자: {{ item.username }}

URL: https://velog.io/@{{item.username}}/{{item.slug}}

{% if item.thumbnail %} -

썸네일: 썸네일

+

썸네일: 썸네일

{% endif %}
{% endfor %} {% endif %} {% if user and insight.user_weekly_reminder %} -

리마인더

-
+

리마인더

+

마지막 작성 글: {{ insight.user_weekly_reminder.title }}

마지막 작성일: {{ insight.user_weekly_reminder.days_ago }}일 전

diff --git a/templates/insights/user_weekly_trend.html b/templates/insights/user_weekly_trend.html index 22223fe..5d9fc4a 100644 --- a/templates/insights/user_weekly_trend.html +++ b/templates/insights/user_weekly_trend.html @@ -1,135 +1,178 @@ -
- {% if insight.trending_summary or insight.user_weekly_stats or insight.reminder %} -
-

- 📝 - {% if user.username %} - {{user.username}}님의 - {% else %} - 내 - {% endif %} - 활동 리포트 -

- {% endif %} - - {% if insight.user_weekly_stats %} -
-

- 저번 주에는 - {% if insight.user_weekly_stats.new_posts > 0 %} - {{insight.user_weekly_stats.new_posts}}개의 글을 작성하셨네요! 👏
- {% else %} - 글을 작성하지 않으셨네요. 이번 주에는 멋진 글을 작성해보는 건 어떨까요? 화이팅! 💪
- {% endif %} - {% if insight.user_weekly_stats.views > 0 %} - 지난 한 주간 {{insight.user_weekly_stats.views}}명이 - {% if user.username %} - {{user.username}}님의 - {% else %} - 내 - {% endif %} - 포스트를 읽었어요.
- {% endif %} - {% if insight.user_weekly_stats.likes > 0 %} - 그리고 {{insight.user_weekly_stats.likes}}개의 좋아요를 받았어요. - {% endif %} - - * 이번 주에 신규 가입을 하셨다면 총 누적 조회수로 계산됩니다. -
-

-
- {% endif %} +
- {% if insight.user_weekly_reminder %} -
-

- 마지막으로 글을 작성하신지 {{insight.user_weekly_reminder.days_ago}}일이 지났어요 😭 -

-

- 지난번엔 "{{insight.user_weekly_reminder.title}}" 라는 제목의 글을 작성하셨네요!
- 이번 주에 새로운 글을 발행하시면 저희가 분석해드려요.
- 다음 주엔 꼭 분석해드리고 싶네요! 화이팅! 💪
-
- Tip💡: 리더보드에서 인기 글을 참고해 작성해보시는 건 어떨까요? -

-
- {% endif %} - - {% if insight.trending_summary %} -

- 이번 주에 쓴 글 -

- {% for item in insight.trending_summary %} -
-
- {% if item.thumbnail %} -
- {{item.title}} -
- {% endif %} -
-
- {% if item.thumbnail %} -

- {% else %} -

- {% endif %} - - {{forloop.counter}}. {{ item.title }} - -

-
-
-
-

- {{ item.summary }} -

-
- {% if item.key_points %} -

- 📌 {{ item.key_points|join:", " }} -

- {% endif %} -
-
- {% endfor %} - {% endif %} + {% if insight.trending_summary or insight.user_weekly_stats or insight.user_weekly_reminder %} +

+ {% if user.username %} + {{user.username}}님의 활동 리포트 + {% else %} + 활동 리포트 + {% endif %} +

+ {% endif %} - {% if insight.trend_analysis %} -

- 내 글을 분석해보면? -

- {% if insight.trend_analysis.hot_keywords %} -

- 📌 내 기술 키워드 -

-

- {{ insight.trend_analysis.hot_keywords|join:", " }} -

- {% endif %} - {% if insight.trend_analysis.title_trends %} -

- 🤔 제목 분석 -

-

- {{ insight.trend_analysis.title_trends }} -

- {% endif %} - {% if insight.trend_analysis.content_trends %} -

- 🧐 콘텐츠 분석 -

-

- {{ insight.trend_analysis.content_trends }} -

- {% endif %} - {% if insight.trend_analysis.insights %} -

- 💡 인사이트 + {% if insight.user_weekly_stats %} +
+ {% if insight.user_weekly_stats.new_posts > 0 %} +

+ 저번 주에는 + + {{insight.user_weekly_stats.new_posts}}개의 글 + + 을 작성하셨네요!
+ 👏 지난 한 주간 + + {{insight.user_weekly_stats.views}}명 + + 이 + {% if user.username %} + {{user.username}}님의 + {% endif %} + 포스트를 읽었어요.
+ 그리고 + + {{insight.user_weekly_stats.likes}}개의 좋아요 + + 를 받았어요. + + * 이번 주에 신규 가입을 하셨다면 총 누적 조회수로 계산됩니다. + +

+ {% endif %} +
+ {% endif %} + + {% if insight.user_weekly_reminder %} +
+ {% if insight.user_weekly_reminder.days_ago %} + +

+ 😭 마지막으로 글을 작성하신지 {{insight.user_weekly_reminder.days_ago}}일이 지났어요! +

+

+ {% if insight.user_weekly_reminder.title %} + 지난번엔 "{{insight.user_weekly_reminder.title}}" (이)라는 제목의 글을 작성하셨네요!
+ {% endif %} + 다음 주에 새로운 글을 발행하시면 저희가 분석해드려요.
+ 다음주엔 꼭 분석해드리고 싶네요! 화이팅! 💪
+
+ TIP: + + 리더보드 + + 에서 인기 글을 참고해 작성해보시는 건 어떨까요? +

+ {% else %} +

+ 😭 글을 작성하지 않으셨네요! +

+

+ 다음 주에 새로운 글을 발행하시면 저희가 분석해드려요.
+ 다음 주엔 꼭 분석해드리고 싶네요! 화이팅! 💪
+
+ TIP: + + 리더보드 + + 에서 인기 글을 참고해 작성해보시는 건 어떨까요? +

+ {% endif %} +
+ {% endif %} + + {% if insight.trending_summary %} +

+ 이번주에 작성한 글 +

+ {% for item in insight.trending_summary %} +
+
+ {% if item.thumbnail %} +
+ {{item.title}} +
+ {% endif %} +
+

+ + {{ item.title }} +

-

- {{ insight.trend_analysis.insights }} + {% if item.username and item.key_points %} +

+ @{{item.username}} | {{ item.key_points|join:", " }} +

+ {% elif item.username %} +

+ @{{item.username}} +

+ {% elif item.key_points %} +

+ 📌 {{ item.key_points|join:", " }} +

+ {% endif %} +

+ {{ item.summary }}

- {% endif %} - {% endif %} +
+
+
+ {% endfor %} + {% endif %} + + {% if insight.trend_analysis %} +
+

+ 주간 내 활동 분석 +

+ {% if insight.trend_analysis.hot_keywords %} +

+ 🔑 내 기술 키워드 +

+

+ {{ insight.trend_analysis.hot_keywords|join:", " }} +

+ {% endif %} + {% if insight.trend_analysis.title_trends %} +

+ 📋 제목 분석 +

+

+ {{ insight.trend_analysis.title_trends }} +

+ {% endif %} + {% if insight.trend_analysis.content_trends %} +

+ 📦 콘텐츠 분석 +

+

+ {{ insight.trend_analysis.content_trends }} +

+ {% endif %} + {% if insight.trend_analysis.insights %} +

+ 💡 인사이트 +

+

+ {{ insight.trend_analysis.insights }} +

+ {% endif %} +
+ {% endif %}
\ No newline at end of file diff --git a/templates/insights/weekly_trend.html b/templates/insights/weekly_trend.html index 993ffc0..6ce622e 100644 --- a/templates/insights/weekly_trend.html +++ b/templates/insights/weekly_trend.html @@ -1,89 +1,96 @@ -
- {% if insight.trending_summary or insight.trend_analysis %} -

- 📈 벨로그 트렌드 리포트 -

- {% endif %} +
+

+ 벨로그 주간 트렌드 +

- {% if insight.trending_summary %} -

- 이 주의 트렌딩 글 -

- {% for item in insight.trending_summary %} -
-
- {% if item.thumbnail %} -
- {{item.title}} -
- {% endif %} -
-
- {% if item.thumbnail %} -

- {% else %} -

- {% endif %} - - {{forloop.counter}}. {{ item.title }} - - {% if item.username %} -
- @{{item.username}} - {% endif %} -

-
-
-
-

- {{ item.summary }} -

-
- {% if item.key_points %} -

- 📌 {{ item.key_points|join:", " }} -

- {% endif %} -
+ {% if insight.trending_summary %} +

+ 이번 주의 트렌딩 글 +

+ {% for item in insight.trending_summary %} +
+
+ {% if item.thumbnail %} +
+ {{item.title}}
- {% endfor %} - {% endif %} - - {% if insight.trend_analysis %} -

- 이번 주 트렌드 분석 -

- {% if insight.trend_analysis.hot_keywords %} -

- 📌 핫한 기술 키워드 -

-

- {{ insight.trend_analysis.hot_keywords|join:", " }} -

- {% endif %} - {% if insight.trend_analysis.title_trends %} -

- 🤔 제목 트렌드 -

-

- {{ insight.trend_analysis.title_trends }} -

- {% endif %} - {% if insight.trend_analysis.content_trends %} -

- 🧐 콘텐츠 트렌드 + {% endif %} +
+

+ + {{ item.title }} +

-

- {{ insight.trend_analysis.content_trends }} + {% if item.username and item.key_points %} +

+ @{{item.username}} | 📌 {{ item.key_points|join:", " }} +

+ {% elif item.username %} +

+ @{{item.username}} +

+ {% elif item.key_points %} +

+ 📌 {{ item.key_points|join:", " }} +

+ {% endif %} +

+ {{ item.summary }}

- {% endif %} - {% if insight.trend_analysis.insights %} -

- 💡 인사이트 -

-

- {{ insight.trend_analysis.insights }} -

- {% endif %} - {% endif %} -
\ No newline at end of file +

+
+
+ {% endfor %} + {% endif %} + + {% if insight.trend_analysis %} +
+

+ 주간 트렌드 분석 +

+ {% if insight.trend_analysis.hot_keywords %} +

+ 🔑 핫한 기술 키워드 +

+

+ {{ insight.trend_analysis.hot_keywords|join:", " }} +

+ {% endif %} + + {% if insight.trend_analysis.title_trends %} +

+ 📋 제목 트렌드 +

+

+ {{ insight.trend_analysis.title_trends }} +

+ {% endif %} + + {% if insight.trend_analysis.content_trends %} +

+ 📦 콘텐츠 트렌드 +

+

+ {{ insight.trend_analysis.content_trends }} +

+ {% endif %} + + {% if insight.trend_analysis.insights %} +

+ 💡 인사이트 +

+

+ {{ insight.trend_analysis.insights }} +

+ {% endif %} +
+ {% endif %} +