102
102
"""gen_revision_id should create a revision id matching the regex"""
103
103
revision_id = generate_ids.gen_revision_id(username, timestamp)
104
104
self.assertMatchesRe(regex, revision_id)
105
# It should be a utf8 revision_id, not a unicode one
106
self.assertIsInstance(revision_id, str)
107
# gen_revision_id should always return ascii revision ids.
108
revision_id.decode('ascii')
110
106
def test_timestamp(self):
111
107
"""passing a timestamp should cause it to be used"""
127
123
def test_gen_revision_id_user(self):
128
124
"""If there is no email, fall back to the whole username"""
129
125
tail = r'-\d{14}-[a-z0-9]{16}'
130
self.assertGenRevisionId('joe_bar' + tail, 'Joe Bar')
126
self.assertGenRevisionId('joe_bar' + tail,'Joe Bar')
131
127
self.assertGenRevisionId('joebar' + tail, 'joebar')
132
128
self.assertGenRevisionId('joe_br' + tail, u'Joe B\xe5r')
133
129
self.assertGenRevisionId(r'joe_br_user\+joe_bar_foo-bar.com' + tail,
134
130
u'Joe B\xe5r <user+Joe_Bar_Foo-Bar.com>')
136
def test_revision_ids_are_ascii(self):
137
"""gen_revision_id should always return an ascii revision id."""
138
tail = r'-\d{14}-[a-z0-9]{16}'
139
self.assertGenRevisionId('joe_bar' + tail, 'Joe Bar')
140
self.assertGenRevisionId('joe_bar' + tail, u'Joe Bar')
141
self.assertGenRevisionId('joe@foo' + tail, u'Joe Bar <joe@foo>')
142
# We cheat a little with this one, because email-addresses shouldn't
143
# contain non-ascii characters, but generate_ids should strip them
145
self.assertGenRevisionId('joe@f' + tail, u'Joe Bar <joe@f\xb6>')