piknik

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

test_html.py (2845B)


      1 # standard imports
      2 import unittest
      3 import logging
      4 import json
      5 import shutil
      6 import io
      7 import tempfile
      8 from email.message import Message
      9 from email.utils import localtime as email_localtime
     10 
     11 # external imports
     12 from mimeparse import parse_mime_type
     13 
     14 # local imports
     15 from piknik import (
     16         Basket,
     17         Issue,
     18         )
     19 from piknik.msg import IssueMessage
     20 from piknik.render.html import Renderer
     21 from piknik.render.html import Accumulator
     22 from piknik.wrap import Wrapper
     23 
     24 # test imports
     25 from tests.common import TestStates
     26 from tests.common import TestMsgStore
     27 from tests.common import pgp_setup
     28 
     29 logging.basicConfig(level=logging.DEBUG)
     30 logg = logging.getLogger()
     31 
     32 
     33 def test_wrapper(p):
     34     m = Message()
     35     m.add_header('Foo', 'bar')
     36     m.add_header('X-Piknik-Envelope', 'foo')
     37     m.set_type('multipart/relative')
     38     m.set_payload(p)
     39     return m
     40 
     41 
     42 class TestMsg(unittest.TestCase):
     43 
     44     def setUp(self):
     45         (self.crypto, self.gpg, self.gpg_dir) = pgp_setup()
     46         self.store = TestStates()
     47         self.b = Basket(self.store, message_wrapper=self.crypto.sign)
     48         self.render_dir = tempfile.mkdtemp()
     49 
     50 
     51     def tearDown(self):
     52         shutil.rmtree(self.render_dir)
     53 
     54 
     55     def test_states_two_issues(self):
     56         issue_one = Issue('foo')
     57         self.b.add(issue_one)
     58 
     59         issue_two = Issue('bar')
     60         v = self.b.add(issue_two)
     61 
     62         m = self.b.msg(v, 's:foo')
     63 
     64         state = self.b.get_state(v)
     65 
     66         msgs = []
     67         w = io.StringIO()
     68         renderer = Renderer(self.b, outdir=self.render_dir)
     69         renderer.apply()
     70 
     71 
     72     def test_issue(self):
     73         issue = Issue('foo')
     74         issue_id = self.b.add(issue)
     75 
     76         m = self.b.msg(issue_id, 's:foo')
     77 
     78         self.b.tag(issue_id, 'inky')
     79         self.b.tag(issue_id, 'pinky')
     80 
     81         state = self.b.get_state(issue_id)
     82         tags = self.b.tags(issue_id)
     83 
     84         w = io.StringIO()
     85         acc = Accumulator(w=w)
     86         wrapper = Wrapper()
     87         renderer = Renderer(self.b, outdir=self.render_dir, wrapper=wrapper, accumulator=acc.add)
     88         renderer.apply_begin()
     89         renderer.apply_issue(state, issue, tags)
     90         renderer.apply_end()
     91 
     92         w.seek(0)
     93         print(w.read())
     94 
     95 
     96     def test_issue_attachment(self):
     97         b = Basket(self.store, message_wrapper=test_wrapper)
     98         issue = Issue('foo')
     99         issue_id = b.add(issue)
    100 
    101         m = b.msg(issue_id, 'f:tests/three.webp')
    102 
    103         state = b.get_state(issue_id)
    104         tags = []
    105 
    106         w = io.StringIO()
    107         acc = Accumulator(w=w)
    108         wrapper = Wrapper()
    109         renderer = Renderer(b, outdir=self.render_dir, wrapper=wrapper, accumulator=acc.add)
    110         renderer.apply_begin()
    111         renderer.apply_issue(state, issue, tags)
    112         renderer.apply_end()
    113 
    114         w.seek(0)
    115         print(w.read())
    116 
    117 
    118 
    119 if __name__ == '__main__':
    120     unittest.main()