allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject allura git commit: Includes "seconds" in ago() helper
Date Mon, 31 Oct 2016 19:02:52 GMT
Repository: allura
Updated Branches:
  refs/heads/master 590a5ca74 -> 4854dad5c


Includes "seconds" in ago() helper


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/4854dad5
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/4854dad5
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/4854dad5

Branch: refs/heads/master
Commit: 4854dad5c9ad455e2883c9c5cb10aea64d0b5792
Parents: 590a5ca
Author: Dave Brondsema <dave@brondsema.net>
Authored: Wed Oct 12 10:53:09 2016 -0400
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Mon Oct 31 15:02:49 2016 -0400

----------------------------------------------------------------------
 Allura/allura/lib/helpers.py                     |  6 ++----
 Allura/allura/tests/functional/test_discuss.py   |  2 +-
 .../allura/tests/functional/test_user_profile.py |  2 +-
 .../allura/tests/unit/test_helpers/test_ago.py   | 19 +++++++++++--------
 .../tests/functional/test_forum.py               |  2 +-
 .../tests/functional/test_controllers.py         |  7 ++++---
 6 files changed, 20 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/4854dad5/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index f06da1e..b90692a 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -404,16 +404,14 @@ def ago(start_time, show_date_after=7):
 
     if start_time is None:
         return 'unknown'
-    granularities = ['century', 'decade', 'year', 'month', 'day', 'hour',
-                     'minute']
+    granularities = ['century', 'decade', 'year', 'month', 'day', 'hour', 'minute', 'second']
     end_time = datetime.utcnow()
     if show_date_after is not None and end_time - start_time > timedelta(days=show_date_after):
         return start_time.strftime('%Y-%m-%d')
 
     while True:
         granularity = granularities.pop()
-        ago = date.distance_of_time_in_words(
-            start_time, end_time, granularity, round=True)
+        ago = date.distance_of_time_in_words(start_time, end_time, granularity, round=True)
         rounded_to_one_granularity = 'and' not in ago
         if rounded_to_one_granularity:
             break

http://git-wip-us.apache.org/repos/asf/allura/blob/4854dad5/Allura/allura/tests/functional/test_discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_discuss.py b/Allura/allura/tests/functional/test_discuss.py
index c18a330..836d094 100644
--- a/Allura/allura/tests/functional/test_discuss.py
+++ b/Allura/allura/tests/functional/test_discuss.py
@@ -270,7 +270,7 @@ class TestDiscuss(TestDiscussBase):
         assert create_activity.call_args[0][1] == 'modified'
         r = self.app.get(thread_url)
         assert 'zzz' in str(r.html.find('div', {'class': 'display_post'}))
