Exemple #1
0
 def delete(self):
     """Delete this plan."""
     p_handler = plan_handler.PlanHandler(pecan.request.security_context)
     try:
         p_handler.delete(self._id)
     except (db_exc.DBError):
         raise exception.PlanStillReferenced(name=self._id)
Exemple #2
0
 def test_plan_get(self, mock_registry):
     mock_registry.Plan.get_by_uuid.return_value = {}
     handler = plan_handler.PlanHandler(self.ctx)
     res = handler.get('test_id')
     self.assertIsNotNone(res)
     get_by_uuid = mock_registry.Plan.get_by_uuid
     get_by_uuid.assert_called_once_with(self.ctx, 'test_id')
Exemple #3
0
 def test_trigger_workflow_stage_select(self, mock_kc, mock_registry):
     trigger_id = 1
     plan_obj = fakes.FakePlan()
     artifacts = [{
         "name": "Test",
         "artifact_type": "heroku",
         "content": {
             "href": "https://github.com/some/project"
         },
         "language_pack": "auto"
     }]
     plan_obj.raw_content = {"artifacts": artifacts}
     mock_registry.Plan.get_by_trigger_id.return_value = plan_obj
     handler = plan_handler.PlanHandler(self.ctx)
     handler._build_artifact = mock.MagicMock()
     handler.trigger_workflow(trigger_id, workflow=['unittest'])
     handler._build_artifact.assert_called_once_with(
         plan_obj,
         artifact=artifacts[0],
         commit_sha='',
         status_url=None,
         workflow=['unittest'],
     )
     mock_registry.Plan.get_by_trigger_id.assert_called_once_with(
         None, trigger_id)
Exemple #4
0
    def put(self):
        """Modify this plan."""
        policy.check('update_plan',
                     pecan.request.security_context)
        # make sure the plan exists before parsing the request
        handler = plan_handler.PlanHandler(pecan.request.security_context)
        handler.get(self._id)

        host_url = pecan.request.application_url.rstrip('/')
        if not pecan.request.body or len(pecan.request.body) < 1:
            raise exception.BadRequest(reason="No data.")

        if (pecan.request.content_type is not None and
                'yaml' in pecan.request.content_type):
            data = init_yml_plan_by_version()
            updated_plan_yml = yamlutils.dump(yaml_content(handler.update(
                self._id, data.as_dict(objects.registry.Plan))))
        else:
            data = init_json_plan_by_version()
            plan_obj = handler.update(self._id,
                                      data.as_dict(objects.registry.Plan))
            updated_plan_yml = wsme_json.encode_result(plan.Plan.from_db_model(
                plan_obj, host_url), plan.Plan)

        pecan.response.status = 200
        return updated_plan_yml
Exemple #5
0
 def test_plan_create(self, mock_kc, mock_registry):
     data = {'name': 'new_name', 'uuid': 'input_uuid'}
     db_obj = fakes.FakePlan()
     mock_registry.Plan.return_value = db_obj
     handler = plan_handler.PlanHandler(self.ctx)
     res = handler.create(data)
     db_obj.create.assert_called_once_with(self.ctx)
     self.assertEqual(db_obj, res)
Exemple #6
0
 def test_plan_delete(self, mock_kc, mock_destroy, mock_registry):
     db_obj = fakes.FakePlan()
     mock_registry.Plan.get_by_uuid.return_value = db_obj
     handler = plan_handler.PlanHandler(self.ctx)
     handler.delete('test_id')
     mock_destroy.assert_called_once_with(app_id=db_obj.id)
     mock_registry.Plan.get_by_uuid.assert_called_once_with(
         self.ctx, 'test_id')
Exemple #7
0
 def test_plan_delete(self, mock_registry):
     db_obj = fakes.FakePlan()
     mock_registry.Plan.get_by_uuid.return_value = db_obj
     handler = plan_handler.PlanHandler()
     handler.delete('test_id')
     db_obj.destroy.assert_called_once_with(None)
     mock_registry.Plan.get_by_uuid.assert_called_once_with(None,
                                                            'test_id')
