[a158f3]: / ForgeBlog / forgeblog / tests / functional / test_feeds.py  Maximize  Restore  History

Download this file

148 lines (129 with data), 5.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# 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 ming.odm.odmsession import ThreadLocalODMSession
from tg import tmpl_context as c
from alluratest.controller import TestController
from allura import model as M
from allura.lib import helpers as h
from forgeblog import model as BM
class TestFeeds(TestController):
def _post(self, slug='', **kw):
d = {
'title': 'My Pôst'.encode(),
'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._post()
r = self.app.get('/blog/feed.rss')
r.mustcontain('/my-p%C3%B4st/</link>')
r = self.app.get('/blog/feed.atom')
r.mustcontain('/my-p%C3%B4st/"')
def test_rss_feed_contains_self_link(self):
r = self.app.get('/blog/feed.rss')
# atom namespace included
assert '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">' in r
# ...and atom:link points to feed url
assert ('<atom:link href="http://localhost/blog/feed.rss" '
'rel="self" type="application/rss+xml"></atom:link>' in r)
def test_post_feeds(self):
self._post()
d = self._blog_date()
response = self.app.get(h.urlquote('/blog/%s/my-pôst/feed.rss' % d))
assert 'Nothing to see' in response
response = self.app.get(h.urlquote('/blog/%s/my-pôst/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()
ThreadLocalODMSession.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 "Nothing to see here" not in response
# Change the status to draft.
response = self.app.get('/blog/')
assert "Everything is here" in response
self._update(url='hello-world', status="draft")
response = self.app.get('/blog/')
assert "Everything is here" not 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 '/blog/%s/deletion-post/edit' % d not in response
response = self.app.get("/blog/feed.rss")
assert url not in response
def test_comments_only_in_per_post_feed(self):
self._post()
blog_post = BM.BlogPost.query.get()
with h.push_config(c, user=M.User.query.get(username='test-admin')), \
h.push_context(blog_post.project._id, app_config_id=blog_post.app_config_id):
blog_post.discussion_thread.add_post(text='You are a good blogger, I am a boring commentor.')
ThreadLocalODMSession.flush_all()
resp = self.app.get(h.urlquote("/blog/" + self._blog_date() + "/my-pôst/feed.rss"))
assert 'boring comment' in resp
resp = self.app.get("/blog/feed.rss")
assert 'boring comment' not in resp