-        assert 'Last edit: Test Admin less than 1 minute ago' in str(
+        assert 'Last edit: Test Admin ' in str(
             r.html.find('div', {'class': 'display_post'}))
 
     def test_deleted_post(self):

http://git-wip-us.apache.org/repos/asf/allura/blob/4854dad5/Allura/allura/tests/functional/test_user_profile.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_user_profile.py b/Allura/allura/tests/functional/test_user_profile.py
index d3c502d..5655b4b 100644
--- a/Allura/allura/tests/functional/test_user_profile.py
+++ b/Allura/allura/tests/functional/test_user_profile.py
@@ -37,7 +37,7 @@ class TestUserProfile(TestController):
         assert_in('Username:test-admin', r.html.find(None, 'personal-data').getText())
         assert_in('projects', sections)
         assert_in('Test Project', r.html.find(None, 'projects').getText())
-        assert_in('Last Updated:less than 1 minute ago', r.html.find(None, 'projects').getText())
+        assert_in('Last Updated:', r.html.find(None, 'projects').getText())
         assert_in('tools', sections)
         assert_in('Admin', r.html.find(None, 'tools').getText())
         assert_in('skills', sections)

http://git-wip-us.apache.org/repos/asf/allura/blob/4854dad5/Allura/allura/tests/unit/test_helpers/test_ago.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_helpers/test_ago.py b/Allura/allura/tests/unit/test_helpers/test_ago.py
index 5e09a2c..039bb00 100644
--- a/Allura/allura/tests/unit/test_helpers/test_ago.py
+++ b/Allura/allura/tests/unit/test_helpers/test_ago.py
@@ -15,23 +15,26 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
+from datetime import datetime
+
 from mock import patch
+from nose.tools import assert_equal
 
-from datetime import datetime
 from allura.lib import helpers
 
 
-class TestAgo:
+class TestAgo(object):
 
     def setUp(self):
         self.start_time = datetime(2010, 1, 1, 0, 0, 0)
 
-    def test_that_empty_times_are_phrased_in_minutes(self):
-        self.assertTimeSince('0 minutes ago', 2010, 1, 1, 0, 0, 0)
+    def test_that_exact_times_are_phrased_in_seconds(self):
+        self.assertTimeSince('0 seconds ago', 2010, 1, 1, 0, 0, 0)
 
-    def test_that_partial_minutes_are_rounded(self):
-        self.assertTimeSince('less than 1 minute ago', 2010, 1, 1, 0, 0, 29)
-        self.assertTimeSince('1 minute ago', 2010, 1, 1, 0, 0, 31)
+    def test_that_partial_seconds_are_rounded(self):
+        self.assertTimeSince('less than 1 second ago', 2010, 1, 1, 0, 0, 0, 1)
+        # the are not rounded, actually.  oh well
+        self.assertTimeSince('less than 1 second ago', 2010, 1, 1, 0, 0, 0, 999999)
 
     def test_that_minutes_are_rounded(self):
         self.assertTimeSince('1 minute ago', 2010, 1, 1, 0, 1, 29)
@@ -55,7 +58,7 @@ class TestAgo:
         self.assertTimeSince('2010-01-01', 2011, 8, 1, 0, 0, 0)
 
     def assertTimeSince(self, time_string, *time_components):
-        assert time_string == self.time_since(*time_components)
+        assert_equal(time_string, self.time_since(*time_components))
 
     def time_since(self, *time_components):
         end_time = datetime(*time_components)

http://git-wip-us.apache.org/repos/asf/allura/blob/4854dad5/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
index a8c3283..55da689 100644
--- a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
+++ b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
@@ -608,7 +608,7 @@ class TestForum(TestController):
         self.app.post(post_link, params)
         r = self.app.get(thread_url)
         assert 'zzz' in str(r.html.find('div', {'class': 'display_post'}))
-        assert 'Last edit: Test Admin less than 1 minute ago' in str(
+        assert 'Last edit: Test Admin ' in str(
             r.html.find('div', {'class': 'display_post'}))
 
     def test_subscription_controls(self):

http://git-wip-us.apache.org/repos/asf/allura/blob/4854dad5/ForgeGit/forgegit/tests/functional/test_controllers.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py
index fc0b755..09aa905 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -27,6 +27,7 @@ from datadiff.tools import assert_equal as dd_assert_equal
 from nose.tools import assert_equal, assert_in, assert_not_in, assert_not_equal
 import tg
 import pkg_resources
+from nose.tools import assert_regexp_matches
 from pylons import tmpl_context as c
 from ming.orm import ThreadLocalORMSession
 from mock import patch, PropertyMock
@@ -646,7 +647,7 @@ class TestFork(_TestCase):
         assert 'git checkout master' in merge_instructions
         assert 'git fetch git://git.localhost/p/test2/code master' in merge_instructions
         assert 'git merge {}'.format(c_id) in merge_instructions
-        assert_in('less than 1 minute ago', r)
+        assert_regexp_matches(str(r), r'[0-9]+ seconds? ago')
 
         merge_form = r.html.find('div', {'class': 'merge-help-text merge-ok'})
         assert merge_form
@@ -675,8 +676,8 @@ class TestFork(_TestCase):
         r, mr_num = self._request_merge()
         r = self.app.get('/p/test/src-git/merge-requests/')
         assert 'href="%s/"' % mr_num in r, r
-        assert_equal(r.html.findAll('span')[-2].getText(), 'less than 1 minute ago')
-        assert_equal(r.html.findAll('span')[-1].getText(), 'less than 1 minute ago')
+        assert_regexp_matches(r.html.findAll('span')[-2].getText(), r'[0-9]+ seconds? ago')
+        assert_regexp_matches(r.html.findAll('span')[-1].getText(), r'[0-9]+ seconds? ago')
 
     def test_merge_request_update_status(self):
         r, mr_num = self._request_merge()


Mime
View raw message