paste* backends: Support the 'public' attribute

This commit is contained in:
Laurent Bachelier 2011-04-27 00:32:15 +02:00
commit 9022435e49
6 changed files with 27 additions and 4 deletions

View file

@ -25,6 +25,9 @@ __all__ = ['PastealaconPaste']
class PastealaconPaste(BasePaste):
# all pastes are public
public = True
@classmethod
def id2url(cls, _id):
return 'http://pastealacon.com/%s' % _id

View file

@ -34,6 +34,7 @@ class PastealaconTest(BackendTest):
assert p.title == 'ouiboube'
assert p.page_url.startswith('http://pastealacon.com/')
assert u'héhéhé' in p.contents
assert p.public is True
# raw method
p = self.backend.get_paste(_id)
@ -41,6 +42,7 @@ class PastealaconTest(BackendTest):
assert p.title is NotLoaded
assert p.page_url.startswith('http://pastealacon.com/')
assert u'héhéhé' in p.contents
assert p.public is True
def test_post(self):
p = self.backend.new_paste(None, title='ouiboube', contents=u'Weboob Test héhéhé')
@ -49,6 +51,7 @@ class PastealaconTest(BackendTest):
self.backend.fill_paste(p, ['title'])
assert p.title == 'ouiboube'
assert p.id in p.page_url
assert p.public is True
# test all get methods from the Paste we just created
self._get_paste(p.id)

View file

@ -79,6 +79,7 @@ class PastebinBrowser(BaseBrowser):
data = {'api_dev_key': dev_key,
'api_option': 'paste',
'api_paste_expire_date': '1M',
'api_paste_private': '0' if paste.public else '1',
'api_paste_code': paste.contents.encode(self.ENCODING),
}
if paste.title:

View file

@ -18,7 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.tools.browser import BasePage
from weboob.tools.browser import BasePage, BrokenPageError
__all__ = ['PastePage', 'PostPage']
@ -30,6 +30,14 @@ class PastePage(BasePage):
'//div[@class="paste_box_line1"]//h1', 1, 'xpath').text
paste.contents = self.parser.select(self.document.getroot(),
'//textarea[@id="paste_code"]', 1, 'xpath').text
visibility_text = self.parser.select(header,
'//div[@class="paste_box_line1"]//img', 1, 'xpath').attrib['alt']
if visibility_text.startswith('Public'):
paste.public = True
elif visibility_text.startswith('Private'):
paste.public = False
else:
raise BrokenPageError('Unable to get the paste visibility')
return paste
def get_id(self):
@ -44,5 +52,6 @@ class PostPage(BasePage):
self.browser.select_form(name='myform')
self.browser['paste_code'] = paste.contents.encode(self.browser.ENCODING)
self.browser['paste_name'] = paste.title.encode(self.browser.ENCODING)
self.browser['paste_private'] = ['0' if paste.public else '1']
self.browser['paste_expire_date'] = ['1M']
self.browser.submit()

View file

@ -32,6 +32,7 @@ class PastebinTest(BackendTest):
assert p.title == 'plop'
assert p.page_url == 'http://pastebin.com/7HmXwzyt'
assert p.contents == 'prout'
assert p.public is True
# raw method
p = self.backend.get_paste(_id)
@ -39,25 +40,29 @@ class PastebinTest(BackendTest):
assert p.title is NotLoaded
assert p.page_url == 'http://pastebin.com/7HmXwzyt'
assert p.contents == 'prout'
assert p.public is NotLoaded
def test_post(self):
p = self.backend.new_paste(None, title='ouiboube', contents='Weboob Test')
p = self.backend.new_paste(None, title='ouiboube', contents='Weboob Test', public=True)
self.backend.post_paste(p)
assert p.id
self.backend.fill_paste(p, ['title'])
assert p.title == 'ouiboube'
assert p.id in p.page_url
assert p.public is True
def test_specialchars(self):
# post a paste and get the contents through the HTML response
p1 = self.backend.new_paste(None, title='ouiboube', contents=u'Weboob <test>¿¡')
p1 = self.backend.new_paste(None, title='ouiboube', contents=u'Weboob <test>¿¡', public=False)
self.backend.post_paste(p1)
assert p1.id
assert p1.public is False
# this should use the raw method to get the contents
p2 = self.backend.get_paste(p1.id)
self.backend.fillobj(p2, ['contents'])
assert p2.contents == p1.contents
assert p2.public is NotLoaded
def test_notfound(self):
for _id in ('weboooooooooooooooooooooooooob', 'http://pastebin.com/weboooooooooooooooooooooooooob'):

View file

@ -31,12 +31,14 @@ class BasePaste(CapBaseObject):
"""
Represents a pasted text.
"""
def __init__(self, _id, title=NotLoaded, language=NotLoaded, contents=NotLoaded):
def __init__(self, _id, title=NotLoaded, language=NotLoaded, contents=NotLoaded,
public=NotLoaded):
CapBaseObject.__init__(self, unicode(_id))
self.add_field('title', basestring, title)
self.add_field('language', basestring, language)
self.add_field('contents', basestring, contents)
self.add_field('public', bool, public)
@classmethod
def id2url(cls, _id):