Esempio n. 1
0
 def test_trigger_post_on_comment_missing_login(self, mock_policy,
                                                assem_mock, resp_mock,
                                                request_mock):
     mock_policy.return_value = True
     cfg.CONF.api.rebuild_phrase = "solum retry tests"
     status_url = 'https://api.github.com/repos/u/r/statuses/{sha}'
     collab_url = ('https://api.github.com/repos/u/r/' +
                   'collaborators{/collaborator}')
     body_dict = {
         'sender': {
             'url': 'https://api.github.com'
         },
         'comment': {
             'commit_id': 'asdf',
             'body': 'solum retry tests',
             'user': '******'
         },
         'repository': {
             'statuses_url': status_url,
             'collaborators_url': collab_url,
             'private': False
         }
     }
     request_mock.body = json.dumps(body_dict)
     obj = trigger.TriggerController()
     obj.post('test_id')
     self.assertEqual(400, resp_mock.status)
     tw = assem_mock.return_value.trigger_workflow
     assert not tw.called
Esempio n. 2
0
 def test_trigger_process_request_on_valid_pub_repo(self, assem_mock,
                                                    resp_mock,
                                                    request_mock):
     cfg.CONF.api.rebuild_phrase = "solum retry tests"
     status_url = 'https://api.github.com/repos/u/r/statuses/{sha}'
     collab_url = ('https://api.github.com/repos/u/r/' +
                   'collaborators{/collaborator}')
     body_dict = {
         'sender': {
             'url': 'https://api.github.com'
         },
         'comment': {
             'commit_id': 'asdf',
             'body': 'solum retry tests',
             'user': {
                 'login': '******'
             }
         },
         'repository': {
             'statuses_url': status_url,
             'collaborators_url': collab_url,
             'private': False
         }
     }
     obj = trigger.TriggerController()
     commit_sha, collab_url = obj._process_request(body_dict)
     self.assertEqual('https://api.github.com/repos/u/r/collaborators/u',
                      collab_url)
     self.assertEqual('asdf', commit_sha)
Esempio n. 3
0
 def test_trigger_post_on_mismatch_comment_pub_repo(self, http_mock,
                                                    mock_policy, assem_mock,
                                                    resp_mock,
                                                    request_mock):
     mock_policy.return_value = True
     cfg.CONF.api.rebuild_phrase = "solum retry tests"
     status_url = 'https://api.github.com/repos/u/r/statuses/{sha}'
     collab_url = ('https://api.github.com/repos/u/r/' +
                   'collaborators{/collaborator}')
     body_dict = {
         'sender': {
             'url': 'https://api.github.com'
         },
         'action': 'created',
         'comment': {
             'commit_id': 'asdf',
             'body': 'solum is awesome',
             'user': {
                 'login': '******'
             }
         },
         'repository': {
             'statuses_url': status_url,
             'collaborators_url': collab_url,
             'private': False
         }
     }
     request_mock.body = json.dumps(body_dict)
     http_mock.return_value = ({'status': '204'}, '')  # a collaborator
     obj = trigger.TriggerController()
     obj.post('test_id')
     self.assertEqual(403, resp_mock.status)
     tw = assem_mock.return_value.trigger_workflow
     assert not tw.called
Esempio n. 4
0
 def test_trigger_post_on_github_comment_webhook(self, assem_mock,
                                                 resp_mock, request_mock):
     cfg.CONF.api.rebuild_phrase = "solum retry tests"
     status_url = 'https://api.github.com/repos/u/r/statuses/{sha}'
     collab_url = ('https://api.github.com/repos/u/r/' +
                   'collaborators{/collaborator}')
     body_dict = {
         'sender': {
             'url': 'https://api.github.com'
         },
         'action': 'created',
         'comment': {
             'commit_id': 'asdf',
             'body': '  SOLUM retry tests ',
             'user': {
                 'login': '******'
             }
         },
         'repository': {
             'statuses_url': status_url,
             'collaborators_url': collab_url,
             'private': True
         }
     }
     expected_st_url = 'https://api.github.com/repos/u/r/statuses/asdf'
     request_mock.body = json.dumps(body_dict)
     obj = trigger.TriggerController()
     obj.post('test_id')
     self.assertEqual(202, resp_mock.status)
     tw = assem_mock.return_value.trigger_workflow
     tw.assert_called_once_with('test_id',
                                'asdf',
                                expected_st_url,
                                None,
                                workflow=None)
Esempio n. 5
0
 def test_trigger_post_on_github_webhook(self, mock_policy, assem_mock,
                                         resp_mock, request_mock):
     mock_policy.return_value = True
     status_url = 'https://api.github.com/repos/u/r/statuses/{sha}'
     body_dict = {
         'sender': {
             'url': 'https://api.github.com'
         },
         'action': 'opened',
         'pull_request': {
             'head': {
                 'sha': 'asdf'
             }
         },
         'repository': {
             'statuses_url': status_url
         }
     }
     expected_st_url = 'https://api.github.com/repos/u/r/statuses/asdf'
     request_mock.body = json.dumps(body_dict)
     obj = trigger.TriggerController()
     obj.post('test_id')
     self.assertEqual(202, resp_mock.status)
     tw = assem_mock.return_value.trigger_workflow
     tw.assert_called_once_with('test_id',
                                'asdf',
                                expected_st_url,
                                None,
                                workflow=None)
