From a658021f7e7e1cb36aa270067c53896e47666035 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Thu, 31 Oct 2013 10:44:46 +0100 Subject: [PATCH] fix unittest for 1358fac and extend internal documentation --- isso/notify.py | 6 +++++- isso/utils/http.py | 9 +++++++++ isso/utils/parse.py | 12 ++++++------ specs/test_comment.py | 6 ++++++ specs/test_vote.py | 6 ++++++ 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/isso/notify.py b/isso/notify.py index adb5244..b50860d 100644 --- a/isso/notify.py +++ b/isso/notify.py @@ -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 diff --git a/isso/utils/http.py b/isso/utils/http.py index 0be920c..f579c4b 100644 --- a/isso/utils/http.py +++ b/isso/utils/http.py @@ -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 diff --git a/isso/utils/parse.py b/isso/utils/parse.py index 6af6425..8decd38 100644 --- a/isso/utils/parse.py +++ b/isso/utils/parse.py @@ -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")))))) diff --git a/specs/test_comment.py b/specs/test_comment.py index 1bc8406..09d6e01 100644 --- a/specs/test_comment.py +++ b/specs/test_comment.py @@ -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')) diff --git a/specs/test_vote.py b/specs/test_vote.py index 95c4d17..36dfb6e 100644 --- a/specs/test_vote.py +++ b/specs/test_vote.py @@ -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'))