Exemple #8
0
 def get_all(self):
     """Return all plans, based on the query provided."""
     handler = plan_handler.PlanHandler(pecan.request.security_context)
     plan_yml = yamlutils.dump([
         yaml_content(obj) for obj in handler.get_all()
         if obj and obj.raw_content
     ])
     pecan.response.status = 200
     return plan_yml
Exemple #9
0
 def test_plan_update(self, mock_registry):
     data = {'user_id': 'new_user_id'}
     db_obj = fakes.FakePlan()
     mock_registry.Plan.get_by_uuid.return_value = db_obj
     handler = plan_handler.PlanHandler()
     res = handler.update('test_id', data)
     self.assertEqual(db_obj.user_id, res.user_id)
     db_obj.save.assert_called_once_with(None)
     mock_registry.Plan.get_by_uuid.assert_called_once_with(None,
                                                            'test_id')
Exemple #10
0
    def get(self):
        """Return this plan."""
        handler = plan_handler.PlanHandler(pecan.request.security_context)

        if pecan.request.accept is not None and 'yaml' in pecan.request.accept:
            plan_serialized = yamlutils.dump(
                yaml_content(handler.get(self._id)))
        else:
            plan_model = plan.Plan.from_db_model(
                handler.get(self._id), pecan.request.host_url)
            plan_serialized = wsme_json.encode_result(plan_model, plan.Plan)
        pecan.response.status = 200
        return plan_serialized
Exemple #11
0
    def get_all(self):
        """Return all plans, based on the query provided."""
        handler = plan_handler.PlanHandler(pecan.request.security_context)

        if pecan.request.accept is not None and 'yaml' in pecan.request.accept:
            plan_serialized = yamlutils.dump([yaml_content(obj)
                                              for obj in handler.get_all()
                                              if obj and obj.raw_content])
        else:
            plan_serialized = wsme_json.encode_result(
                [plan.Plan.from_db_model(obj, pecan.request.host_url)
                 for obj in handler.get_all()],
                wsme_types.ArrayType(plan.Plan))
        pecan.response.status = 200
        return plan_serialized
Exemple #12
0
    def get(self):
        """Return this plan."""
        policy.check('show_plan',
                     pecan.request.security_context)
        handler = plan_handler.PlanHandler(pecan.request.security_context)

        host_url = pecan.request.application_url.rstrip('/')
        if pecan.request.accept is not None and 'yaml' in pecan.request.accept:
            plan_serialized = yamlutils.dump(
                yaml_content(handler.get(self._id)))
        else:
            plan_model = plan.Plan.from_db_model(
                handler.get(self._id), host_url)
            plan_serialized = wsme_json.encode_result(plan_model, plan.Plan)
        pecan.response.status = 200
        return plan_serialized
Exemple #13
0
 def test_plan_update(self, mock_registry):
     data = {
         'user_id': 'new_user_id',
         'name': 'new_name',
         'project_id': 'new_proj_id',
         'uuid': 'new_uuid'
     }
     db_obj = fakes.FakePlan()
     mock_registry.Plan.get_by_uuid.return_value = db_obj
     handler = plan_handler.PlanHandler(self.ctx)
     res = handler.update('test_id', data)
     self.assertEqual(db_obj.user_id, res.user_id)
     self.assertEqual(db_obj.name, res.name)
     self.assertEqual(db_obj.project_id, res.project_id)
     self.assertEqual(db_obj.uuid, res.uuid)
     db_obj.save.assert_called_once_with(self.ctx)
     mock_registry.Plan.get_by_uuid.assert_called_once_with(
         self.ctx, 'test_id')
Exemple #14
0
 def test_plan_update(self, mock_registry):
     data = {
         'user_id': 'new_user_id',
         'name': 'new_name',
         'project_id': 'new_proj_id',
         'uuid': 'new_uuid'
     }
     db_obj = fakes.FakePlan()
     mock_registry.Plan.get_by_uuid.return_value = db_obj
     db_obj.raw_content.update(data)
     to_update_data = {
         'name': data['name'],
         'raw_content': db_obj.raw_content
     }
     handler = plan_handler.PlanHandler(self.ctx)
     handler.update('test_id', data)
     mock_registry.Plan.update_and_save.assert_called_once_with(
         self.ctx, 'test_id', to_update_data)
