/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/email/tests/testemail.py

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    return TestLoader().loadTestsFromName(__name__)
31
31
 
32
32
 
33
 
sample_config = (b"[DEFAULT]\n"
34
 
                 b"post_commit_to=demo@example.com\n"
35
 
                 b"post_commit_sender=Sample <foo@example.com>\n"
36
 
                 b"revision_mail_headers=X-Cheese: to the rescue!\n")
37
 
 
38
 
unconfigured_config = (b"[DEFAULT]\n"
39
 
                       b"email=Robert <foo@example.com>\n")
40
 
 
41
 
sender_configured_config = (b"[DEFAULT]\n"
42
 
                            b"post_commit_sender=Sample <foo@example.com>\n")
43
 
 
44
 
to_configured_config = (b"[DEFAULT]\n"
45
 
                        b"post_commit_to=Sample <foo@example.com>\n")
46
 
 
47
 
multiple_to_configured_config = (b"[DEFAULT]\n"
48
 
                                 b"post_commit_sender=Sender <from@example.com>\n"
49
 
                                 b"post_commit_to=Sample <foo@example.com>, Other <baz@bar.com>\n")
50
 
 
51
 
customized_mail_config = (b"[DEFAULT]\n"
52
 
                          b"post_commit_to=demo@example.com\n"
53
 
                          b"post_commit_sender=Sample <foo@example.com>\n"
54
 
                          b"post_commit_subject=[commit] $message\n"
55
 
                          b"post_commit_body='''$committer has committed "
56
 
                          b"revision 1 at $url.\n\n'''\n")
57
 
 
58
 
push_config = (b"[DEFAULT]\n"
59
 
               b"post_commit_to=demo@example.com\n"
60
 
               b"post_commit_push_pull=True\n")
61
 
 
62
 
with_url_config = (b"[DEFAULT]\n"
63
 
                   b"post_commit_url=http://some.fake/url/\n"
64
 
                   b"post_commit_to=demo@example.com\n"
65
 
                   b"post_commit_sender=Sample <foo@example.com>\n")
 
33
sample_config=("[DEFAULT]\n"
 
34
               "post_commit_to=demo@example.com\n"
 
35
               "post_commit_sender=Sample <foo@example.com>\n"
 
36
               "revision_mail_headers=X-Cheese: to the rescue!\n")
 
37
 
 
38
unconfigured_config=("[DEFAULT]\n"
 
39
                     "email=Robert <foo@example.com>\n")
 
40
 
 
41
sender_configured_config=("[DEFAULT]\n"
 
42
                          "post_commit_sender=Sample <foo@example.com>\n")
 
43
 
 
44
to_configured_config=("[DEFAULT]\n"
 
45
                      "post_commit_to=Sample <foo@example.com>\n")
 
46
 
 
47
multiple_to_configured_config=("[DEFAULT]\n"
 
48
              "post_commit_sender=Sender <from@example.com>\n"
 
49
              "post_commit_to=Sample <foo@example.com>, Other <baz@bar.com>\n")
 
50
 
 
51
customized_mail_config=("[DEFAULT]\n"
 
52
                        "post_commit_to=demo@example.com\n"
 
53
                        "post_commit_sender=Sample <foo@example.com>\n"
 
54
                        "post_commit_subject=[commit] $message\n"
 
55
                        "post_commit_body='''$committer has committed "
 
56
                            "revision 1 at $url.\n\n'''\n")
 
57
 
 
58
push_config=("[DEFAULT]\n"
 
59
    "post_commit_to=demo@example.com\n"
 
60
    "post_commit_push_pull=True\n")
 
61
 
 
62
with_url_config=("[DEFAULT]\n"
 
63
                 "post_commit_url=http://some.fake/url/\n"
 
64
                 "post_commit_to=demo@example.com\n"
 
65
                 "post_commit_sender=Sample <foo@example.com>\n")
66
66
 
67
67
# FIXME: this should not use a literal log, rather grab one from breezy.log
68
 
sample_log = ('------------------------------------------------------------\n'
69
 
              'revno: 1\n'
70
 
              'revision-id: A\n'
71
 
              'committer: Sample <john@example.com>\n'
72
 
              'branch nick: work\n'
73
 
              'timestamp: Thu 1970-01-01 00:00:01 +0000\n'
74
 
              'message:\n'
75
 
              '  foo bar baz\n'
76
 
              '  fuzzy\n'
77
 
              '  wuzzy\n')
 
