30
30
return TestLoader().loadTestsFromName(__name__)
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")
38
unconfigured_config = (b"[DEFAULT]\n"
39
b"email=Robert <foo@example.com>\n")
41
sender_configured_config = (b"[DEFAULT]\n"
42
b"post_commit_sender=Sample <foo@example.com>\n")
44
to_configured_config = (b"[DEFAULT]\n"
45
b"post_commit_to=Sample <foo@example.com>\n")
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")
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")
58
push_config = (b"[DEFAULT]\n"
59
b"post_commit_to=demo@example.com\n"
60
b"post_commit_push_pull=True\n")
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")
38
unconfigured_config=("[DEFAULT]\n"
39
"email=Robert <foo@example.com>\n")
41
sender_configured_config=("[DEFAULT]\n"
42
"post_commit_sender=Sample <foo@example.com>\n")
44
to_configured_config=("[DEFAULT]\n"
45
"post_commit_to=Sample <foo@example.com>\n")
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")
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")
58
push_config=("[DEFAULT]\n"
59
"post_commit_to=demo@example.com\n"
60
"post_commit_push_pull=True\n")
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")
67
67
# FIXME: this should not use a literal log, rather grab one from breezy.log
68
sample_log = ('------------------------------------------------------------\n'
71
'committer: Sample <john@example.com>\n'
73
'timestamp: Thu 1970-01-01 00:00:01 +0000\n'
68
sample_log=('------------------------------------------------------------\n'
71
'committer: Sample <john@example.com>\n'
73
'timestamp: Thu 1970-01-01 00:00:01 +0000\n'
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),
90
(sender.revision.committer, sender.url(), sample_log),
93
93
def test_command_line(self):
94
94
sender = self.get_sender()
136
136
self.assertEqual(sender.url(), 'http://some.fake/url/')
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/')
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/')
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())
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,
184
committer="Sample <john@example.com>",
186
sender = EmailSender(self.branch, b'A', my_config)
179
tree.commit('foo bar baz\nfuzzy\nwuzzy', rev_id='A',
180
allow_pointless=True,
183
committer="Sample <john@example.com>",
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.