コード例 #1
0
ファイル: test_workflow.py プロジェクト: maniacs-ops/solum
    def test_create(self, mock_wf_insert, mock_pa, mock_registry):

        app_obj = fakes.FakeApp()
        app_id = app_obj.id
        test_cmd = app_obj.workflow_config['test_cmd']
        run_cmd = app_obj.workflow_config['run_cmd']
        mock_registry.App.get_by_id.return_value = app_obj

        workflow_data = {
            "actions": ["unittest", "build", "deploy"],
            "app_id": app_id,
            "source": app_obj.source,
            "config": app_obj.workflow_config,
            "actions": app_obj.trigger_actions
        }

        fp = fakes.FakePlan()
        mock_registry.Plan.return_value = fp

        fa = fakes.FakeAssembly()
        fa.plan_uuid = fp.uuid
        mock_registry.Assembly.return_value = fa

        wf_obj = fakes.FakeWorkflow()
        wf_obj.app_id = app_obj.id
        wf_obj.assembly = fa.id
        mock_registry.Workflow.return_value = wf_obj

        fi = fakes.FakeImage()
        mock_registry.Image.return_value = fi

        handler = workflow_handler.WorkflowHandler(self.ctx)

        res = handler.create(workflow_data,
                             commit_sha='master',
                             status_url='',
                             du_id='')
        self.assertEqual(wf_obj, res)
        git_info = {
            'source_url': app_obj.source['repository'],
            'commit_sha': app_obj.source['revision'],
            'repo_token': app_obj.source['repo_token'],
            'private': app_obj.source['private'],
            'private_ssh_key': app_obj.source['private_ssh_key'],
            'status_url': '',
        }
        mock_pa.assert_called_once_with(
            verb='launch_workflow',
            workflow=['unittest', 'build', 'deploy'],
            build_id=fa.id,
            name=fi.name,
            assembly_id=fa.id,
            git_info=git_info,
            test_cmd=test_cmd,
            ports=app_obj.ports,
            base_image_id=fi.base_image_id,
            source_format=fi.source_format,
            image_format=fi.image_format,
            run_cmd=run_cmd,
            du_id='')
コード例 #2
0
ファイル: test_app.py プロジェクト: maniacs-ops/solum
    def test_app_create_invalid_repo_url(self, mock_kc, mock_registry):
        invalid_urls_list = list()
        invalid_urls_list.append('http://github.com/skdhfskjhdks')
        invalid_urls_list.append('github.com/abc/xyz')
        invalid_urls_list.append('xyz://github.com/abc/xyz.git')
        invalid_urls_list.append('xyz://github.com/abc/xyz')
        invalid_urls_list.append('abc')
        invalid_urls_list.append('http')
        invalid_urls_list.append('git')

        for invalid_url in invalid_urls_list:
            data = {
                'name': 'fakeapp',
                'description': 'fake app for testing',
                'source': {
                    'repository': invalid_url,
                    'revision': 'master'
                }
            }
            raw_content = {'a': 'b'}
            data['raw_content'] = json.dumps(raw_content)
            self.ctx.password = '******'

            db_obj = fakes.FakeApp()
            mock_registry.App.return_value = db_obj
            handler = app_handler.AppHandler(self.ctx)

            self.assertRaises(exc.BadRequest, handler.create, data)
            assert not db_obj.create.called, 'db_obj.create called'
コード例 #3
0
 def test_app_create(self, mock_kc, mock_registry):
     data = {'name': 'fakeapp', 'description': 'fake app for testing'}
     db_obj = fakes.FakeApp()
     mock_registry.App.return_value = db_obj
     handler = app_handler.AppHandler(self.ctx)
     res = handler.create(data)
     db_obj.create.assert_called_once_with(self.ctx)
     self.assertEqual(db_obj, res)
コード例 #4
0
 def test_apps_get_all(self, AppHandler, resp_mock, request_mock):
     hand_get = AppHandler.return_value.get_all
     fake_app = fakes.FakeApp()
     hand_get.return_value = [fake_app]
     resp = app.AppsController().get_all()
     self.assertIsNotNone(resp)
     self.assertEqual(200, resp_mock.status)
     hand_get.assert_called_with()
コード例 #5
0
 def test_app_get(self, AppHandler, resp_mock, request_mock):
     fake_app = fakes.FakeApp()
     hand_get = AppHandler.return_value.get
     hand_get.return_value = fake_app
     cont = app.AppController('test_id')
     resp = cont.get()
     self.assertIsNotNone(resp)
     hand_get.assert_called_with('test_id')
     self.assertEqual(200, resp_mock.status)
コード例 #6
0
ファイル: test_app.py プロジェクト: paperandsoap/solum
 def test_app_create(self, mock_kc, mock_registry):
     data = {
         'name': 'fakeapp',
         'description': 'fake app for testing',
         'source': {
             'repository': 'https://github.com/example/a.git',
             'revision': 'master'
         }
     }
     db_obj = fakes.FakeApp()
     mock_registry.App.return_value = db_obj
     handler = app_handler.AppHandler(self.ctx)
     res = handler.create(data)
     db_obj.create.assert_called_once_with(self.ctx)
     self.assertEqual(db_obj, res)
コード例 #7
0
ファイル: test_app.py プロジェクト: maniacs-ops/solum
    def test_app_patch(self, mock_registry):
        mock_registry.App.side_effect = [mock.MagicMock(), mock.MagicMock()]
        db_obj = objects.registry.App()
        # Without this, I'd just get a mocked function call.
        # I want real data so I can track that it's being updated.
        a = fakes.FakeApp().as_dict()
        db_obj.as_dict.return_value = a
        mock_registry.App.get_by_uuid.return_value = db_obj
        # I'm not saving anything anyway, I just want to make sure
        # that I'm sending the right data to update_and_save.
        mock_registry.App.update_and_save = (
            lambda context, obj_id, data_dict: data_dict)

        # Build a phony app whose as_dict returns this dict below.
        to_update_data = {
            'name': 'newfakeapp',
            'workflow_config': {
                'run_cmd': 'newruncommand',
            },
            'source': {
                'revision': 'experimental',
            },
            'repo_token': 'abc'
        }
        handler = app_handler.AppHandler(self.ctx)
        new_app = objects.registry.App()
        new_app.as_dict.return_value = to_update_data

        # The actual call to handler.patch
        updated = handler.patch('test_id', new_app)

        self.assertEqual('newfakeapp', updated['name'])
        self.assertEqual('newruncommand',
                         updated['workflow_config']['run_cmd'])
        self.assertEqual('python ./tests.py',
                         updated['workflow_config']['test_cmd'])
        self.assertEqual('http://github.com/example/a.git',
                         updated['source']['repository'])
        self.assertEqual('experimental', updated['source']['revision'])
コード例 #8
0
 def setUp(self):
     super(TestAuth, self).setUp()
     self.CONF = self.useFixture(config.Config())
     self.app = fakes.FakeApp()