651
651
# explodes in your face. Annoying? Insane? You bet.
652
652
return [{'bugs': bugs_to_return}]
654
def _copy_comment(self, comment, fields_to_return=None):
655
# Copy wanted fields.
657
(key, value) for (key, value) in comment.iteritems()
658
if fields_to_return is None or key in fields_to_return)
659
# Replace the time field with an XML-RPC DateTime.
660
if 'time' in comment:
661
comment['time'] = xmlrpclib.DateTime(
662
comment['time'].timetuple())
654
666
def comments(self, arguments):
655
667
"""Return comments for a given set of bugs."""
656
668
# We'll always pass bug IDs when we call comments().
662
674
fields_to_return = arguments.get('include_fields')
663
675
comments_by_bug_id = {}
665
def copy_comment(comment):
666
# Copy wanted fields.
668
(key, value) for (key, value) in comment.iteritems()
669
if fields_to_return is None or key in fields_to_return)
670
# Replace the time field with an XML-RPC DateTime.
671
if 'time' in comment:
672
comment['time'] = xmlrpclib.DateTime(
673
comment['time'].timetuple())
676
677
for bug_id in bug_ids:
677
678
comments_for_bug = self.bug_comments[bug_id].values()
681
682
# dict can have a value but no type; hence Python defaults
682
683
# to treating them as strings).
683
684
comments_by_bug_id[str(bug_id)] = [
684
copy_comment(comment) for comment in comments_for_bug
685
self._copy_comment(comment, fields_to_return)
686
for comment in comments_for_bug
685
687
if comment_ids is None or comment['id'] in comment_ids]
687
689
# More xmlrpclib:1387 odd-knobbery avoidance.
781
784
{'login': 'foo.bar@canonical.com', 'password': 'test'},
787
# A list of comments on bugs.
790
1: {'author': 'trillian',
794
'text': "I'd really appreciate it if Marvin would "
796
'time': datetime(2008, 6, 16, 12, 44, 29),
798
2: {'author': 'marvin',
802
'text': "Life? Don't talk to me about life.",
803
'time': datetime(2008, 6, 16, 13, 22, 29),
807
1: {'author': 'trillian',
811
'text': "Bring the passengers to the bridge please Marvin.",
812
'time': datetime(2008, 6, 16, 13, 8, 8),
814
2: {'author': 'Ford Prefect <ford.prefect@h2g2.com>',
818
'text': "I appear to have become a perfectly safe penguin.",
819
'time': datetime(2008, 6, 17, 20, 28, 40),
784
824
def version(self):
785
825
"""Return the version of Bugzilla being used."""
786
826
# This is to work around the old "xmlrpclib tries to expand
856
896
return self.get_bugs(search_args)
898
def comments(self, arguments):
899
"""Return comments for a given set of bugs."""
900
# Turn the arguments into something that
901
# TestBugzillaXMLRPCTransport.comments() will understand and
902
# then pass the buck.
903
comments_args = dict(arguments)
904
fields_to_return = arguments.get('include_fields')
905
if arguments.get('ids') is not None:
906
# We nuke the 'ids' argument because it means something
907
# different when passed to TestBugzillaXMLRPCTransport.comments.
908
del comments_args['ids']
909
comments_args['bug_ids'] = arguments['ids']
910
[return_dict] = TestBugzillaXMLRPCTransport.comments(
913
return_dict = {'bugs': {}}
915
if arguments.get('comment_ids') is not None:
916
# We need to return all the comments listed.
917
comments_to_return = {}
918
for bug_id, comments in self.bug_comments.items():
919
for comment_number, comment in comments.items():
920
if comment['id'] in arguments['comment_ids']:
921
comments_to_return[comment['id']] = (
922
self._copy_comment(comment, fields_to_return))
924
return_dict['comments'] = comments_to_return
926
# Stop xmlrpclib:1387 from throwing a wobbler at having a
927
# length-1 dict to deal with.
859
931
class TestMantis(Mantis):
860
932
"""Mantis ExternalSystem for use in tests.