Пример #1
0
 def test_validate_methods(self, m):
     m.register_uri('GET', self.MIST_APP_URL + 'artifacts/test-name.jar/sha', text="SOME_CONTENT")
     m.register_uri('GET', self.MIST_APP_URL + 'artifacts/unknown.jar/sha', status_code=404)
     m.register_uri('GET', self.MIST_APP_URL + 'contexts/test-ctx', text="""
     {
       "name": "simple",
       "maxJobs": 20,
       "workerMode": "shared",
       "precreated": false,
       "sparkConf": {
         "spark.executor.memory": "256m",
         "spark.driver.memory": "512m"
       },
       "runOptions": "",
       "downtime": "Inf",
       "streamingDuration": "1s"
     }
     """)
     m.register_uri('GET', self.MIST_APP_URL + 'contexts/unknown-ctx', status_code=404)
     mist = MistApp()
     with self.assertRaises(ValueError):
         mist._validate_artifact(models.Artifact('test-name', 'test-name.jar'))
     mist._validate_artifact(models.Artifact('unknown', 'test-name.jar'))
     mist._validate_context(models.Context('test'))
     fn1 = models.Function('test', 'Test', 'test-ctx', path='test-name.jar')
     mist._validate_function(fn1)
     fn2 = models.Function('test', 'Test', 'unknown-ctx', path='unknown.jar')
     with self.assertRaises(ValueError):
         mist._validate_function(fn2)
     fn3 = models.Function('test', 'Test', 'test-ctx', path='unknown.jar')
     with self.assertRaises(ValueError):
         mist._validate_function(fn3)
Пример #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')