Repository: fedora-infra/bodhi

Issue:
Home page does not load due to mandatory_days_in_testing() raising TypeError
The home page currently does not load in the development environment due to a ```TypeError``` from ```mandatory_days_in_testing()```:

```
Traceback (most recent call last):
  File "/home/vagrant/bodhi/bodhi/server/services/errors.py", line 104, in __init__
    summary=status2summary(errors.status),
  File "/usr/lib/python2.7/site-packages/mako/template.py", line 462, in render
    return runtime._render(self, self.callable_, args, data)
  File "/usr/lib/python2.7/site-packages/mako/runtime.py", line 838, in _render
    **_kwargs_for_callable(callable_, data))
  File "/usr/lib/python2.7/site-packages/mako/runtime.py", line 873, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "/usr/lib/python2.7/site-packages/mako/runtime.py", line 899, in _exec_template
    callable_(context, *args, **kwargs)
  File "/home/vagrant/bodhi/bodhi/server/templates/master.html", line 110, in render_body
    % for state in request.releases:
  File "/usr/lib/python2.7/site-packages/pyramid/decorator.py", line 42, in __get__
    val = self.wrapped(inst)
  File "/usr/lib/python2.7/site-packages/pyramid/util.py", line 78, in <lambda>
    fn = lambda this: callable(this)
  File "/home/vagrant/bodhi/bodhi/server/__init__.py", line 180, in get_releases
    return Release.all_releases(request.db)
  File "/home/vagrant/bodhi/bodhi/server/models.py", line 861, in all_releases
    releases[release.state.value].append(release.__json__())
  File "/home/vagrant/bodhi/bodhi/server/models.py", line 344, in __json__
    return self._to_json(self, request=request, anonymize=anonymize)
  File "/home/vagrant/bodhi/bodhi/server/models.py", line 373, in _to_json
    d[attr] = cls._expand(obj, getattr(obj, attr), seen, request)
  File "/home/vagrant/bodhi/bodhi/server/models.py", line 409, in _expand
    return [cls._expand(obj, item, seen, req) for item in relation]
  File "/home/vagrant/bodhi/bodhi/server/models.py", line 411, in _expand
    return cls._to_json(relation, seen + [type(obj)], req)
  File "/home/vagrant/bodhi/bodhi/server/models.py", line 362, in _to_json
    attribute = getattr(obj, name)
  File "/home/vagrant/bodhi/bodhi/server/models.py", line 3101, in meets_testing_requirements
    num_days = self.mandatory_days_in_testing
  File "/home/vagrant/bodhi/bodhi/server/models.py", line 1610, in mandatory_days_in_testing
    days = self.release.mandatory_days_in_testing
  File "/home/vagrant/bodhi/bodhi/server/models.py", line 831, in mandatory_days_in_testing
    self.id_prefix.lower().replace('-', '_')))
TypeError: int() argument must be a string or a number, not 'NoneType'
```


Discussion:

Resolving patch:
diff --git a/bodhi/server/models.py b/bodhi/server/models.py
--- a/bodhi/server/models.py
+++ b/bodhi/server/models.py
@@ -826,11 +826,13 @@ def mandatory_days_in_testing(self):
                 '%s.%s.mandatory_days_in_testing' % (name, status)))
             if days:
                 return days
-        days = int(config.get('%s.mandatory_days_in_testing' %
-                              self.id_prefix.lower().replace('-', '_')))
-        if not days:
-            log.warn('No mandatory days in testing defined for %s' % self.name)
-        return days
+        days = config.get('%s.mandatory_days_in_testing' %
+                          self.id_prefix.lower().replace('-', '_'))
+        if days is None:
+            log.warn('No mandatory days in testing defined for %s. Defaulting to 0.' % self.name)
+            return 0
+        else:
+            return int(days)
 
     @property
     def collection_name(self):


Test patch:
diff --git a/bodhi/tests/server/test_models.py b/bodhi/tests/server/test_models.py
--- a/bodhi/tests/server/test_models.py
+++ b/bodhi/tests/server/test_models.py
@@ -1,5 +1,8 @@
 # -*- coding: utf-8 -*-
-
+# Copyright © 2011-2017 Red Hat, Inc. and others.
+#
+# This file is part of Bodhi.
+#
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
 # as published by the Free Software Foundation; either version 2
@@ -1331,6 +1334,13 @@ def test_mandatory_days_in_testing_false(self):
 
         self.assertEqual(update.mandatory_days_in_testing, 0)
 
+    @mock.patch.dict('bodhi.server.models.config', {}, clear=True)
+    def test_mandatory_days_in_testing_release_not_configured(self):
+        """mandatory_days_in_testing() should return 0 if there is no config for the release."""
+        update = self.obj
+
+        self.assertEqual(update.mandatory_days_in_testing, 0)
+
     def test_days_to_stable_critpath(self):
         """
         The Update.days_to_stable() method should return a positive integer depending