~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_merge_directive.py

Merge (hopefully the last time) mainline fixes for 0.15.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
        self.build_tree_contents([('tree1/file', 'a\nb\nc\nd\ne\n')])
47
47
        tree1.commit('bar')
48
48
        os.chdir('tree1')
 
49
        return tree1, tree2
49
50
 
50
51
    def test_merge_directive(self):
51
52
        self.prepare_merge_directive()
97
98
            gpg.GPGStrategy = old_strategy
98
99
        self.assertContainsRe(md_text, '^-----BEGIN PSEUDO-SIGNED CONTENT')
99
100
 
100
 
    def test_mail(self):
101
 
        self.prepare_merge_directive()
 
101
    def run_bzr_fakemail(self, *args, **kwargs):
102
102
        sendmail_calls = []
103
103
        def sendmail(self, from_, to, message):
104
104
            sendmail_calls.append((self, from_, to, message))
110
110
        old_connect = smtplib.SMTP.connect
111
111
        smtplib.SMTP.connect = connect
112
112
        try:
113
 
            md_text = self.run_bzr('merge-directive', '--mail-to',
114
 
                                   'pqm@example.com', '--plain', '../tree2',
115
 
                                   '.')[0]
 
113
            result = self.run_bzr(*args, **kwargs)
116
114
        finally:
117
115
            smtplib.SMTP.sendmail = old_sendmail
118
116
            smtplib.SMTP.connect = old_connect
 
117
        return result + (connect_calls, sendmail_calls)
 
118
 
 
119
    def test_mail_default(self):
 
120
        tree1, tree2 = self.prepare_merge_directive()
 
121
        md_text, errr, connect_calls, sendmail_calls =\
 
122
            self.run_bzr_fakemail('merge-directive', '--mail-to',
 
123
                                  'pqm@example.com', '--plain', '../tree2',
 
124
                                  '.')
119
125
        self.assertEqual('', md_text)
120
126
        self.assertEqual(1, len(connect_calls))
121
127
        call = connect_calls[0]
125
131
        self.assertEqual(('J. Random Hacker <jrandom@example.com>',
126
132
                          'pqm@example.com'), call[1:3])
127
133
        self.assertContainsRe(call[3], EMAIL1)
 
134
 
 
135
    def test_mail_uses_config(self):
 
136
        tree1, tree2 = self.prepare_merge_directive()
 
137
        tree1.branch.get_config().set_user_option('smtp_server', 'bogushost')
 
138
        md_text, errr, connect_calls, sendmail_calls =\
 
139
            self.run_bzr_fakemail('merge-directive', '--mail-to',
 
140
                                  'pqm@example.com', '--plain', '../tree2',
 
141
                                  '.')
 
142
        call = connect_calls[0]
 
143
        self.assertEqual(('bogushost', 0), call[1:3])