incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [1/2] git commit: [#6829] Minor fixes, added tests
Date Mon, 09 Dec 2013 15:52:41 GMT
Updated Branches:
  refs/heads/master 633b107a3 -> 247633b85


[#6829] Minor fixes, added tests

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@gmail.com>


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

Branch: refs/heads/master
Commit: 247633b85dc54dfdde4e64d02a3cedc74c886c34
Parents: d20a1de
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Thu Dec 5 15:15:48 2013 +0000
Committer: Cory Johns <admin1@users.sf.net>
Committed: Mon Dec 9 15:52:11 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/discuss.py                  |  8 ++-
 Allura/allura/model/repo.py                     |  4 ++
 Allura/allura/tests/test_globals.py             |  2 +-
 Allura/allura/tests/unit/test_post_model.py     | 11 ++++
 Allura/allura/tests/unit/test_repo.py           |  7 ++
 ForgeActivity/forgeactivity/main.py             | 14 +++-
 .../forgeactivity/nf/activity/css/activity.css  |  8 +--
 .../forgeactivity/templates/index.html          | 18 +++--
 .../forgeactivity/tests/functional/test_root.py | 69 ++++++++++++++++++++
 .../forgeblog/tests/unit/test_blog_post.py      |  4 +-
 .../tests/unit/test_ticket_model.py             |  5 ++
 .../forgeuserstats/tests/test_stats.py          |  2 +-
 12 files changed, 131 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/247633b8/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index 4043c3e..1059295 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -496,10 +496,14 @@ class Post(Message, VersionedArtifact, ActivityObject):
     @property
     def activity_extras(self):
         d = ActivityObject.activity_extras.fget(self)
+        # For activity summary, convert Post text to html,
+        # strip all tags, and truncate near the 80 char mark
+        LEN = 80
         summary = jinja2.Markup.escape(
                 g.markdown.cached_convert(self, 'text')).striptags()
-        if len(summary) > 80:
-            summary = summary[:80] + '...'
+        if len(summary) > LEN:
+            split = max(summary.find(' ', LEN), LEN)
+            summary = summary[:split] + '...'
         d.update(summary=summary)
         return d
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/247633b8/Allura/allura/model/repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo.py b/Allura/allura/model/repo.py
index d9a4a10..682670a 100644
--- a/Allura/allura/model/repo.py
+++ b/Allura/allura/model/repo.py
@@ -172,6 +172,10 @@ class Commit(RepoObject, ActivityObject):
     # Ephemeral attrs
     repo=None
 
+    def __init__(self, **kw):
+        for k, v in kw.iteritems():
+            setattr(self, k, v)
+
     @property
     def activity_name(self):
         return self.shorthand_id()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/247633b8/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index c35f69c..789af0e 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -188,7 +188,7 @@ def test_macro_neighborhood_feeds():
             r = g.markdown_wiki.convert('[[neighborhood_blog_posts]]')
         assert 'test content' in r
 
-@with_setup(teardown=setUp) # reset everything we changed
+@with_setup(setUp, setUp) # start clean and reset everything we change
 def test_macro_members():
     p_nbhd = M.Neighborhood.query.get(name='Projects')
     p_test = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/247633b8/Allura/allura/tests/unit/test_post_model.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_post_model.py b/Allura/allura/tests/unit/test_post_model.py
index 9ac2256..ed33ecb 100644
--- a/Allura/allura/tests/unit/test_post_model.py
+++ b/Allura/allura/tests/unit/test_post_model.py
@@ -39,3 +39,14 @@ class TestPostModel(WithDatabase):
         with h.push_config(c, user=M.User()):
             self.post.approve()
         assert self.post.status == 'ok'
+
+    def test_activity_extras(self):
+        self.post.text = """\
+This is a **bold thing**, 40 chars here.
+* Here's the first item in our list.
+* And here's the second item."""
+        assert 'allura_id' in self.post.activity_extras
+        summary = self.post.activity_extras['summary']
+        assert summary == "This is a bold thing, 40 chars here. " + \
+                          "Here's the first item in our list. " + \
+                          "And here's..."

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/247633b8/Allura/allura/tests/unit/test_repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_repo.py b/Allura/allura/tests/unit/test_repo.py
index 8c104fa..c730d59 100644
--- a/Allura/allura/tests/unit/test_repo.py
+++ b/Allura/allura/tests/unit/test_repo.py
@@ -208,6 +208,13 @@ class TestBlob(unittest.TestCase):
 
 
 class TestCommit(unittest.TestCase):
+    def test_activity_extras(self):
+        commit = M.repo.Commit()
+        commit.shorthand_id = MagicMock(return_value='abcdef')
+        commit.message = 'commit msg'
+        self.assertIn('allura_id', commit.activity_extras)
+        self.assertEqual(commit.activity_extras['summary'], commit.summary)
+
     def test_get_path_no_create(self):
         commit = M.repo.Commit()
         commit.get_tree = MagicMock()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/247633b8/ForgeActivity/forgeactivity/main.py
----------------------------------------------------------------------
diff --git a/ForgeActivity/forgeactivity/main.py b/ForgeActivity/forgeactivity/main.py
index 6249ed0..3d1e62f 100644
--- a/ForgeActivity/forgeactivity/main.py
+++ b/ForgeActivity/forgeactivity/main.py
@@ -46,8 +46,7 @@ class ForgeActivityApp(Application):
 
     def __init__(self, project, config):
         Application.__init__(self, project, config)
-        self.root = ForgeActivityController()
-        g.register_app_css('css/activity.css', app=self)
+        self.root = ForgeActivityController(self)
 
     def main_menu(self): # pragma no cover
         return []
@@ -68,6 +67,17 @@ class W:
     follow_toggle = FollowToggle()
 
 class ForgeActivityController(BaseController):
+    def __init__(self, app, *args, **kw):
+        super(ForgeActivityController, self).__init__(*args, **kw)
+        self.app = app
+
+    def _before(self, *args, **kw):
+        """Runs before each request to this controller.
+
+        """
+        # register the custom css for our tool
+        g.register_app_css('css/activity.css', app=self.app)
+
     @expose('jinja:forgeactivity:templates/index.html')
     @with_trailing_slash
     def index(self, **kw):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/247633b8/ForgeActivity/forgeactivity/nf/activity/css/activity.css
----------------------------------------------------------------------
diff --git a/ForgeActivity/forgeactivity/nf/activity/css/activity.css b/ForgeActivity/forgeactivity/nf/activity/css/activity.css
index be36ba0..f7198fe 100644
--- a/ForgeActivity/forgeactivity/nf/activity/css/activity.css
+++ b/ForgeActivity/forgeactivity/nf/activity/css/activity.css
@@ -9,21 +9,21 @@
   padding: 20px;
   border-bottom: 1px solid #eee;
 }
-.activity ul.timeline li article time {
+.activity ul.timeline li time {
   font-size: 12px;
   color: #777;
 }
-.activity ul.timeline li article h1 {
+.activity ul.timeline li h1 {
   padding: 0;
   font-size: 16px;
   line-height: 32px;
 }
-.activity ul.timeline li article p {
+.activity ul.timeline li p {
   padding: 0;
   vertical-align: top;
   font-size: 14px;
 }
-.activity ul.timeline li article p .avatar {
+.activity ul.timeline li p .avatar {
   display: inline-block;
   margin: 0 8px 8px 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/247633b8/ForgeActivity/forgeactivity/templates/index.html
----------------------------------------------------------------------
diff --git a/ForgeActivity/forgeactivity/templates/index.html b/ForgeActivity/forgeactivity/templates/index.html
index eadb82a..f430c64 100644
--- a/ForgeActivity/forgeactivity/templates/index.html
+++ b/ForgeActivity/forgeactivity/templates/index.html
@@ -59,16 +59,14 @@
     <ul class="timeline">
         {% for a in timeline %}
         <li>
-          <article>
-            <time datetime="{{a.published}}" title="{{a.published}}">{{h.ago(a.published,
show_date_after=None)}}</time>
-            <h1>{{activity_obj(a.actor)}} {{a.verb}} {{activity_obj(a.obj)}} {% if
a.target.activity_name %}on {{activity_obj(a.target)}}{% endif %}</h1>
-            {% if a.obj.activity_extras.get('summary') %}
-            <p>
-              {{ icon(a.actor, 16, 'avatar') }}
-              {{ a.obj.activity_extras.get('summary') }}
-            </p>
-            {% endif %}
-          </article>
+          <time datetime="{{a.published|datetimeformat}}" title="{{a.published|datetimeformat}}">{{h.ago(a.published,
show_date_after=None)}}</time>
+          <h1>{{activity_obj(a.actor)}} {{a.verb}} {{activity_obj(a.obj)}} {% if a.target.activity_name
%}on {{activity_obj(a.target)}}{% endif %}</h1>
+          {% if a.obj.activity_extras.get('summary') %}
+          <p>
+            {{ icon(a.actor, 16, 'avatar') }}
+            {{ a.obj.activity_extras.get('summary') }}
+          </p>
+          {% endif %}
         </li>
         {% endfor %}
     </ul>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/247633b8/ForgeActivity/forgeactivity/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeActivity/forgeactivity/tests/functional/test_root.py b/ForgeActivity/forgeactivity/tests/functional/test_root.py
index d0b9884..b008fc4 100644
--- a/ForgeActivity/forgeactivity/tests/functional/test_root.py
+++ b/ForgeActivity/forgeactivity/tests/functional/test_root.py
@@ -16,8 +16,10 @@
 #       under the License.
 
 from mock import patch
+from textwrap import dedent
 from tg import config
 
+import dateutil.parser
 from nose.tools import assert_equal
 
 from alluratest.controller import TestController
@@ -48,6 +50,73 @@ class TestActivityController(TestController):
         resp = self.app.get('/activity/')
         assert 'No activity to display.' in resp
 
+    @td.with_tool('test', 'activity')
+    @patch('forgeactivity.main.g.director')
+    def test_index_html(self, director):
+        from activitystream.storage.base import StoredActivity
+        from bson import ObjectId
+        director.get_timeline.return_value = [StoredActivity(**{
+            "_id" : ObjectId("529fa331033c5e6406d8b338"),
+            "obj" : {
+                    "activity_extras" : {
+                            "allura_id" : "Post:971389ad979eaafa658beb807bf4629d30f5f642.tickets@test.p.sourceforge.net",
+                            "summary" : "Just wanted to leave a comment on this..."
+                    },
+                    "activity_url" : "/p/test/tickets/_discuss/thread/08e74efd/ed7c/",
+                    "activity_name" : "a comment"
+            },
+            "target" : {
+                    "activity_extras" : {
+                            "allura_id" : "Ticket:529f57a6033c5e5985db2efa",
+                            "summary" : "Make activitystream timeline look better"
+                    },
+                    "activity_url" : "/p/test/tickets/34/",
+                    "activity_name" : "ticket #34"
+            },
+            "actor" : {
+                    "activity_extras" : {
+                            "icon_url" : "/u/test-admin/user_icon",
+                            "allura_id" : "User:521f96cb033c5e2587adbdff"
+                    },
+                    "activity_url" : "/u/test-admin/",
+                    "activity_name" : "Administrator 1",
+                    "node_id" : "User:521f96cb033c5e2587adbdff"
+            },
+            "verb" : "posted",
+            "published" : dateutil.parser.parse("2013-12-04T21:48:19.817"),
+            "score" : 1386193699,
+            "node_id" : "Project:527a6584033c5e62126f5a60",
+            "owner_id" : "Project:527a6584033c5e62126f5a60"
+        })]
+        r = self.app.get('/p/test/activity/')
+        timeline = r.html.find('ul', 'timeline')
+        assert_equal(1, len(timeline.findAll('li')))
+        activity = timeline.find('li')
+        assert_equal(activity.time['title'], "2013-12-04 21:48:19")
+        h1 = """\
+        <h1>
+        <a href="/u/test-admin/">
+         Administrator 1
+        </a>
+        posted
+        <a href="/p/test/tickets/_discuss/thread/08e74efd/ed7c/">
+         a comment
+        </a>
+        on
+        <a href="/p/test/tickets/34/">
+         ticket #34
+        </a>
+        </h1>
+        """
+        assert_equal(dedent(h1), activity.h1.prettify())
+        p = """\
+        <p>
+        <img src="/u/test-admin/user_icon" alt="Administrator 1" title="Administrator
1" class="emboss x16 avatar" />
+        Just wanted to leave a comment on this...
+        </p>
+        """
+        assert_equal(dedent(p), activity.p.prettify())
+
     @td.with_tool('u/test-user-1', 'activity')
     @td.with_user_project('test-user-1')
     def test_follow_user(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/247633b8/ForgeBlog/forgeblog/tests/unit/test_blog_post.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/tests/unit/test_blog_post.py b/ForgeBlog/forgeblog/tests/unit/test_blog_post.py
index 919ac14..f2274d9 100644
--- a/ForgeBlog/forgeblog/tests/unit/test_blog_post.py
+++ b/ForgeBlog/forgeblog/tests/unit/test_blog_post.py
@@ -16,7 +16,7 @@
 #       under the License.
 
 from datetime import datetime
-from nose.tools import assert_equal
+from nose.tools import assert_equal, assert_true
 from pylons import tmpl_context as c
 
 from forgeblog import model as M
@@ -33,6 +33,8 @@ class TestBlogPost(BlogTestWithModel):
         assert_equal(post.title, 'test')
         assert_equal(post.text, 'test message')
         assert_equal(post.state, 'published')
+        assert_equal(post.activity_extras['summary'], post.title)
+        assert_true('allura_id' in post.activity_extras)
 
 
 class TestFeed(BlogTestWithModel):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/247633b8/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py b/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
index 8fc8038..e7ccb2d 100644
--- a/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
+++ b/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
@@ -77,6 +77,11 @@ class TestTicketModel(TrackerTestWithModel):
         else:
             raise AssertionError('Expected schema.Invalid to be thrown')
 
+    def test_activity_extras(self):
+        t = Ticket(summary='my ticket', ticket_num=12)
+        assert_in('allura_id', t.activity_extras)
+        assert_equal(t.activity_extras['summary'], t.summary)
+
     def test_private_ticket(self):
         from pylons import tmpl_context as c
         from allura.model import ProjectRole, User

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/247633b8/ForgeUserStats/forgeuserstats/tests/test_stats.py
----------------------------------------------------------------------
diff --git a/ForgeUserStats/forgeuserstats/tests/test_stats.py b/ForgeUserStats/forgeuserstats/tests/test_stats.py
index bbb43f5..0f8efa9 100644
--- a/ForgeUserStats/forgeuserstats/tests/test_stats.py
+++ b/ForgeUserStats/forgeuserstats/tests/test_stats.py
@@ -51,11 +51,11 @@ class TestStats(TestController):
         assert user.stats.tot_logins_count == 1 + init_logins
         assert user.stats.getLastMonthLogins() == 1 + init_logins
 
+    @td.with_user_project('test-admin')
     @td.with_tool('test', 'wiki', mount_point='wiki', mount_label='wiki', username='test-admin')
     def test_wiki_stats(self):
         initial_artifacts = c.user.stats.getArtifacts()
         initial_wiki = c.user.stats.getArtifacts(art_type="Wiki")
-
         self.app.post('/wiki/TestPage/update',
             params=dict(title='TestPage', text='some text'),
             extra_environ=dict(username=str(c.user.username)))


Mime
View raw message