Skip to content

Commit

Permalink
Display the content type of updates in the UI.
Browse files Browse the repository at this point in the history
fixes fedora-infra#1329

Signed-off-by: Randy Barlow <randy@electronsweatshop.com>
  • Loading branch information
bowlofeggs committed May 30, 2017
1 parent 984ca8c commit 2515cd4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
7 changes: 5 additions & 2 deletions bodhi/server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,9 +1372,12 @@ def content_type(self):
""" Return the ContentType associated with this Update.
If the update has no builds, this evaluates to `None`.
Returns:
ContentType or None: The content type of this Update or None.
"""
if self.builds:
return self.builds[0].type.value
return self.builds[0].type

def obsolete_older_updates(self, db):
"""Obsolete any older pending/testing updates.
Expand Down Expand Up @@ -2379,7 +2382,7 @@ def __json__(self, request=None, anonymize=False):
# Include the karma total in the results
result['karma'] = self.karma
# Also, the Update content_type (derived from the builds content_types)
result['content_type'] = self.content_type
result['content_type'] = self.content_type.value if self.content_type else None

# For https://github.com/fedora-infra/bodhi/issues/270, throw the JSON
# of the test cases in our output as well but take extra care to
Expand Down
11 changes: 11 additions & 0 deletions bodhi/server/templates/update.html
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,17 @@ <h5 class="m-t-2">
<div class="card">
<div class="card-block">

% if update.content_type:
<div class="p-b-1">
<div>
<strong>Content Type</strong>
</div>
<div>
${update.content_type.description | n}
</div>
</div>
% endif

<div class="p-b-1">
<div>
<strong>Status</strong>
Expand Down
17 changes: 17 additions & 0 deletions bodhi/tests/server/services/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,23 @@ def test_obsoletion_with_exception(self, *args):

class TestUpdatesService(bodhi.tests.server.functional.base.BaseWSGICase):

def test_content_type(self):
"""Assert that the content type is displayed in the update template."""
res = self.app.get('/updates/bodhi-2.0-1.fc17', status=200, headers={'Accept': 'text/html'})

self.assertTrue(
('<strong>Content Type</strong>\n </div>\n <div>\n'
' RPM') in res.text)

def test_content_type_none(self):
"""Assert that the content type being None doesn't blow up the update template."""
u = Update.query.filter(Update.title == u'bodhi-2.0-1.fc17').one()
u.builds = []
self.db.commit()
res = self.app.get('/updates/bodhi-2.0-1.fc17', status=200, headers={'Accept': 'text/html'})

self.assertTrue('RPM' not in res.text)

def test_home_html(self):
resp = self.app.get('/', headers={'Accept': 'text/html'})
self.assertIn('Fedora Updates System', resp)
Expand Down
8 changes: 7 additions & 1 deletion bodhi/tests/server/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,12 @@ def get_update(self, name=u'TurboGears-1.0.8-3.fc11'):
release=rel))
return self.klass(**attrs)

def test___json___with_no_builds(self):
"""Test the __json__() method when there are no Builds."""
self.obj.builds = []

eq_(self.obj.__json__()['content_type'], None)

def test_autokarma_not_nullable(self):
"""Assert that the autokarma column does not allow NULL values.
Expand All @@ -566,7 +572,7 @@ def test_builds(self):
eq_(self.obj.builds[0].package.name, u'TurboGears')

def test_content_type(self):
eq_(self.obj.content_type, 'rpm')
eq_(self.obj.content_type, model.ContentType.rpm)

def test_mandatory_days_in_testing_critpath(self):
"""
Expand Down

0 comments on commit 2515cd4

Please sign in to comment.