~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/tests/externalbugtracker.py

MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
651
651
        # explodes in your face. Annoying? Insane? You bet.
652
652
        return [{'bugs': bugs_to_return}]
653
653
 
 
654
    def _copy_comment(self, comment, fields_to_return=None):
 
655
        # Copy wanted fields.
 
656
        comment = dict(
 
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())
 
663
        return comment
 
664
 
 
665
 
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 = {}
664
676
 
665
 
        def copy_comment(comment):
666
 
            # Copy wanted fields.
667
 
            comment = dict(
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())
674
 
            return comment
675
 
 
676
677
        for bug_id in bug_ids:
677
678
            comments_for_bug = self.bug_comments[bug_id].values()
678
679
 
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]
686
688
 
687
689
        # More xmlrpclib:1387 odd-knobbery avoidance.
760
762
    # Map namespaces onto method names.
761
763
    methods = {
762
764
        'Bug': [
 
765
            'comments',
763
766
            'get',
764
767
            'search',
765
768
            ],
781
784
        {'login': 'foo.bar@canonical.com', 'password': 'test'},
782
785
        ]
783
786
 
 
787
    # A list of comments on bugs.
 
788
    bug_comments = {
 
789
        1: {
 
790
            1: {'author': 'trillian',
 
791
                'bug_id': 1,
 
792
                'id': 1,
 
793
                'is_private': False,
 
794
                'text': "I'd really appreciate it if Marvin would "
 
795
                        "enjoy life a bit.",
 
796
                'time': datetime(2008, 6, 16, 12, 44, 29),
 
797
                },
 
798
            2: {'author': 'marvin',
 
799
                'bug_id': 1,
 
800
                'id': 3,
 
801
                'is_private': False,
 
802
                'text': "Life? Don't talk to me about life.",
 
803
                'time': datetime(2008, 6, 16, 13, 22, 29),
 
804
                },
 
805
            },
 
806
        2: {
 
807
            1: {'author': 'trillian',
 
808
                'bug_id': 2,
 
809
                'id': 2,
 
810
                'is_private': False,
 
811
                'text': "Bring the passengers to the bridge please Marvin.",
 
812
                'time': datetime(2008, 6, 16, 13, 8, 8),
 
813
                },
 
814
             2: {'author': 'Ford Prefect <ford.prefect@h2g2.com>',
 
815
                'bug_id': 2,
 
816
                'id': 4,
 
817
                'is_private': False,
 
818
                'text': "I appear to have become a perfectly safe penguin.",
 
819
                'time': datetime(2008, 6, 17, 20, 28, 40),
 
820
                },
 
821
            },
 
822
        }
 
823
 
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
855
895
 
856
896
        return self.get_bugs(search_args)
857
897
 
 
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(
 
911
                self, comments_args)
 
912
        else:
 
913
            return_dict = {'bugs': {}}
 
914
 
 
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))
 
923
 
 
924
            return_dict['comments'] = comments_to_return
 
925
 
 
926
        # Stop xmlrpclib:1387 from throwing a wobbler at having a
 
927
        # length-1 dict to deal with.
 
928
        return [return_dict]
 
929
 
858
930
 
859
931
class TestMantis(Mantis):
860
932
    """Mantis ExternalSystem for use in tests.