#219 Keep the original state_reason when removing the compose.
Merged 8 months ago by jkaluza. Opened 8 months ago by jkaluza.

@@ -172,9 +172,13 @@ 

              log.info("%r: Removing compose", compose)

              compose.state = COMPOSE_STATES["removed"]

              if compose.removed_by:

-                 compose.state_reason = "Removed by {}".format(compose.removed_by)

+                 state_reason = "Removed by {}.".format(compose.removed_by)

              else:

-                 compose.state_reason = "Compose is expired"

+                 state_reason = "Compose is expired."

+             if compose.state_reason:

+                 compose.state_reason += "\n%s" % state_reason

+             else:

+                 compose.state_reason = state_reason

              compose.time_removed = datetime.utcnow()

              db.session.commit()

              if not compose.reused_id:

@@ -80,7 +80,23 @@ 

          db.session.expunge_all()

          c = db.session.query(Compose).filter(Compose.id == 1).one()

          self.assertEqual(c.state, COMPOSE_STATES["removed"])

-         self.assertEqual(c.state_reason, 'Compose is expired')

+         self.assertEqual(c.state_reason, 'Compose is expired.')

+ 

+     def test_a_compose_which_state_is_done_is_removed_keep_state_reason(self):

+         """

+         Test that we do remove a compose in done state.

+         """

+         c = db.session.query(Compose).filter(Compose.id == 1).one()

+         c.time_to_expire = datetime.utcnow() - timedelta(seconds=120)

+         c.state = COMPOSE_STATES["done"]

+         c.state_reason = "Generated successfully."

+         db.session.add(c)

+         db.session.commit()

+         self.thread.do_work()

+         db.session.expunge_all()

+         c = db.session.query(Compose).filter(Compose.id == 1).one()

+         self.assertEqual(c.state, COMPOSE_STATES["removed"])

+         self.assertEqual(c.state_reason, 'Generated successfully.\nCompose is expired.')

  

      def test_does_not_remove_a_compose_which_is_not_expired(self):

          """

When compose expires or is removed, we replace the original state_reason with "Compose is expired." or "Removed by $user" message. This overrides the original state_reason which makes it hard to find out what actually happened to compose earlier.

Instead of replacing the state_reason, the state_reason is now appended to original state_reason.

Pull-Request has been merged by jkaluza

8 months ago