bodhi/controllers.py | 18 ++++++++++++++++-- bodhi/tests/test_controllers.py | 32 ++++++++++++++++++++++++++++++++ bodhi/tests/test_model.py | 8 +++++++- bodhi/validators.py | 6 ++++-- 4 files changed, 59 insertions(+), 5 deletions(-)
New commits: commit bbe533cf2396107a5990664bb53faeadd73d6ec2 Author: Luke Macken lmacken@redhat.com Date: Sun Feb 28 16:00:04 2010 -0500
Make our AutoCompleteValidator handle getting a list of builds
diff --git a/bodhi/validators.py b/bodhi/validators.py index 1dda145..5e3f221 100644 --- a/bodhi/validators.py +++ b/bodhi/validators.py @@ -37,13 +37,15 @@ class AutoCompleteValidator(validators.Schema):
def _to_python(self, value, state): tokens = [] - if type(value) in (str, unicode): + if isinstance(value, basestring): tokens = value.split() - elif type(value) == dict: + elif isinstance(value, dict): if isinstance(value['text'], list): tokens = value['text'] else: tokens = [value['text']] + elif isinstance(value, (list, tuple)): + tokens = value results = [] for token in tokens: if token:
commit b1cb2989e3b668e712830b4eea082d0bf931c68c Author: Luke Macken lmacken@redhat.com Date: Sun Feb 28 15:59:26 2010 -0500
Add a couple of utf-8/unicode related tests
diff --git a/bodhi/tests/test_controllers.py b/bodhi/tests/test_controllers.py index 3df6e2f..4beb656 100644 --- a/bodhi/tests/test_controllers.py +++ b/bodhi/tests/test_controllers.py @@ -1866,3 +1866,35 @@ class TestControllers(testutil.DBTest): refresh_metrics() testutil.create_request('/updates/metrics/', method='GET') assert 'flot' in cherrypy.response.body[0] + + def test_bullets(self): + session = login() + f7 = create_release() + params = { + 'notes' : '\xc2\xb7', + 'builds' : 'TurboGears-1.0.2.2-2.fc7', + 'type_' : 'bugfix', + 'bugs' : '1', + 'cves' : '', + } + #testutil.capture_log(['bodhi.controllers', 'bodhi.util', 'bodhi.model']) + self.save_update(params, session) + #logs = testutil.get_log() + #assert False, logs + update = PackageUpdate.byTitle(params['builds']) + assert update.notes == u'\xb7' + assert update.notes.encode('utf-8') == '\xc2\xb7' + testutil.create_request('/updates/' + params['builds']) + body = cherrypy.response.body[0] + assert '\xc2\xb7' in body + assert u'ยท' in body.decode('utf-8') + + # Try throwing it at the root controller directly + # FIXME: figure out how to authenticate properly when calling + # controllers directly + testutil.set_identity_user(User.select()[0]) + try: + testutil.call(cherrypy.root.save, **{'stable_karma': 3, 'edited': False, 'builds': [u'TurboGears2-2.0.3-1.fc7'], 'autokarma': False, 'inheritance': False, 'suggest_reboot': False, 'notes': u'\xb7', 'bugs': '1', 'unstable_karma': -3, 'type_': u'bugfix', 'close_bugs': False}) + except cherrypy._cperror.HTTPRedirect, e: + assert e.status == 303 + assert e.urls[0] == u'/updates/TurboGears2-2.0.3-1.fc7' diff --git a/bodhi/tests/test_model.py b/bodhi/tests/test_model.py index 2ae4fd0..56f5775 100644 --- a/bodhi/tests/test_model.py +++ b/bodhi/tests/test_model.py @@ -581,11 +581,17 @@ class TestPackageUpdate(testutil.DBTest): update.release = self._get_epel_release() assert update.release.testing_tag == 'dist-5E-epel-testing'
- def test_epel_testing_tag_property(self): + def test_epel_stable_tag_property(self): update = self.get_update(name='TurboGears-1.0.2.2-2.el5') update.release = self._get_epel_release() assert update.release.stable_tag == 'dist-5E-epel'
+ def test_bullets_in_notes(self): + update = self.get_update(name='foo-1.2.3-4') + update.notes = u'\xb7' + u = PackageUpdate.byTitle('foo-1.2.3-4') + assert u.notes == u'\xb7' + def test_utf8_email(self): update = self.get_update(name='TurboGears-1.0.2.2-2.fc7') bug = self.get_bug()
commit aaab0f0055625f7426173767e938219abeaecb46 Author: Luke Macken lmacken@redhat.com Date: Sun Feb 28 15:59:08 2010 -0500
Handle the edge case where no updates are created in our save() method
diff --git a/bodhi/controllers.py b/bodhi/controllers.py index b1c3952..85f2a29 100644 --- a/bodhi/controllers.py +++ b/bodhi/controllers.py @@ -927,7 +927,10 @@ class Root(controllers.RootController): updates=updates, num_items=0, title='Updates sucessfully created!') else: - raise redirect(updates[0].get_url()) + if updates: + raise redirect(updates[0].get_url()) + else: + raise redirect('/')
@expose(template='bodhi.templates.list') @paginate('updates', limit=20, max_limit=20)
commit 600fb7981c95d7e1f9c4cd7f3e518d00261590cd Author: Luke Macken lmacken@redhat.com Date: Sun Feb 28 15:58:45 2010 -0500
Encode to utf-8 before we pass anything to SQLObject...
diff --git a/bodhi/controllers.py b/bodhi/controllers.py index ebaa8dc..b1c3952 100644 --- a/bodhi/controllers.py +++ b/bodhi/controllers.py @@ -799,6 +799,15 @@ class Root(controllers.RootController):
# Create or modify the necessary PackageUpdate objects for release, builds in releases.items(): + try: + # Encode our unicode strings to UTF-8 before they hit SQLObject + # This has fixed numerous tickets, such as #288 + notes = notes.encode('utf-8', 'replace') + type_ = type_.encode('utf8', 'replace') + except Exception, e: + log.exception(e) + log.error('Unable to convert our update to utf-8; passing ' + 'unicode strings to SQLObject.') if edited: update = edited log.debug("Editing update %s" % edited.title) @@ -815,7 +824,6 @@ class Root(controllers.RootController): build.destroySelf() else: try: - type_ = type_.encode('utf8') # hack, for ticket #288 update = PackageUpdate(title=','.join(builds), release=release, submitter=identity.current.user_name,
commit 4a966d9d050c046bce9266b763acafef6633d186 Author: Luke Macken lmacken@redhat.com Date: Sun Feb 28 15:58:11 2010 -0500
Have our save() method handle empty build lists.
diff --git a/bodhi/controllers.py b/bodhi/controllers.py index 0d60f84..ebaa8dc 100644 --- a/bodhi/controllers.py +++ b/bodhi/controllers.py @@ -548,6 +548,9 @@ class Root(controllers.RootController): }
# Basic sanity checks + if not builds: + flash_log("Error: Didn't receive any builds") + raise InvalidUpdateException(params) if type_ not in config.get('update_types'): flash_log('Unknown update type: %s. Valid types are: %s' % ( type_, config.get('update_types')))