Esempio n. 1
0
    def test_mist_cli_apply_ordered(self):
        mist_app = app.MistApp()

        mist_app.get_function_json = MagicMock(
            return_value=self.test_function_obj)
        fn_depl = models.Deployment(
            'test-1', 'Function',
            ConfigTree({
                'path': 'test-3.jar',
                'context': 'test-2'
            }))
        ctx_depl = models.Deployment('test-2', 'Context', ConfigTree())
        artifact_depl = models.Deployment(
            'test-3', 'Artifact', ConfigTree({'file-path': 'test-path.jar'}),
            '0.0.1')
        mist_app.parse_deployment = MagicMock(side_effect=[
            (20, fn_depl),
            (0, ctx_depl),
            (10, artifact_depl),
        ])

        mist_app.update_deployments = MagicMock(return_value=None)
        res = self.runner.invoke(cli.apply, ('--file', self.apply_job_path),
                                 obj=mist_app)
        mist_app.update_deployments.assert_called_once_with(
            [ctx_depl, artifact_depl, fn_depl])
        calls = [
            call(self.fn_apply_file),
            call(self.ctx_file_apply),
            call(self.test_apply_file_artifact)
        ]
        mist_app.parse_deployment.assert_has_calls(calls, any_order=True)

        self.assertEqual(res.exit_code, 0)
Esempio n. 2
0
    def test_update_deployment(self, m):
        mist = MistApp()
        artifact = models.Artifact('test-artifact.py', 'test-artifact.py')
        context = models.Context('test-context')
        fn = models.Function('test-fn', 'Test', 'test-context', 'test-path.py')
        mist.artifact_parser.parse = MagicMock(return_value=artifact)
        mist.context_parser.parse = MagicMock(return_value=context)
        mist.function_parser.parse = MagicMock(return_value=fn)
        mist._MistApp__upload_artifact = MagicMock(return_value=artifact)
        mist.update_context = MagicMock(return_value=context)
        mist.update_function = MagicMock(return_value=fn)
        mist._validate_artifact = MagicMock(return_value=None)
        mist._validate_function = MagicMock(return_value=None)
        mist._validate_context = MagicMock(return_value=None)

        mist.update(
            models.Deployment('test-artifact.py', 'Artifact',
                              ConfigTree(**{'file-path': 'test-path.py'})))
        mist.update(models.Deployment('test-context', 'Context', ConfigTree()))
        mist.update(models.Deployment('test-fn', 'Function', ConfigTree()))
        call_artifact = mist._MistApp__upload_artifact.call_args[0][0]
        call_fn = mist.update_function.call_args[0][0]
        call_context = mist.update_context.call_args[0][0]
        self.assertEqual(call_artifact.name, 'test-artifact.py')
        self.assertEqual(call_context.name, 'test-context')
        self.assertEqual(call_fn.name, 'test-fn')
Esempio n. 3
0
    def test_update_deployments_should_catch_exceptions(self, m):
        mist = MistApp(validate=False)

        context = models.Context('test-context')
        fn = models.Function('test-fn', 'Test', 'test-context', 'test-path.py')
        mist.update_function = MagicMock(return_value=fn)
        mist.update_context = MagicMock(return_value=context)
        mist.context_parser.parse = MagicMock(return_value=context)
        mist.function_parser.parse = MagicMock(return_value=fn)

        depls = [
            models.Deployment('simple', 'Function', ConfigTree()),
            models.Deployment('simple-ctx', 'Context', ConfigTree())
        ]

        mist.update_deployments(depls)
Esempio n. 4
0
    def test_mist_cli_apply_file(self):
        mist_app = app.MistApp()
        mist_app.get_function_json = MagicMock(
            return_value=self.test_function_obj)
        mist_app.parse_deployment = MagicMock(return_value=(
            0,
            models.Deployment('test', 'Artifact',
                              ConfigTree({'file-path': 'test-path.jar'}),
                              '0.0.1')))
        mist_app.update_deployments = MagicMock(return_value=None)

        res = self.runner.invoke(cli.apply,
                                 ('--file', self.test_apply_file_artifact),
                                 obj=mist_app)
        self.assertEqual(res.exit_code, 0)