#1191 frontend: manage.py: propagate return values to cmdline
Merged 4 years ago by praiskup. Opened 4 years ago by praiskup.
Unknown source fix-click  into  master

@@ -69,8 +69,9 @@

              if value:

                  setattr(action, attr, value)

  

-             if attr == "result" and value in [BackendResultEnum("success"), BackendResultEnum("waiting")]:

-                 setattr(action, "ended_on", time.time())

+         if upd_dict.get('result', None) in [BackendResultEnum("success"),

+                                             BackendResultEnum("failure")]:

+             action.ended_on = time.time()

          db.session.add(action)

  

      @classmethod

@@ -1023,12 +1023,6 @@

  

      @property

      def status(self):

-         if getattr(self, '_cached_status_set') is None:

-             self._cached_status = self._status()

-             self._cached_status_set = True

-         return self._cached_status

- 

-     def _status(self):

          """

          Return build status.

          """

@@ -4,6 +4,7 @@

  import os

  import sys

  import copy

+ from functools import wraps

  import pipes

  import importlib

  import click
@@ -83,8 +84,21 @@

      "delete_orphans",

  ]

  

+ 

+ def always_exit(function):

+     """

+     Decorate click command function so it always exits, so each 'return STATUS'

+     is actually propagated to shell.

+     """

+     @wraps(function)

+     def wrapper(*args, **kwargs):

+         sys.exit(bool(function(*args, **kwargs)))

+     return wrapper

+ 

+ 

  for command in commands_list:

      cmd_obj = getattr(getattr(commands, command), command)

+     cmd_obj.callback = always_exit(cmd_obj.callback)

  

      # Add underscored commands, e.g. 'add_user' for 'add-user' for compatibility

      # reasons.  TODO: we can drop this once we have the deployment scripts fixed

@@ -1,5 +1,7 @@

  import json

  

+ from unittest import mock

+ 

  from copr_common.enums import BackendResultEnum, StatusEnum

  from tests.coprs_test_case import CoprsTestCase, new_app_context

  from coprs.logic.builds_logic import BuildsLogic
@@ -300,25 +302,24 @@

      {

        "id": 1,

        "result": 1,

-       "message": null,

-       "ended_on": 1390866440

+       "message": null

      },

      {

        "id": 2,

        "result": 2,

-       "message": "problem!",

-       "ended_on": 1390866440

+       "message": "problem!"

      },

      {

        "id": 100,

        "result": 123,

-       "message": "wheeeee!",

-       "ended_on": 1390866440

+       "message": "wheeeee!"

      }

    ]

  }"""

  

-     def test_update_one_action(self, f_users, f_coprs, f_actions, f_db):

+     @mock.patch('coprs.logic.actions_logic.time.time')

+     def test_update_one_action(self, mc_time, f_users, f_coprs, f_actions, f_db):

+         mc_time.return_value = 1390866440

          r = self.tc.post("/backend/update/",

                           content_type="application/json",

                           headers=self.auth_header,
@@ -332,9 +333,12 @@

          assert updated.message == "no problem"

          assert updated.ended_on == 1390866440

  

-     def test_update_more_existent_and_non_existent_actions(self, f_users,

-                                                           f_coprs, f_actions,

-                                                           f_db):

+ 

+     @mock.patch('coprs.logic.actions_logic.time.time')

+     def test_update_more_existent_and_non_existent_actions(self, mc_time, f_users,

+                                                            f_coprs, f_actions,

+                                                            f_db):

+         mc_time.return_value = 1390866440

          r = self.tc.post("/backend/update/",

                           content_type="application/json",

                           headers=self.auth_header,

It turned out that some tests failed in 'manage.py test', but the
command returned exit status 0. This seems to be the design of click:
https://github.com/pallets/click/issues/747

rebased onto 4b76176c97c2f7b29eb2758731538d39952a3dcf

4 years ago

2 new commits added

  • frontend: fix testsuite broken by a34ad40c260e8e61
  • frontend: fix tests broken by b18cf83599a988fa
4 years ago

3 new commits added

  • frontend: fix testsuite broken by a34ad40c260e8e61
  • frontend: fix testsuite broken by b18cf83599a988fa
  • frontend: manage.py: propagate return values to cmdline
4 years ago

rebased onto 865af7c

4 years ago

This is serious problem, our CI doesn't show valid results for copr-frontend.
Can we please merge today?

Pull-Request has been merged by praiskup

4 years ago