paste* backends: Accept an URL or an ID

Like most other backends, with the id2url decorator.
This commit is contained in:
Laurent Bachelier 2011-04-21 18:29:18 +02:00
commit dc35df83ef
6 changed files with 69 additions and 39 deletions

View file

@ -34,14 +34,14 @@ class PastealaconTest(BackendTest):
p = self.backend.get_paste(_id)
self.backend.fillobj(p, ['title'])
assert p.title == 'ouiboube'
assert p.page_url == 'http://pastealacon.com/'+_id
assert p.page_url.startswith('http://pastealacon.com/')
assert u'héhéhé' in p.contents
# raw method
p = self.backend.get_paste(_id)
self.backend.fillobj(p, ['contents'])
assert p.title is NotLoaded
assert p.page_url == 'http://pastealacon.com/'+_id
assert p.page_url.startswith('http://pastealacon.com/')
assert u'héhéhé' in p.contents
def test_post(self):
@ -52,17 +52,22 @@ class PastealaconTest(BackendTest):
assert p.title == 'ouiboube'
assert p.id in p.page_url
# test all get methods from the Paste we just created
self._get_paste(p.id)
# same but from the full URL
self._get_paste('http://pastealacon.com/'+p.id)
def test_spam(self):
p = PastealaconPaste(None, title='viagra', contents='http://example.com/')
self.assertRaises(BrowserUnavailable, self.backend.post_paste, p)
def test_notfound(self):
# html method
p = self.backend.get_paste('424242424242424242424242424242424242')
self.assertRaises(PasteNotFound, self.backend.fillobj, p, ['title'])
for _id in ('424242424242424242424242424242424242', 'http://pastealacon.com/424242424242424242424242424242424242'):
# html method
p = self.backend.get_paste(_id)
self.assertRaises(PasteNotFound, self.backend.fillobj, p, ['title'])
# raw method
p = self.backend.get_paste('424242424242424242424242424242424242')
self.assertRaises(PasteNotFound, self.backend.fillobj, p, ['contents'])
# raw method
p = self.backend.get_paste(_id)
self.assertRaises(PasteNotFound, self.backend.fillobj, p, ['contents'])