commit 963f1ea33bb35a8d8b16af776e18d684c6494415
parent 0cb789ef7591a13d872de80ab55a0be720228e32
Author: lash <dev@holbrook.no>
Date: Fri, 2 Dec 2022 21:28:18 +0000
Remove commented code, add missing html test file
Diffstat:
M | piknik/render/html.py | | | 120 | ------------------------------------------------------------------------------- |
A | tests/test_html.py | | | 125 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 125 insertions(+), 120 deletions(-)
diff --git a/piknik/render/html.py b/piknik/render/html.py
@@ -63,9 +63,6 @@ class Renderer(BaseRenderer):
if accumulator == None:
accumulator = Accumulator().add
super(Renderer, self).__init__(basket, accumulator=accumulator, wrapper=wrapper)
- #self.issue_buf = []
- #self.state_buf = []
- #self.message_buf = []
self.outdir = outdir
self.last_message_id = None
self.render_mode = 0
@@ -166,105 +163,6 @@ class Renderer(BaseRenderer):
)
return div(r, _id=s)
-# def apply_state_post(self, state, w=sys.stdout):
-# r = div(_id='state_' + state)
-# r.add(h2(state))
-# r_l = ul(_class='state_listing')
-# while True:
-# try:
-# v = self.issue_buf.pop(0)
-# r_l.add(v)
-# except IndexError:
-# break
-# r.add(r_l)
-# self.state_buf.append(r)
-#
-#
-# def apply_issue(self, state, issue, tags, w=sys.stdout):
-# v = li(a(issue.title, href=issue.id + '.html'))
-# r_l = ol()
-# while True:
-# try:
-# v = self.message_buf.pop(0)
-# logg.debug('msgd {} {}'.format(issue.id, str(v)))
-# r_l.add(v)
-# except IndexError:
-# break
-# v.add(r_l)
-# self.issue_buf.append(v)
-#
-#
-# def apply_issue_post(self, state, issue, tags, w=None):
-# close = False
-# if w == None:
-# fp = os.path.join(self.outdir, issue.id + '.html')
-# w = open(fp, 'w')
-# close = True
-# r = dominate.document(title='issue: {} ({})'.format(issue.title, issue.id))
-# r.add(h1(issue.title))
-#
-# r_l = dl()
-# r_l.add(dt('id'))
-# r_l.add(dd(issue.id))
-#
-# r_l.add(dt('tags'))
-# r_r = ul()
-# for v in tags:
-# if v == '(UNTAGGED)':
-# continue
-# r_r.add(li(v))
-#
-# assigned = issue.get_assigned()
-# r_l.add(dd(r_r))
-#
-# r_l.add(dt('assigned to'))
-# if len(assigned) == 0:
-# r_l.add(dd('not assigned'))
-# else:
-# owner = issue.owner()
-# r_r = ul()
-# for v in assigned:
-# o = v[0]
-# s = o.id()
-# if o == owner:
-# s += ' (owner)'
-# r_r.add(li(s))
-# r_l.add(dd(r_r))
-#
-# r.add(r_l)
-#
-# for i, v in enumerate(self.message_buf):
-# r.add(p(v)) w.write(r.render())
-#
-# if close:
-# w.close()
-#
-#
-# def apply_message_post(self, state, issue, tags, message, message_from, message_date, message_id, message_valid, w=sys.stdout):
-# #r = ol()
-# #w.write(self.message_buf.render())
-# self.msg_idx = 0
-# pass
-#
-#
-# def apply_message_part(self, state, issue, envelope, message, message_from, message_date, message_id, message_valid, dump_dir=None, w=sys.stdout):
-# m = parse_mime_type(message.get_content_type())
-# filename = message.get_filename()
-#
-# if message_id != self.last_message_id:
-# s = '--- {} @ {}'.format(message_from, message_date)
-# self.message_buf.append(div(s, _id=issue.id))
-# self.last_message_id = message_id
-#
-# r = div(_id=issue.id + '.' + message_id + '.' + str(self.msg_idx))
-# self.msg_idx += 1
-# if filename == None:
-# v = message.get_payload()
-# if message.get('Content-Transfer-Encoding') == 'BASE64':
-# v = b64decode(v).decode()
-# r.add(p(v))
-# #w.write(r.render())
-
def apply_begin(self, accumulator=None):
r = dominate.document(title='issues for ...')
@@ -276,21 +174,3 @@ class Renderer(BaseRenderer):
def apply_end(self, accumulator=None):
self.add(())
return None
-
-
-# def apply_end(self, w=sys.stdout):
-# r = dominate.document(title='issues for ...')
-# r.head.add(meta(name='generator', content='piknik'))
-# r.head.add(link(rel='stylesheet', href='style.css'))
-# buf = None
-# if len(self.state_buf) > 0:
-# buf = self.state_buf
-# else:
-# buf = self.issue_buf
-# while True:
-# try:
-# v = buf.pop(0)
-# r.add(v)
-# except IndexError:
-# break
-# w.write(r.render())
diff --git a/tests/test_html.py b/tests/test_html.py
@@ -0,0 +1,125 @@
+# standard imports
+import unittest
+import logging
+import json
+import shutil
+import io
+import tempfile
+from email.message import Message
+from email.utils import localtime as email_localtime
+
+# external imports
+from mimeparse import parse_mime_type
+
+# local imports
+from piknik import (
+ Basket,
+ Issue,
+ )
+from piknik.msg import IssueMessage
+from piknik.render.html import Renderer
+from piknik.render.html import Accumulator
+from piknik.wrap import Wrapper
+
+# test imports
+from tests.common import TestStates
+from tests.common import TestMsgStore
+from tests.common import pgp_setup
+
+logging.basicConfig(level=logging.DEBUG)
+logg = logging.getLogger()
+
+
+#def test_wrapper(p):
+# m = Message()
+# m.add_header('Foo', 'bar')
+# m.set_type('multipart/relative')
+# m.set_payload(p)
+# return m
+#
+#
+#def test_unwrapper(msg, message_callback=None, part_callback=None):
+# for v in msg.walk():
+# if message_callback != None:
+# message_callback(v)
+
+
+class TestMsg(unittest.TestCase):
+
+ def setUp(self):
+ (self.crypto, self.gpg, self.gpg_dir) = pgp_setup()
+ self.store = TestStates()
+ self.b = Basket(self.store, message_wrapper=self.crypto.sign)
+ self.render_dir = tempfile.mkdtemp()
+
+
+ def tearDown(self):
+ #logg.debug('look in {}'.format(self.render_dir))
+ shutil.rmtree(self.render_dir)
+
+
+ def test_states_two_issues(self):
+ issue_one = Issue('foo')
+ self.b.add(issue_one)
+
+ issue_two = Issue('bar')
+ v = self.b.add(issue_two)
+
+ m = self.b.msg(v, 's:foo')
+
+ state = self.b.get_state(v)
+
+ msgs = []
+ w = io.StringIO()
+ renderer = Renderer(self.b, outdir=self.render_dir)
+ renderer.apply()
+
+
+ def test_issue(self):
+ issue = Issue('foo')
+ issue_id = self.b.add(issue)
+
+ m = self.b.msg(issue_id, 's:foo')
+
+ self.b.tag(issue_id, 'inky')
+ self.b.tag(issue_id, 'pinky')
+
+ state = self.b.get_state(issue_id)
+ tags = self.b.tags(issue_id)
+
+ w = io.StringIO()
+ acc = Accumulator(w=w)
+ wrapper = Wrapper()
+ renderer = Renderer(self.b, outdir=self.render_dir, wrapper=wrapper, accumulator=acc.add)
+ renderer.apply_begin()
+ renderer.apply_issue(state, issue, tags)
+ renderer.apply_end()
+
+ w.seek(0)
+ print(w.read())
+
+
+ def test_issue_attachment(self):
+ issue = Issue('foo')
+ issue_id = self.b.add(issue)
+
+ m = self.b.msg(issue_id, 'f:tests/one.png')
+
+ state = self.b.get_state(issue_id)
+ tags = []
+
+ w = io.StringIO()
+ acc = Accumulator(w=w)
+ wrapper = Wrapper()
+ renderer = Renderer(self.b, outdir=self.render_dir, wrapper=wrapper, accumulator=acc.add)
+ renderer.apply_begin()
+ renderer.apply_issue(state, issue, tags)
+ renderer.apply_end()
+
+ w.seek(0)
+ print(w.read())
+
+
+
+if __name__ == '__main__':
+ unittest.main()