Repository: fedora-infra/bodhi

Issue:
Days to stable is displayed as a negative number on updates that can be pushed
I noticed today that an update that was eligible to be pushed to stable yesterday shows "days to stable" as -1:

https://bodhi.stg.fedoraproject.org/updates/FEDORA-2017-d0d830d7d2

It probably makes sense to either not show this field when the number is negative, or to render it as 0.
Days to stable is displayed as a negative number on updates that can be pushed
I noticed today that an update that was eligible to be pushed to stable yesterday shows "days to stable" as -1:

https://bodhi.stg.fedoraproject.org/updates/FEDORA-2017-d0d830d7d2

It probably makes sense to either not show this field when the number is negative, or to render it as 0.


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
@@ -979,6 +979,20 @@ def validate_builds(self, key, build):
             raise ValueError(u'An update must contain builds of the same type.')
         return build
 
+    @property
+    def mandatory_days_in_testing(self):
+        """
+        Calculate and return how many days an update should be in testing before becoming stable.
+
+        :return: The number of mandatory days in testing.
+        :rtype:  int
+        """
+        if self.critpath:
+            return int(config.get('critpath.stable_after_days_without_negative_karma'))
+
+        days = self.release.mandatory_days_in_testing
+        return days if days else 0
+
     @property
     def karma(self):
         """
@@ -1481,7 +1495,7 @@ def set_request(self, db, action, username):
             else:
                 # If we haven't met the stable karma requirements, check if it
                 # has met the mandatory time-in-testing requirements
-                if self.release.mandatory_days_in_testing:
+                if self.mandatory_days_in_testing:
                     if not self.met_testing_requirements and \
                        not self.meets_testing_requirements:
                         if self.release.id_prefix == "FEDORA-EPEL":
@@ -2127,6 +2141,8 @@ def meets_testing_requirements(self):
         If this release does not have a mandatory testing requirement, then
         simply return True.
         """
+        num_days = self.mandatory_days_in_testing
+
         if self.critpath:
             # Ensure there is no negative karma. We're looking at the sum of
             # each users karma for this update, which takes into account
@@ -2138,10 +2154,8 @@ def meets_testing_requirements(self):
             for karma in feedback.values():
                 if karma < 0:
                     return False
-            num_days = int(config.get('critpath.stable_after_days_without_negative_karma'))
             return self.days_in_testing >= num_days
 
-        num_days = self.release.mandatory_days_in_testing
         if not num_days:
             return True
 
@@ -2166,7 +2180,7 @@ def met_testing_requirements(self):
         If this release does not have a mandatory testing requirement, then
         simply return True.
         """
-        min_num_days = self.release.mandatory_days_in_testing
+        min_num_days = self.mandatory_days_in_testing
         if min_num_days:
             if not self.meets_testing_requirements:
                 return False
@@ -2190,7 +2204,7 @@ def days_to_stable(self):
         mandatory_days_in_testing or longer."""
         if not self.meets_testing_requirements and self.date_testing:
             return (
-                self.release.mandatory_days_in_testing -
+                self.mandatory_days_in_testing -
                 (datetime.utcnow() - self.date_testing).days)
         return 0
 


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
@@ -360,6 +360,52 @@ def test_builds(self):
         eq_(self.obj.builds[0].release.name, u'F11')
         eq_(self.obj.builds[0].package.name, u'TurboGears')
 
+    def test_mandatory_days_in_testing_critpath(self):
+        """
+        The Update.mandatory_days_in_testing method should be the configured value
+        for critpath if it is a critpath update.
+        """
+        update = self.obj
+        update.critpath = True
+
+        # Configured value.
+        expected = int(config.get('critpath.stable_after_days_without_negative_karma'))
+
+        eq_(update.mandatory_days_in_testing, expected)
+
+    def test_mandatory_days_in_testing(self):
+        """
+        The Update.mandatory_days_in_testing method should be a positive integer if the
+        mandatory_days_in_testing attribute of release is not truthy.
+        """
+        update = self.obj
+
+        eq_(update.mandatory_days_in_testing, 7)
+
+    @mock.patch.dict('bodhi.server.models.config', {'fedora.mandatory_days_in_testing': '0'})
+    def test_mandatory_days_in_testing_false(self):
+        """
+        The Update.mandatory_days_in_testing method should be 0 if the
+        mandatory_days_in_testing attribute of release is not truthy.
+        """
+        update = self.obj
+
+        eq_(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
+        on the configuration.
+        """
+        update = self.get_update()
+        update.critpath = True
+        update.date_testing = datetime.utcnow() + timedelta(days=-4)
+
+        criptath_days_to_stable = int(
+            config.get('critpath.stable_after_days_without_negative_karma'))
+
+        eq_(update.days_to_stable, criptath_days_to_stable - 4)
+
     def test_days_to_stable_meets_testing_requirements(self):
         """
         The Update.days_to_stable() method should return 0 if Update.meets_testing_requirements()