Beispiel #1
0
 def setUp(self):
     self.hooks = Hooks()
     self.hooks.utils = mock(Utils)
     self.appdata = {}
     self.appdata["hooks"] = dict([("pre-build",
                                    "pwd && echo 'In pre build!'")])
     self.appdata["hooks"]["bad-hook-cmd"] = "garbage command"
     pass
class TestHooks(unittest.TestCase):

    def setUp(self):
        self.hooks = Hooks()
        self.hooks.utils = mock(Utils)
        self.appdata = {}
        self.appdata["hooks"] = dict(
            [("pre-build", "pwd && echo 'In pre build!'")])
        self.appdata["hooks"]["bad-hook-cmd"] = "garbage command"
        pass

    @pytest.mark.skip
    def test_run_hook_returns_zero_when_hook_succeeds(self):

        when(self.hooks.whobj).invoke_webhook(any(), any(), any()).thenReturn()
        sc = mock(StatsClient)
        when(sc).timing(any(), any()).thenReturn(any())
        when(self.hooks.utils).getStatsClient().thenReturn(sc)
        when(self.hooks.utils).get_identifier(any(), any(), any()).thenReturn(any())
        assert self.hooks.run_hook("pre-build", self.appdata, os.getcwd(), "roger-tools.pre-build-test") == 0

    @pytest.mark.skip
    def test_run_hook_returns_non_zero_when_hook_fails(self):

        when(self.hooks.whobj).invoke_webhook(any(), any(), any()).thenReturn()
        sc = mock(StatsClient)
        when(sc).timing(any(), any()).thenReturn(any())
        when(self.hooks.utils).getStatsClient().thenReturn(sc)
        when(self.hooks.utils).get_identifier(any(), any(), any()).thenReturn(any())
        assert self.hooks.run_hook(
            "bad-hook-cmd", self.appdata, os.getcwd(), "roger-tools.bad-hook-cmd-test") != 0

    @pytest.mark.skip
    def test_run_hook_returns_zero_when_hook_is_absent(self):

        when(self.hooks.whobj).invoke_webhook(any(), any(), any()).thenReturn()
        sc = mock(StatsClient)
        when(sc).timing(any(), any()).thenReturn(any())
        when(self.hooks.utils).getStatsClient().thenReturn(sc)
        when(self.hooks.utils).get_identifier(any(), any(), any()).thenReturn(any())
        assert self.hooks.run_hook(
            "absent-hook", self.appdata, os.getcwd(), "roger-tools.absent-hook-test") == 0

    @pytest.mark.skip
    def test_run_hook_preserves_current_directory(self):

        when(self.hooks.whobj).invoke_webhook(any(), any(), any()).thenReturn()
        sc = mock(StatsClient)
        when(sc).timing(any(), any()).thenReturn(any())
        when(self.hooks.utils).getStatsClient().thenReturn(sc)
        when(self.hooks.utils).get_identifier(any(), any(), any()).thenReturn(any())
        cwd = os.getcwd()
        self.hooks.run_hook("pre-build", self.appdata, "/tmp", "roger-tools.pre-build-tmp-test")
        assert cwd == os.getcwd()

    def tearDown(self):
        pass
Beispiel #3
0
class TestHooks(unittest.TestCase):
    def setUp(self):
        self.hooks = Hooks()
        self.hooks.utils = mock(Utils)
        self.appdata = {}
        self.appdata["hooks"] = dict([("pre-build",
                                       "pwd && echo 'In pre build!'")])
        self.appdata["hooks"]["bad-hook-cmd"] = "garbage command"
        pass

    @pytest.mark.skip
    def test_run_hook_returns_zero_when_hook_succeeds(self):

        when(self.hooks.whobj).invoke_webhook(any(), any(), any(), any(),
                                              any(), any()).thenReturn()
        when(self.hooks.utils).get_identifier(any(), any(),
                                              any()).thenReturn(any())
        assert self.hooks.run_hook("pre-build", self.appdata, os.getcwd(),
                                   any(), any()) == 0

    @pytest.mark.skip
    def test_run_hook_returns_non_zero_when_hook_fails(self):

        when(self.hooks.whobj).invoke_webhook(any(), any(), any(), any(),
                                              any(), any()).thenReturn()
        when(self.hooks.utils).get_identifier(any(), any(),
                                              any()).thenReturn(any())
        assert self.hooks.run_hook("bad-hook-cmd", self.appdata, os.getcwd(),
                                   any(), any(), any()) != 0

    @pytest.mark.skip
    def test_run_hook_returns_zero_when_hook_is_absent(self):

        when(self.hooks.whobj).invoke_webhook(any(), any(), any(), any(),
                                              any(), any()).thenReturn()
        when(self.hooks.utils).get_identifier(any(), any(),
                                              any()).thenReturn(any())
        assert self.hooks.run_hook("absent-hook", self.appdata, os.getcwd(),
                                   any(), any()) == 0

    @pytest.mark.skip
    def test_run_hook_preserves_current_directory(self):

        when(self.hooks.whobj).invoke_webhook(any(), any(), any(), any(),
                                              any(), any()).thenReturn()
        when(self.hooks.utils).get_identifier(any(), any(),
                                              any()).thenReturn(any())
        cwd = os.getcwd()
        self.hooks.run_hook("pre-build", self.appdata, "/tmp", any(), any())
        assert cwd == os.getcwd()

    def tearDown(self):
        pass
Beispiel #4
0
 def setUp(self):
     self.hooks = Hooks()
     self.hooks.utils = mock(Utils)
     self.appdata = {}
     self.appdata["hooks"] = dict(
         [("pre-build", "pwd && echo 'In pre build!'")])
     self.appdata["hooks"]["bad-hook-cmd"] = "garbage command"
     pass
Beispiel #5
0
                        self.task_id.extend(container_task_id)
                    except (Exception) as e:
                        print("ERROR - : %s" %e, file=sys.stderr)
                        execution_result = 'FAILURE'
                        raise
                    finally:
                        # todo: maybe send datadog event from here?
                        pass

            hookname = "post_push"
            exit_code = hooksObj.run_hook(hookname, data, app_path, args.env, settingObj.getUser())
            if exit_code != 0:
                raise ValueError("{} hook failed.".format(hookname))
            print(colored("******Done with the PUSH step******", "green"))

        except (Exception) as e:
            raise ValueError("ERROR - {}".format(e))

if __name__ == "__main__":
    settingObj = Settings()
    appObj = AppConfig()
    frameworkUtils = FrameworkUtils()
    hooksObj = Hooks()
    roger_push = RogerPush()
    try:
        roger_push.parser = roger_push.parse_args()
        roger_push.args = roger_push.parser.parse_args()
        roger_push.main(settingObj, appObj, frameworkUtils, hooksObj, roger_push.args)
    except (Exception) as e:
        printException(e)