Example #1
0
    def test_push(self):
        """Tests standard push command"""
        ctx = Context()

        # Force the return of fake service
        self.mock_api_service.get_applications.return_value = self.GET_APP_RESPONSE

        a = Application.push(ctx,
                             source_directory=self.SOURCE_DIR,
                             name=self.APP_NAME,
                             bound_services=self.BOUND_SERVICES,
                             env=self.ENV)

        assert a == Application(self.APP_NAME, self.APP_ID, self.APP_STATE,
                                self.APP_INSTANCES, self.APP_URLS,
                                self.APP_BINDINGS)

        assert a._client == self.user_admin

        # Now push the application but with non-standard client
        a = Application.push(ctx,
                             source_directory=self.SOURCE_DIR,
                             name=self.APP_NAME,
                             bound_services=self.BOUND_SERVICES,
                             env=self.ENV,
                             client=self.user_luser)

        assert a == Application(self.APP_NAME, self.APP_ID, self.APP_STATE,
                                self.APP_INSTANCES, self.APP_URLS,
                                self.APP_BINDINGS)

        assert a._client == self.user_luser
Example #2
0
    def test_push_fail(self):
        """Try pushing the app, but it doesn't appear in the response"""
        ctx = Context()

        # Force the return of fake service
        self.mock_api_service_bad.api_get_app_list.return_value = self.GET_APP_BAD_RESPONSE

        with pytest.raises(AssertionError):
            a = Application.push(ctx, self.SOURCE_DIR, self.APP_NAME,
                                 self.BOUND_SERVICES, self.ENV)
Example #3
0
    def test_push_not_created(self):
        """Try pushing the app, the push succedeed, but somehow the application
        isn't visible. Ensure the message is informative."""
        ctx = Context()

        # Force the return of fake service
        self.mock_api_service_bad.api_get_app_list.return_value = []

        with pytest.raises(AssertionError) as ex:
            a = Application.push(ctx, self.SOURCE_DIR, self.APP_NAME,
                                 self.BOUND_SERVICES, self.ENV)

        msg = "App " + self.APP_NAME + " has not been created on the Platform"
        assert msg in ex.__str__()
Example #4
0
    def test_push_tap_exception(self):
        """Try pushing the app, but exception was raised by TapCli"""
        ctx = Context()

        # Force the return of fake service
        self.mock_api_service.api_get_app_list.return_value = self.GET_APP_RESPONSE

        # Force the exception raising
        mock_TapCli = MagicMock()
        mock_TapCli.push.side_effect = Exception("Bang, bang!")
        self.mock_tap_cli_exception.return_value = mock_TapCli

        with pytest.raises(Exception):
            a = Application.push(ctx, self.SOURCE_DIR, self.APP_NAME,
                                 self.BOUND_SERVICES, self.ENV)

        self.mock_api_service.delete_application.assert_called_once_with(
            self.APP_ID, self.user_admin)
Example #5
0
    def test_push_has_stopped(self):
        """Pushes an application that will be in stopped state. Verifies that
        the is_stopped property doesn't crash anything."""
        ctx = Context()

        # Force the return of fake service
        rep = copy.deepcopy(self.GET_APP_RESPONSE)
        rep.data[0]["state"] = "stopped"
        self.mock_api_service.get_applications.return_value = rep

        a = Application.push(ctx,
                             source_directory=self.SOURCE_DIR,
                             name=self.APP_NAME,
                             bound_services=self.BOUND_SERVICES,
                             env=self.ENV)

        assert a == Application(self.APP_NAME, self.APP_ID, "stopped",
                                self.APP_INSTANCES, self.APP_URLS,
                                self.APP_BINDINGS)
        assert a._client == self.user_admin
        assert a.is_stopped == True
        assert a.is_running == False