~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-12-26 06:01:53 UTC
  • mfrom: (14575.2.4 megalint-9)
  • Revision ID: launchpad@pqm.canonical.com-20111226060153-1rfmi1yn90lu4fuf
[r=jtv][no-qa] Lint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    monkey_patch,
24
24
    TestCase,
25
25
    )
 
26
from lp.testing.fakemethod import FakeMethod
26
27
 
27
28
 
28
29
class TestMantisBugBatchParser(TestCase):
69
70
        self.assertThat(parser.getBugs(), Equals({}))
70
71
 
71
72
    def test_passing(self):
72
 
        data = ['ignored,id,resolution,status',
73
 
                'foo,42,not,complete',
74
 
                'boo,13,,confirmed']
 
73
        data = [
 
74
            'ignored,id,resolution,status',
 
75
            'foo,42,not,complete',
 
76
            'boo,13,,confirmed',
 
77
            ]
75
78
        parser = MantisBugBatchParser(data, self.logger)
76
79
        bug_42 = dict(
77
80
            id=42, status='complete', resolution='not', ignored='foo')
80
83
        self.assertThat(parser.getBugs(), Equals({42: bug_42, 13: bug_13}))
81
84
 
82
85
    def test_incomplete_line(self):
83
 
        data = ['ignored,id,resolution,status',
84
 
                '42,not,complete']
 
86
        data = [
 
87
            'ignored,id,resolution,status',
 
88
            '42,not,complete',
 
89
            ]
85
90
        parser = MantisBugBatchParser(data, self.logger)
86
91
        self.assertThat(parser.getBugs(), Equals({}))
87
92
        log = self.logger.getLogBuffer()
88
93
        self.assertThat(
89
 
            log, Equals("WARNING Line ['42', 'not', 'complete'] incomplete.\n"))
 
94
            log,
 
95
            Equals("WARNING Line ['42', 'not', 'complete'] incomplete.\n"))
90
96
 
91
97
    def test_non_integer_id(self):
92
 
        data = ['ignored,id,resolution,status',
93
 
                'foo,bar,not,complete']
 
98
        data = [
 
99
            'ignored,id,resolution,status',
 
100
            'foo,bar,not,complete',
 
101
            ]
94
102
        parser = MantisBugBatchParser(data, self.logger)
95
103
        self.assertThat(parser.getBugs(), Equals({}))
96
104
        log = self.logger.getLogBuffer()
107
115
        # If the 'view_all_set.php' request raises a 404, then the csv_data
108
116
        # attribute is None.
109
117
        base_url = "http://example.com/"
110
 
        def raise404(self, request, data):
111
 
            raise urllib2.HTTPError('url', 404, 'Not Found', None, None)
112
 
        with monkey_patch(Mantis, urlopen=raise404):
 
118
 
 
119
        fail_404 = urllib2.HTTPError('url', 404, 'Not Found', None, None)
 
120
 
 
121
        with monkey_patch(Mantis, urlopen=FakeMethod(failure=fail_404)):
113
122
            bugtracker = Mantis(base_url)
114
123
            self.assertThat(bugtracker.csv_data, Is(None))