piknik

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

commit 63b898444be1769d52bb86c6b676a98c3465e88c
parent bd3966f45276140ebaca933ac669c7eaaa8f0a7d
Author: lash <dev@holbrook.no>
Date:   Thu,  1 Dec 2022 15:37:39 +0000

Avoid duplicate message trigger for multipart enclosure

Diffstat:
Mpiknik/msg.py | 8++++++--
Mpiknik/render/base.py | 8+++-----
Mtests/test_render.py | 20++++++++++++++++----
3 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/piknik/msg.py b/piknik/msg.py @@ -46,8 +46,12 @@ class IssueMessage: message_ids = [] message_id = None envelope = None + initial = False for m in msg.walk(): + if not initial: + initial = True + continue env_header = m.get('X-Piknik-Envelope') if env_header != None: if envelope_callback != None: @@ -62,8 +66,8 @@ class IssueMessage: if new_message_id != None: message_id = new_message_id message_ids.append(message_id) - - message_callback(envelope, m, message_id) + else: + message_callback(envelope, m, message_id) if post_callback != None: post_callback(message_ids) diff --git a/piknik/render/base.py b/piknik/render/base.py @@ -8,7 +8,7 @@ class Renderer: def __init__(self, basket, accumulator=None): self.b = basket - self.e = None + #self.e = None self.a = accumulator @@ -19,13 +19,11 @@ class Renderer: def apply_envelope_pre(self, state, issue, tags, envelope, accumulator=None): - #logg.debug('entering envelope {}'.format(envelope)) - self.e = envelope + pass def apply_envelope_post(self, state, issue, tags, envelope, accumulator=None): - #logg.debug('leaving envelope {}'.format(self.e)) - self.e = None + pass def apply_envelope(self, state, issue, tags, envelope, accumulator=None): diff --git a/tests/test_render.py b/tests/test_render.py @@ -32,6 +32,7 @@ def test_wrapper(p): m = Message() m.add_header('Foo', 'bar') m.set_type('multipart/relative') + m.add_header('X-Piknik-Envelope', 'foo') m.set_payload(p) return m @@ -42,6 +43,17 @@ def test_unwrapper(msg, message_callback=None, part_callback=None): message_callback(v) +class TestRenderer(Renderer): + + def __init__(self, basket, accumulator=None): + super(TestRenderer, self).__init__(basket, accumulator=accumulator) + self.c = 0 + + + def apply_message(self, state, issue, tags, envelope, message, accumulator=None): + r = self.c + self.c += 1 + return r class TestMsg(unittest.TestCase): @@ -51,11 +63,11 @@ class TestMsg(unittest.TestCase): def accumulate(v): self.acc.append(v) - (self.crypto, self.gpg, self.gpg_dir) = pgp_setup() + #(self.crypto, self.gpg, self.gpg_dir) = pgp_setup() self.store = TestStates() - self.b = Basket(self.store, message_wrapper=self.crypto.sign) + self.b = Basket(self.store, message_wrapper=test_wrapper) #, message_wrapper=self.crypto.sign) self.render_dir = tempfile.mkdtemp() - self.renderer = Renderer(self.b, accumulator=accumulate) #outdir=self.render_dir) + self.renderer = TestRenderer(self.b, accumulator=accumulate) #outdir=self.render_dir) def tearDown(self): @@ -73,7 +85,7 @@ class TestMsg(unittest.TestCase): m = self.b.msg(v, 's:foo') self.renderer.apply() - print(self.acc) + self.assertEqual(len(self.acc), 1) if __name__ == '__main__':