68
sample_log=('------------------------------------------------------------\n'
 
69
            'revno: 1\n'
 
70
            'revision-id: A\n'
 
71
            'committer: Sample <john@example.com>\n'
 
72
            'branch nick: work\n'
 
73
            'timestamp: Thu 1970-01-01 00:00:01 +0000\n'
 
74
            'message:\n'
 
75
            '  foo bar baz\n'
 
76
            '  fuzzy\n'
 
77
            '  wuzzy\n')
78
78
 
79
79
 
80
80
class TestGetTo(TestCaseInTempDir):
87
87
    def test_custom_body(self):
88
88
        sender = self.get_sender(customized_mail_config)
89
89
        self.assertEqual('%s has committed revision 1 at %s.\n\n%s' %
90
 
                         (sender.revision.committer, sender.url(), sample_log),
91
 
                         sender.body())
 
90
            (sender.revision.committer, sender.url(), sample_log),
 
91
             sender.body())
92
92
 
93
93
    def test_command_line(self):
94
94
        sender = self.get_sender()
136
136
        self.assertEqual(sender.url(), 'http://some.fake/url/')
137
137
 
138
138
    def test_public_url_set(self):
139
 
        config = (b"[DEFAULT]\n"
140
 
                  b"public_branch=http://the.publication/location/\n")
 
139
        config=("[DEFAULT]\n"
 
140
                "public_branch=http://the.publication/location/\n")
141
141
        sender = self.get_sender(config)
142
142
        self.assertEqual(sender.url(), 'http://the.publication/location/')
143
143
 
144
144
    def test_url_precedence(self):
145
 
        config = (b"[DEFAULT]\n"
146
 
                  b"post_commit_url=http://some.fake/url/\n"
147
 
                  b"public_branch=http://the.publication/location/\n")
 
145
        config=("[DEFAULT]\n"
 
146
                "post_commit_url=http://some.fake/url/\n"
 
147
                "public_branch=http://the.publication/location/\n")
148
148
        sender = self.get_sender(config)
149
149
        self.assertEqual(sender.url(), 'http://some.fake/url/')
150
150
 
155
155
    def test_subject(self):
156
156
        sender = self.get_sender()
157
157
        self.assertEqual("Rev 1: foo bar baz in %s" %
158
 
                         sender.branch.base,
 
158
                            sender.branch.base,
159
159
                         sender.subject())
160
160
 
161
161
    def test_custom_subject(self):
162
162
        sender = self.get_sender(customized_mail_config)
163
163
        self.assertEqual("[commit] %s" %
164
 
                         sender.revision.get_summary(),
 
164
                            sender.revision.get_summary(),
165
165
                         sender.subject())
166
166
 
167
167
    def test_diff_filename(self):
170
170
 
171
171
    def test_headers(self):
172
172
        sender = self.get_sender()
173
 
        self.assertEqual({'X-Cheese': 'to the rescue!'},
174
 
                         sender.extra_headers())
 
173
        self.assertEqual({'X-Cheese': 'to the rescue!'}, sender.extra_headers())
175
174
 
176
175
    def get_sender(self, text=sample_config):
177
176
        my_config = config.MemoryStack(text)
178
177
        self.branch = BzrDir.create_branch_convenience('.')
179
178
        tree = self.branch.controldir.open_workingtree()
180
 
        tree.commit('foo bar baz\nfuzzy\nwuzzy', rev_id=b'A',
181
 
                    allow_pointless=True,
182
 
                    timestamp=1,
183
 
                    timezone=0,
184
 
                    committer="Sample <john@example.com>",
185
 
                    )
186
 
        sender = EmailSender(self.branch, b'A', my_config)
 
179
        tree.commit('foo bar baz\nfuzzy\nwuzzy', rev_id='A',
 
180
            allow_pointless=True,
 
181
            timestamp=1,
 
182
            timezone=0,
 
183
            committer="Sample <john@example.com>",
 
184
            )
 
185
        sender = EmailSender(self.branch, 'A', my_config)
187
186
        # This is usually only done after the EmailSender has locked the branch
188
187
        # and repository during send(), however, for testing, we need to do it
189
188
        # earlier, since send() is not called.