Exemple #15
0
    def post(self):
        """Create a new plan."""
        if not pecan.request.body or len(pecan.request.body) < 1:
            raise exception.BadRequest(reason="No data.")

        handler = plan_handler.PlanHandler(pecan.request.security_context)

        if (pecan.request.content_type is not None and
                'yaml' in pecan.request.content_type):
            data = init_yml_plan_by_version()
            created_plan = yamlutils.dump(yaml_content(handler.create(
                data.as_dict(objects.registry.Plan))))
        else:
            data = init_json_plan_by_version()
            plan_wsme = plan.Plan.from_db_model(handler.create(
                data.as_dict(objects.registry.Plan)), pecan.request.host_url)
            created_plan = wsme_json.encode_result(plan_wsme, plan.Plan)

        pecan.response.status = 201
        return created_plan
Exemple #16
0
    def test_trigger_workflow_verify_artifact_failed(self, mock_kc,
                                                     mock_registry):

        trigger_id = 1
        plan_obj = fakes.FakePlan()
        artifacts = [{
            "name": "Test",
            "artifact_type": "heroku",
            "content": {
                "href": "https://github.com/some/project"
            },
            "language_pack": "auto"
        }]
        plan_obj.raw_content = {"artifacts": artifacts}
        mock_registry.Plan.get_by_trigger_id.return_value = plan_obj
        handler = plan_handler.PlanHandler(self.ctx)
        handler._build_artifact = mock.MagicMock()
        handler._verify_artifact = mock.MagicMock(return_value=False)
        collab_url = 'https://api.github.com/repos/u/r/collaborators/foo'
        handler.trigger_workflow(trigger_id, collab_url=collab_url)
        assert not handler._build_artifact.called
Exemple #17
0
 def delete(self):
     """Delete this plan."""
     handler = plan_handler.PlanHandler(pecan.request.security_context)
     handler.delete(self._id)
Exemple #18
0
 def get(self):
     """Return this plan."""
     handler = plan_handler.PlanHandler(pecan.request.security_context)
     plan_yml = yamlutils.dump(yaml_content(handler.get(self._id)))
     pecan.response.status = 200
     return plan_yml
Exemple #19
0
def init_plan_v1(yml_input_plan):
    plan_handler_v1 = plan_handler.PlanHandler(pecan.request.security_context)
    plan_v1 = plan.Plan(**yml_input_plan)
    return plan_handler_v1, plan_v1
Exemple #20
0
 def get(self):
     """Return this plan."""
     handler = plan_handler.PlanHandler()
     return handler.get(self._id)
Exemple #21
0
 def post(self, data):
     """Create a new plan."""
     handler = plan_handler.PlanHandler()
     return handler.create(data)
Exemple #22
0
 def test_plan_get_all(self, mock_registry):
     mock_registry.PlanList.get_all.return_value = {}
     handler = plan_handler.PlanHandler(self.ctx)
     res = handler.get_all()
     self.assertIsNotNone(res)
     mock_registry.PlanList.get_all.assert_called_once_with(self.ctx)
Exemple #23
0
 def put(self, data):
     """Modify this plan."""
     handler = plan_handler.PlanHandler()
     return handler.update(self._id, data)
Exemple #24
0
 def delete(self):
     """Delete this plan."""
     handler = plan_handler.PlanHandler()
     return handler.delete(self._id)
Exemple #25
0
 def test_plan_create(self, mock_registry):
     data = {'user_id': 'new_user_id'}
     handler = plan_handler.PlanHandler()
     res = handler.create(data)
     self.assertEqual('new_user_id', res.user_id)
Exemple #26
0
 def __init__(self, plan_id):
     super(PlanController, self).__init__()
     self._id = plan_id
     self._handler = plan_handler.PlanHandler()
Exemple #27
0
 def __init__(self):
     super(PlansController, self).__init__()
     self._handler = plan_handler.PlanHandler()
Exemple #28
0
 def get_all(self):
     """Return all plans, based on the query provided."""
     handler = plan_handler.PlanHandler()
     return handler.get_all()