1.1 --- a/tests/test_message.py Mon Oct 29 22:36:16 2012 +0100
1.2 +++ b/tests/test_message.py Fri Jan 18 00:36:13 2013 +0100
1.3 @@ -1,14 +1,40 @@
1.4 #!/usr/bin/env python
1.5
1.6 from MoinMessage import Message
1.7 +from email.mime.multipart import MIMEMultipart
1.8 from email.mime.text import MIMEText
1.9 import sys
1.10
1.11 if __name__ == "__main__":
1.12 + try:
1.13 + type = sys.argv[1]
1.14 + action = sys.argv[2]
1.15 + args = sys.argv[3:]
1.16 + except IndexError:
1.17 + args = None
1.18 +
1.19 + if not args:
1.20 + print >>sys.stderr, "Need an update type, update action and some updates as arguments to this program."
1.21 + sys.exit(1)
1.22 +
1.23 message = Message()
1.24 + parts = []
1.25
1.26 - for arg in sys.argv[1:]:
1.27 - message.add_update([MIMEText(arg, "moin")])
1.28 + # Add each content fragment as either a separate update to a collection of
1.29 + # updates or as an alternative part to a single update.
1.30 +
1.31 + for arg in args:
1.32 + part = MIMEText(arg, "moin", sys.stdin.encoding)
1.33 + if type == "collection":
1.34 + part["Update-Action"] = action
1.35 + message.add_update(part)
1.36 + else:
1.37 + parts.append(part)
1.38 +
1.39 + if type != "collection":
1.40 + multipart = message.get_update(parts)
1.41 + multipart["Update-Action"] = action
1.42 + message.add_update(multipart)
1.43
1.44 text = message.get_payload()
1.45 print text