Beispiel #1
0
    def test_deploy_function_exists(self, m):
        m.register_uri('PUT',
                       self.MIST_APP_URL + 'functions',
                       text="""
        {
            "name": "test-fn",
            "className": "Test",
            "path": "test-path.py",
            "defaultContext": "foo" 
        }
        """)
        # returns something by with addr
        m.register_uri('GET',
                       self.MIST_APP_URL + 'functions/test-fn',
                       text="""
        {
            "name": "test-fn",
            "className": "Test",
            "path": "test-path.py",
            "defaultContext": "foo" 
        }
        """)

        fn = models.Function('test-fn', 'Test', 'foo', 'test-path.py')
        mist = MistApp()
        res = mist.update_function(fn)
        self.assertIsInstance(res, models.Function)
        self.assertEqual(res.name, 'test-fn')
        self.assertEqual(res.class_name, 'Test')
        self.assertEqual(res.path, 'test-path.py')
        self.assertEqual(res.default_context.name, 'foo')
Beispiel #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')
Beispiel #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)
Beispiel #4
0
 def test_deploy_function(self, m):
     m.register_uri('POST', self.MIST_APP_URL + 'endpoints', text="""
     {
         "name": "test-fn",
         "className": "Test",
         "path": "test-path.py",
         "defaultContext": "foo" 
     }
     """)
     fn = models.Function('test-fn', 'Test', 'foo', 'test-path.py')
     mist = MistApp()
     res = mist.update_function(fn)
     self.assertIsInstance(res, models.Function)
     self.assertEqual(res.name, 'test-fn')
     self.assertEqual(res.class_name, 'Test')
     self.assertEqual(res.path, 'test-path.py')
     self.assertEqual(res.default_context.name, 'foo')