fix unittest for 1358fac and extend internal documentation

This commit is contained in:
Martin Zimmermann 2013-10-31 10:44:46 +01:00
parent 1358fac258
commit a658021f7e
5 changed files with 32 additions and 7 deletions

View File

@ -32,6 +32,10 @@ def format(comment, permalink, remote_addr, deletion_key, activation_key=None):
class Connection(object):
"""
Establish connection to SMTP server, optional with authentication, and
close connection afterwards.
"""
def __init__(self, conf):
self.conf = conf
@ -75,5 +79,5 @@ class SMTPMailer(object):
class NullMailer(object):
def sendmail(self, subject, body, retries=5):
def sendmail(self, subject, body):
pass

View File

@ -13,6 +13,15 @@ from isso.utils import parse
class curl(object):
"""Easy to use wrapper around :module:`httplib`. Use as context-manager
so we can close the response properly.
.. code-block:: python
with http.curl('GET', 'http://localhost:8080', '/') as resp:
if resp: # may be None if request failed
return resp.status
"""
def __init__(self, method, host, path, timeout=3):
self.method = method

View File

@ -54,15 +54,15 @@ def host(name):
"""
Parse :param name: into `httplib`-compatible host:port.
>>> print(host("http://example.tld/"))
>>> host("http://example.tld/")
('example.tld', 80, False)
>>> print(host("https://example.tld/"))
>>> host("https://example.tld/")
('example.tld', 443, True)
>>> print(host("example.tld"))
>>> host("example.tld")
('example.tld', 80, False)
>>> print(host("example.tld:42"))
>>> host("example.tld:42")
('example.tld', 42, False)
>>> print(host("https://example.tld:80/"))
>>> host("https://example.tld:80/")
('example.tld', 80, True)
"""
@ -109,7 +109,7 @@ def title(data, default=u"Untitled."):
assert html.lastChild.nodeName == "html"
html = html.lastChild
# aka getElementById
# aka getElementById, but limited to div and section tags
el = list(filter(lambda i: i.attributes["id"].value == "isso-thread",
filter(lambda i: "id" in i.attributes,
chain(*map(html.getElementsByTagName, ("div", "section"))))))

View File

@ -22,9 +22,15 @@ class Dummy:
status = 200
def __enter__(self):
return self
def read(self):
return ''
def __exit__(self, exc_type, exc_val, exc_tb):
pass
http.curl = lambda method, host, path: Dummy()
loads = lambda data: json.loads(data.decode('utf-8'))

View File

@ -16,9 +16,15 @@ class Dummy:
status = 200
def __enter__(self):
return self
def read(self):
return ''
def __exit__(self, exc_type, exc_val, exc_tb):
pass
http.curl = lambda method, host, path: Dummy()
loads = lambda data: json.loads(data.decode('utf-8'))