Esempio n. 6
0
 def test_trigger_post_with_empty_body(self, assem_mock, resp_mock,
                                       request_mock):
     obj = trigger.TriggerController()
     obj.post('test_id')
     self.assertEqual(400, resp_mock.status)
     tw = assem_mock.return_value.trigger_workflow
     assert not tw.called
Esempio n. 7
0
 def test_trigger_post_on_unknown_git_webhook(self, assem_mock, resp_mock,
                                              request_mock):
     body_dict = {"pull_request": {"head": {"sha": "asdf"}}}
     request_mock.body = json.dumps(body_dict)
     obj = trigger.TriggerController()
     obj.post('test_id')
     self.assertEqual(501, resp_mock.status)
     tw = assem_mock.return_value.trigger_workflow
     assert not tw.called
Esempio n. 8
0
 def test_trigger_post_on_github_ping_webhook(self, assem_mock, resp_mock,
                                              request_mock):
     body_dict = {
         "sender": {
             "url": "https://api.github.com"
         },
         "zen": "Keep it logically awesome."
     }
     request_mock.body = json.dumps(body_dict)
     obj = trigger.TriggerController()
     obj.post('test_id')
     self.assertEqual(501, resp_mock.status)
     tw = assem_mock.return_value.trigger_workflow
     assert not tw.called
Esempio n. 9
0
 def test_trigger_post_on_non_github_webhook(self, mock_policy, assem_mock,
                                             resp_mock, request_mock):
     mock_policy.return_value = True
     body_dict = {
         "sender": {
             "url": "https://non-github.com"
         },
         "pull_request": {
             "head": {
                 "sha": "asdf"
             }
         }
     }
     request_mock.body = json.dumps(body_dict)
     obj = trigger.TriggerController()
     obj.post('test_id')
     self.assertEqual(501, resp_mock.status)
     tw = assem_mock.return_value.trigger_workflow
     assert not tw.called
Esempio n. 10
0
 def test_trigger_post_on_wrong_github_webhook(self, assem_mock, resp_mock,
                                               request_mock):
     status_url = 'https://api.github.com/repos/u/r/statuses/{sha}'
     body_dict = {
         'sender': {
             'url': 'https://api.github.com'
         },
         'pull_request': {
             'head': {
                 'sha': 'asdf'
             }
         },
         'repository': {
             'HACKED_statuses_url': status_url
         }
     }
     request_mock.body = json.dumps(body_dict)
     obj = trigger.TriggerController()
     obj.post('test_id')
     self.assertEqual(400, resp_mock.status)
     tw = assem_mock.return_value.trigger_workflow
     assert not tw.called
Esempio n. 11
0
class Controller(object):
    """Version 1 API controller root."""

    plans = plan.PlansController()
    apps = app.AppsController()
    assemblies = assembly.AssembliesController()
    services = service.ServicesController()
    components = component.ComponentsController()
    extensions = extension.ExtensionsController()
    operations = operation.OperationsController()
    sensors = sensor.SensorsController()
    language_packs = language_pack.LanguagePacksController()
    pipelines = pipeline.PipelinesController()
    triggers = trigger.TriggerController()
    infrastructure = infrastructure.InfrastructureController()

    @exception.wrap_wsme_pecan_controller_exception
    @wsme_pecan.wsexpose(Platform)
    def index(self):
        base_url = pecan.request.application_url.rstrip('/')
        host_url = '%s/%s' % (base_url, 'v1')
        return Platform(uri=host_url,
                        name='solum',
                        type='platform',
                        description='solum native implementation',
                        implementation_version=version.version_string(),
                        plans_uri='%s/plans' % host_url,
                        apps_uri='%s/apps' % host_url,
                        assemblies_uri='%s/assemblies' % host_url,
                        services_uri='%s/services' % host_url,
                        components_uri='%s/components' % host_url,
                        extensions_uri='%s/extensions' % host_url,
                        operations_uri='%s/operations' % host_url,
                        sensors_uri='%s/sensors' % host_url,
                        language_packs_uri='%s/language_packs' % host_url,
                        pipelines_uri='%s/pipelines' % host_url,
                        triggers_uri='%s/triggers' % host_url,
                        infrastructure_uri='%s/infrastructure' % host_url)
Esempio n. 12
0
 def test_trigger_get_workflow_with_invalid_stage(self, assem_mock,
                                                  resp_mock, request_mock):
     obj = trigger.TriggerController()
     query = {'workflow': 'unittest+unitunitunittest'}
     workflow = obj._get_workflow(query)
     self.assertEqual(['unittest'], list(workflow))
Esempio n. 13
0
 def test_trigger_get_workflow_with_all(self, assem_mock, resp_mock,
                                        request_mock):
     obj = trigger.TriggerController()
     query = {'workflow': 'unittest+build+deploy'}
     workflow = obj._get_workflow(query)
     self.assertEqual(['unittest', 'build', 'deploy'], list(workflow))
Esempio n. 14
0
 def test_trigger_get_workflow_with_deploy(self, assem_mock, resp_mock,
                                           request_mock):
     obj = trigger.TriggerController()
     query = {'workflow': 'deploy'}
     workflow = obj._get_workflow(query)
     self.assertEqual(['deploy'], list(workflow))
Esempio n. 15
0
 def test_trigger_get_workflow_with_empty_body(self, assem_mock, resp_mock,
                                               request_mock):
     obj = trigger.TriggerController()
     workflow = obj._get_workflow({})
     self.assertIsNone(workflow)