Better API for ICapPaste.new_paste

This commit is contained in:
Laurent Bachelier 2011-04-23 00:30:27 +02:00
commit 8af2674994
6 changed files with 11 additions and 13 deletions

View file

@ -82,7 +82,7 @@ class Pastoob(ReplApplication):
accepted_backends = [backend for backend in self.weboob.iter_backends()] accepted_backends = [backend for backend in self.weboob.iter_backends()]
backend = choice(accepted_backends) backend = choice(accepted_backends)
p = backend.new_paste() p = backend.new_paste(_id=None)
p.title = os.path.basename(filename) p.title = os.path.basename(filename)
p.contents = contents p.contents = contents
backend.post_paste(p) backend.post_paste(p)

View file

@ -38,8 +38,8 @@ class PastealaconBackend(BaseBackend, ICapPaste):
LICENSE = 'AGPLv3+' LICENSE = 'AGPLv3+'
BROWSER = PastealaconBrowser BROWSER = PastealaconBrowser
def new_paste(self): def new_paste(self, *args, **kwargs):
return PastealaconPaste(None) return PastealaconPaste(*args, **kwargs)
def get_paste(self, _id): def get_paste(self, _id):
with self.browser: with self.browser:

View file

@ -24,8 +24,6 @@ from weboob.tools.browser import BrowserUnavailable
from weboob.capabilities.paste import PasteNotFound from weboob.capabilities.paste import PasteNotFound
from .paste import PastealaconPaste
class PastealaconTest(BackendTest): class PastealaconTest(BackendTest):
BACKEND = 'pastealacon' BACKEND = 'pastealacon'
@ -45,7 +43,7 @@ class PastealaconTest(BackendTest):
assert u'héhéhé' in p.contents assert u'héhéhé' in p.contents
def test_post(self): def test_post(self):
p = PastealaconPaste(None, title='ouiboube', contents=u'Weboob Test héhéhé') p = self.backend.new_paste(None, title='ouiboube', contents=u'Weboob Test héhéhé')
self.backend.post_paste(p) self.backend.post_paste(p)
assert p.id assert p.id
self.backend.fill_paste(p, ['title']) self.backend.fill_paste(p, ['title'])
@ -59,7 +57,7 @@ class PastealaconTest(BackendTest):
self._get_paste('http://pastealacon.com/'+p.id) self._get_paste('http://pastealacon.com/'+p.id)
def test_spam(self): def test_spam(self):
p = PastealaconPaste(None, title='viagra', contents='http://example.com/') p = self.backend.new_paste(None, title='viagra', contents='http://example.com/')
self.assertRaises(BrowserUnavailable, self.backend.post_paste, p) self.assertRaises(BrowserUnavailable, self.backend.post_paste, p)
def test_notfound(self): def test_notfound(self):

View file

@ -42,8 +42,8 @@ class PastebinBackend(BaseBackend, ICapPaste):
Value('apikey', label='Optional API key', default='', masked=True), Value('apikey', label='Optional API key', default='', masked=True),
) )
def new_paste(self): def new_paste(self, *args, **kwargs):
return PastebinPaste(None) return PastebinPaste(*args, **kwargs)
def get_paste(self, _id): def get_paste(self, _id):
with self.browser: with self.browser:

View file

@ -18,7 +18,6 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.tools.test import BackendTest from weboob.tools.test import BackendTest
from .paste import PastebinPaste
from weboob.capabilities.base import NotLoaded from weboob.capabilities.base import NotLoaded
from weboob.capabilities.paste import PasteNotFound from weboob.capabilities.paste import PasteNotFound
@ -42,7 +41,7 @@ class PastebinTest(BackendTest):
assert p.contents == 'prout' assert p.contents == 'prout'
def test_post(self): def test_post(self):
p = PastebinPaste(None, title='ouiboube', contents='Weboob Test') p = self.backend.new_paste(None, title='ouiboube', contents='Weboob Test')
self.backend.post_paste(p) self.backend.post_paste(p)
assert p.id assert p.id
self.backend.fill_paste(p, ['title']) self.backend.fill_paste(p, ['title'])
@ -51,7 +50,7 @@ class PastebinTest(BackendTest):
def test_specialchars(self): def test_specialchars(self):
# post a paste and get the contents through the HTML response # post a paste and get the contents through the HTML response
p1 = PastebinPaste(None, title='ouiboube', contents=u'Weboob <test>¿¡') p1 = self.backend.new_paste(None, title='ouiboube', contents=u'Weboob <test>¿¡')
self.backend.post_paste(p1) self.backend.post_paste(p1)
assert p1.id assert p1.id

View file

@ -53,9 +53,10 @@ class ICapPaste(IBaseCap):
This capability represents the ability for a website backend to store plain text. This capability represents the ability for a website backend to store plain text.
""" """
def new_paste(self): def new_paste(self, *args, **kwargs):
""" """
Get a new paste object for posting it with the backend. Get a new paste object for posting it with the backend.
The parameters should be passed to the object init.
@return a Paste object @return a Paste object
""" """