allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject allura git commit: [#4153] Deletion handled, tests added and improved.
Date Thu, 24 Mar 2016 17:41:28 GMT
Repository: allura
Updated Branches:
  refs/heads/master 129e186e8 -> e00fcd869


[#4153] Deletion handled, tests added and improved.


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

Branch: refs/heads/master
Commit: e00fcd8698fd863b948f7199c765fe8fd6f33378
Parents: 129e186
Author: dastanforever <pranav.sharma.nits@gmail.com>
Authored: Thu Mar 24 18:16:37 2016 +0530
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Thu Mar 24 17:14:18 2016 +0000

----------------------------------------------------------------------
 Allura/allura/model/artifact.py                 |   4 +-
 ForgeBlog/forgeblog/main.py                     |   2 +
 .../forgeblog/tests/functional/test_feeds.py    | 126 +++++++++++++++++++
 .../forgeblog/tests/functional/test_root.py     |  34 -----
 4 files changed, 130 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/e00fcd86/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 0a3cb02..d0ece70 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -875,14 +875,14 @@ class Feed(MappedClass):
 
     @classmethod
     def update(cls, artifact, title=None, description=None, author=None,
-            author_link=None, author_name=None, pubdate=None, link=None, **kw):
+            author_link=None, author_name=None, pubdate=None, link=None, delete=False, **kw):
         """
         For a blog post which is present already but to be updated.
         """
         if not Feed.has_access(artifact):
             return
         v1 = Feed.query.find({'ref_id': artifact.index_id()}).first()
-        if artifact.state == 'draft':
+        if artifact.state == 'draft' or delete:
             Feed.delete(v1)
         # Modify the previous version.
         else:

http://git-wip-us.apache.org/repos/asf/allura/blob/e00fcd86/ForgeBlog/forgeblog/main.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/main.py b/ForgeBlog/forgeblog/main.py
index 96d809c..ca23336 100644
--- a/ForgeBlog/forgeblog/main.py
+++ b/ForgeBlog/forgeblog/main.py
@@ -377,6 +377,8 @@ class PostController(BaseController, FeedController):
     def save(self, delete=None, **kw):
         require_access(self.post, 'write')
         if delete:
+            # Remove from the Rss Feed.
+            M.Feed.update(self.post, delete=True)
             self.post.delete()
             flash('Post deleted', 'info')
             redirect(h.really_unicode(c.app.url).encode('utf-8'))

http://git-wip-us.apache.org/repos/asf/allura/blob/e00fcd86/ForgeBlog/forgeblog/tests/functional/test_feeds.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/tests/functional/test_feeds.py b/ForgeBlog/forgeblog/tests/functional/test_feeds.py
new file mode 100644
index 0000000..f587ebd
--- /dev/null
+++ b/ForgeBlog/forgeblog/tests/functional/test_feeds.py
@@ -0,0 +1,126 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+
+import datetime
+
+from nose.tools import assert_equal, assert_in
+from ming.orm.ormsession import ThreadLocalORMSession
+from alluratest.controller import TestController
+from allura import model as M
+
+
+class TestFeeds(TestController):
+
+    def _post(self, slug='', **kw):
+        d = {
+            'title': 'My Post',
+            'text': 'Nothing to see here',
+            'labels': '',
+            'state': 'published'}
+        d.update(kw)
+        r = self.app.post('/blog%s/save' % slug, params=d)
+        return r
+
+    def _update(self, url='', delete=False, **kw):
+        if delete:
+            d = {
+            'delete':'Delete'
+            }
+        else:
+            d = {
+                'title': 'My Post',
+                'text': 'Nothing to see here',
+                'labels': '',
+                'state': 'published'}
+            d.update(kw)
+        r = self.app.post('/blog/' + str(self._blog_date()) +  "/" + url + "/save", params
= d)
+        return r
+
+    def _blog_date(self):
+        return datetime.datetime.utcnow().strftime('%Y/%m')
+
+    def test_feeds(self):
+        self.app.get('/blog/feed.rss')
+        self.app.get('/blog/feed.atom')
+
+    def test_rss_feed_contains_self_link(self):
+        r = self.app.get('/blog/feed.rss')
+        # atom namespace included
+        assert_in('<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">', r)
+        # ...and atom:link points to feed url
+        assert_in('<atom:link href="http://localhost/blog/feed.rss" '
+                  'type="application/rss+xml" rel="self"></atom:link>', r)
+
+    def test_post_feeds(self):
+        self._post()
+        d = self._blog_date()
+        response = self.app.get('/blog/%s/my-post/feed.rss' % d)
+        assert 'Nothing to see' in response
+        response = self.app.get('/blog/%s/my-post/feed.atom' % d)
+        assert 'Nothing to see' in response
+        self._post(title='test', text='*sometext*')
+        response = self.app.get('/blog/feed')
+        assert '&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;sometext&lt;/em&gt;&lt;/p&gt;&lt;/div&gt;'
in response
+
+    def test_related_artifacts(self):
+        self._post(title='one')
+        M.MonQTask.run_ready()
+        d = self._blog_date()
+        self._post(title='two', text='[blog:%s/one]' % d)
+        M.MonQTask.run_ready()
+        ThreadLocalORMSession.flush_all()
+        r = self.app.get('/blog/%s/one/' % d)
+        assert 'Related' in r
+        assert 'Blog: %s/two' % d in r
+
+    def test_feed_update(self):
+        # Post a feed.
+        d = self._blog_date()
+        self._post(title="Hello World")
+        response = self.app.get('/blog/%s/hello-world/feed.rss' % d)
+        assert "Nothing to see here" in response
+        # Update it with different data.
+        r = self._update(url='hello-world', text="Everything is here")
+        # Check if the feed changed.
+        response = self.app.get('/blog/%s/hello-world/feed.rss' % d)
+        assert "Everything is here" in response
+        assert not "Nothing to see here" in response
+        # Change the status to draft.
+        response = self.app.get('/blog/')
+        assert "Everything is here" in response
+        r = self._update(url='hello-world', status="draft")
+        response = self.app.get('/blog/')
+        assert not "Everything is here" in response
+
+    def test_post_delete_feed_delete(self):
+        # Post a blogpost.
+        self._post(title="Deletion Post")
+        d = self._blog_date()
+        url = '/blog/' + self._blog_date() + "/deletion-post/"
+        # Check that post exists.
+        response = self.app.get("/blog/")
+        assert '/blog/%s/deletion-post/edit' % d in response
+        response = self.app.get("/blog/feed.rss")
+        assert url in response
+        # Delete the post.
+        self._update(url="deletion-post", delete=True)
+        # Check feed is deleted.
+        response = self.app.get("/blog/")
+        assert not '/blog/%s/deletion-post/edit' % d in response
+        response = self.app.get("/blog/feed.rss")
+        assert not url in response

http://git-wip-us.apache.org/repos/asf/allura/blob/e00fcd86/ForgeBlog/forgeblog/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/tests/functional/test_root.py b/ForgeBlog/forgeblog/tests/functional/test_root.py
index ca6dc03..4ca87ac 100644
--- a/ForgeBlog/forgeblog/tests/functional/test_root.py
+++ b/ForgeBlog/forgeblog/tests/functional/test_root.py
@@ -190,40 +190,6 @@ class Test(TestController):
         response = self.app.get('/blog/%s/my-post/diff?v1=0&v2=0' % d)
         assert 'My Post' in response
 
-    def test_feeds(self):
-        self.app.get('/blog/feed.rss')
-        self.app.get('/blog/feed.atom')
-
-    def test_rss_feed_contains_self_link(self):
-        r = self.app.get('/blog/feed.rss')
-        # atom namespace included
-        assert_in('<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">', r)
-        # ...and atom:link points to feed url
-        assert_in('<atom:link href="http://localhost/blog/feed.rss" '
-                  'type="application/rss+xml" rel="self"></atom:link>', r)
-
-    def test_post_feeds(self):
-        self._post()
-        d = self._blog_date()
-        response = self.app.get('/blog/%s/my-post/feed.rss' % d)
-        assert 'Nothing to see' in response
-        response = self.app.get('/blog/%s/my-post/feed.atom' % d)
-        assert 'Nothing to see' in response
-        self._post(title='test', text='*sometext*')
-        response = self.app.get('/blog/feed')
-        assert '&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;sometext&lt;/em&gt;&lt;/p&gt;&lt;/div&gt;'
in response
-
-    def test_related_artifacts(self):
-        self._post(title='one')
-        M.MonQTask.run_ready()
-        d = self._blog_date()
-        self._post(title='two', text='[blog:%s/one]' % d)
-        M.MonQTask.run_ready()
-        ThreadLocalORMSession.flush_all()
-        r = self.app.get('/blog/%s/one/' % d)
-        assert 'Related' in r
-        assert 'Blog: %s/two' % d in r
-
     def test_invalid_lookup(self):
         r = self.app.get('/blog/favicon.ico', status=404)
         assert_equal(r.status_int, 404)


Mime
View raw message