From 4f37dd171078e74618f6e0f2569544d2068efc37 Mon Sep 17 00:00:00 2001 From: John Helmert Date: Wed, 12 Jun 2019 21:00:02 -0500 Subject: [PATCH] Add full test coverage for Content.humanize_timestamp --- tests/test_content.py | 39 +++++++++++++++++++++++++++++++++------ tuir/content.py | 4 ++-- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/tests/test_content.py b/tests/test_content.py index 7da3fa2..d03d779 100644 --- a/tests/test_content.py +++ b/tests/test_content.py @@ -106,13 +106,40 @@ def test_content_humanize_timestamp(): assert Content.humanize_timestamp(timestamp) == '0min' assert Content.humanize_timestamp(timestamp, True) == 'moments ago' - timestamp = time.time() - 60 * 60 * 24 * 30.4 * 12 - assert Content.humanize_timestamp(timestamp) == '11month' - assert Content.humanize_timestamp(timestamp, True) == '11 months ago' + timestamp = time.time() - 60 + assert Content.humanize_timestamp(timestamp) == '1min' + assert Content.humanize_timestamp(timestamp, True) == '1 minute ago' - timestamp = time.time() - 60 * 60 * 24 * 30.4 * 12 * 5 - assert Content.humanize_timestamp(timestamp) == '5yr' - assert Content.humanize_timestamp(timestamp, True) == '5 years ago' + timestamp = time.time() - 60 * 2 + assert Content.humanize_timestamp(timestamp, True) == '2 minutes ago' + + timestamp = time.time() - 60 * 60 + assert Content.humanize_timestamp(timestamp) == '1hr' + assert Content.humanize_timestamp(timestamp, True) == '1 hour ago' + + timestamp = time.time() - 60 * 60 * 2 + assert Content.humanize_timestamp(timestamp, True) == '2 hours ago' + + timestamp = time.time() - 60 * 60 * 24 + assert Content.humanize_timestamp(timestamp) == '1day' + assert Content.humanize_timestamp(timestamp, True) == '1 day ago' + + timestamp = time.time() - 60 * 60 * 24 * 2 + assert Content.humanize_timestamp(timestamp, True) == '2 days ago' + + timestamp = time.time() - 60 * 60 * 24 * 31 + assert Content.humanize_timestamp(timestamp) == '1month' + assert Content.humanize_timestamp(timestamp, True) == '1 month ago' + + timestamp = time.time() - 60 * 60 * 24 * 31 * 2 + assert Content.humanize_timestamp(timestamp, True) == '2 months ago' + + timestamp = time.time() - 60 * 60 * 24 * 31 * 12 + assert Content.humanize_timestamp(timestamp) == '1yr' + assert Content.humanize_timestamp(timestamp, True) == '1 year ago' + + timestamp = time.time() - 60 * 60 * 24 * 31 * 12 * 2 + assert Content.humanize_timestamp(timestamp, True) == '2 years ago' def test_content_wrap_text(): diff --git a/tuir/content.py b/tuir/content.py index 205e517..65b9dde 100644 --- a/tuir/content.py +++ b/tuir/content.py @@ -356,7 +356,7 @@ class Content(object): minutes = seconds // 60 if minutes < 60: if verbose and minutes == 1: - return '1 minutes ago' + return '1 minute ago' elif verbose: return '%d minutes ago' % minutes else: @@ -380,7 +380,7 @@ class Content(object): else: return '%dday' % days - months = days // 30.4 + months = days // 31 if months < 12: if verbose and months == 1: return '1 month ago'