示例#1
0
 def setUp(self):
     c = dummy_conf()
     self.config = {
         'services': c.services,
         'gerrit': c.gerrit,
         'app': c.app,
         'admin': c.admin,
         'sqlalchemy': c.sqlalchemy,
         'auth': c.auth,
         'htpasswd': c.htpasswd,
         'managesf': c.managesf,
         'storyboard': c.storyboard,
         'policy': c.policy,
         'jenkins': c.jenkins,
         'nodepool': c.nodepool,
     }
     pol_file = tempfile.mkstemp()[1] + '.yaml'
     with open(pol_file, 'w') as p:
         yaml.dump(
             {
                 "managesf.node:get": "rule:any",
                 "managesf.node:create": "rule:any",
                 "is_morty": "username:morty",
                 "morty_api": "rule:is_morty"
             },
             p,
             default_flow_style=False)
     self.config['policy']['policy_file'] = pol_file
     self.app = TestApp(load_app(self.config))
示例#2
0
 def test_is_activated(self):
     conf = dummy_conf()
     s = StoryboardOps(conf, None)
     project = {'issue-tracker': 'SFStoryboard'}
     self.assertTrue(s.is_activated(**project))
     project = {'issue-tracker': ''}
     self.assertFalse(s.is_activated(**project))
     conf.services.remove('SFStoryboard')
     project = {'issue-tracker': 'SFStoryboard'}
     self.assertFalse(s.is_activated(**project))
示例#3
0
 def setUp(self):
     c = dummy_conf()
     self.config = {'services': c.services,
                    'gerrit': c.gerrit,
                    'app': c.app,
                    'admin': c.admin,
                    'sqlalchemy': c.sqlalchemy,
                    'auth': c.auth,
                    'htpasswd': c.htpasswd,
                    'managesf': c.managesf,
                    'storyboard': c.storyboard,
                    'mysql': c.mysql,
                    'policy': c.policy, }
     self.app = TestApp(load_app(self.config))
示例#4
0
 def setUp(self):
     c = dummy_conf()
     self.config = {
         'services': c.services,
         'gerrit': c.gerrit,
         'app': c.app,
         'admin': c.admin,
         'sqlalchemy': c.sqlalchemy,
         'auth': c.auth,
         'htpasswd': c.htpasswd,
         'managesf': c.managesf,
         'storyboard': c.storyboard,
         'mysql': c.mysql,
         'policy': c.policy,
     }
     self.app = TestApp(load_app(self.config))
示例#5
0
 def test_extra_validation(self):
     conf = dummy_conf()
     s = StoryboardOps(conf, None)
     project = {
         'name': 'project1',
         'source-repositories': ['repo1', 'repo2']
     }
     logs = s.extra_validations(**project)
     self.assertTrue(len(logs) == 0)
     project = {
         'name': 'project2',
         'source-repositories': ['repo', '-hjook']
     }
     logs = s.extra_validations(**project)
     self.assertTrue('Minimal len is 5' in logs[0])
     self.assertTrue('should match the RE' in logs[1])
示例#6
0
    def test_delete_project_group(self):
        class FakeItem(object):
            def __init__(self, name, id):
                self.name = name
                self.id = id
        conf = dummy_conf()
        patches = [
            patch('storyboardclient.v1.project_groups.'
                  'ProjectGroupsManager.get_all'),
            patch('storyboardclient.v1.project_groups.'
                  'ProjectGroupsManager.get'),
            patch('storyboardclient.v1.project_groups.'
                  'ProjectGroupsManager.update'),
            patch('storyboardclient.v1.project_groups.'
                  'ProjectGroupsManager.delete')]
        with nested(*patches) as (get_all, get, update, delete):
            s = StoryboardOps(conf, None)
            get_all.return_value = [FakeItem('pg1', 3)]
            mdelete = Mock()
            fake_subprojects = [
                FakeItem('project1', 1),
                FakeItem('project2', 2)]

            class fprojects():
                def get_all(self):
                    return fake_subprojects

                def delete(self, id):
                    mdelete(id)

            class NestedProjects():
                def __init__(self):
                    self.projects = fprojects()

            get.return_value = NestedProjects()
            update.return_value = NestedProjects()

            s.delete_project_groups(**{'name': 'pg1'})
            self.assertEqual(len(mdelete.call_args_list), 2)
            self.assertIn(call(1), mdelete.call_args_list)
            self.assertIn(call(2), mdelete.call_args_list)
            self.assertListEqual(delete.call_args_list, [call(id=3)])
示例#7
0
 def test_update_project(self):
     class FakeItem(object):
         def __init__(self, name, id):
             self.name = name
             self.id = id
     conf = dummy_conf()
     s = StoryboardOps(conf, None)
     patches = [
         patch('storyboardclient.v1.projects.ProjectsManager.get_all'),
         patch('storyboardclient.v1.projects.ProjectsManager.update'),
         patch('storyboardclient.v1.projects.ProjectsManager.create')]
     with nested(*patches) as (get_all, update, create):
         get_all.return_value = [FakeItem('project1', 1)]
         s.update_project('project1', 'A desc')
         self.assertTrue(get_all.called)
         self.assertTrue(update.called)
         self.assertFalse(create.called)
     with nested(*patches) as (get_all, update, create):
         get_all.return_value = [FakeItem('project1', 1)]
         s.update_project('project2', 'A desc')
         self.assertTrue(get_all.called)
         self.assertFalse(update.called)
         self.assertTrue(create.called)
示例#8
0
 def setUp(self):
     c = dummy_conf()
     self.config = {'services': c.services,
                    'gerrit': c.gerrit,
                    'app': c.app,
                    'admin': c.admin,
                    'sqlalchemy': c.sqlalchemy,
                    'auth': c.auth,
                    'htpasswd': c.htpasswd,
                    'managesf': c.managesf,
                    'storyboard': c.storyboard,
                    'policy': c.policy,
                    'jenkins': c.jenkins,
                    'nodepool': c.nodepool, }
     pol_file = tempfile.mkstemp()[1] + '.yaml'
     with open(pol_file, 'w') as p:
         yaml.dump(
             {"managesf.node:get": "rule:any",
              "managesf.node:create": "rule:any",
              "is_morty": "username:morty",
              "morty_api": "rule:is_morty"},
             p, default_flow_style=False)
     self.config['policy']['policy_file'] = pol_file
     self.app = TestApp(load_app(self.config))
示例#9
0
 def setupClass(cls):
     cls.conf = dummy_conf()
     localuser.conf = cls.conf
     localuser.model.conf = cls.conf
示例#10
0
 def setupClass(cls):
     cls.conf = dummy_conf()
     cls.jenkins = jenkins.SoftwareFactoryJenkins(cls.conf)
示例#11
0
 def setupClass(cls):
     cls.conf = dummy_conf()
     cls.jenkins = jenkins.SoftwareFactoryJenkins(cls.conf)
示例#12
0
 def setupClass(cls):
     cls.conf = dummy_conf()
     utils.conf = cls.conf
     cls.ru = utils.RemoteUser('john', 'dummy_host',
                               sshkey_path='dummy_key')
示例#13
0
 def setupClass(cls):
     cls.conf = dummy_conf()
     cls.gerrit = gerrit.SoftwareFactoryGerrit(cls.conf)
     cls.auth_patch = patch('managesf.services.gerrit.get_cookie')
     cls.auth_patch.start()
示例#14
0
 def setupClass(cls):
     cls.conf = dummy_conf()
     localuser.conf = cls.conf
     localuser.model.conf = cls.conf
示例#15
0
 def setupClass(cls):
     cls.conf = dummy_conf()
     utils.conf = cls.conf
示例#16
0
 def setupClass(cls):
     cls.conf = dummy_conf()
     SFuser.model.conf = cls.conf
示例#17
0
    def test_update_project_group(self):
        class FakeItem(object):
            def __init__(self, name, id):
                self.name = name
                self.id = id
        conf = dummy_conf()
        patches = [
            patch('storyboardclient.v1.project_groups.'
                  'ProjectGroupsManager.get_all'),
            patch('storyboardclient.v1.project_groups.'
                  'ProjectGroupsManager.create'),
            patch.object(StoryboardOps, 'update_project'),
            patch('storyboardclient.v1.project_groups.'
                  'ProjectGroupsManager.get'),
            patch('storyboardclient.v1.project_groups.'
                  'ProjectGroupsManager.update'),
            patch('storyboardclient.v1.projects.'
                  'ProjectsManager.get_all')]
        with nested(*patches) as (get_all, create, update_project,
                                  get, update, p_get_all):
            new = {
                'resources': {
                    'repos': {
                        'project1': {'description': 'A desc'},
                        'project2': {'description': 'A desc'}
                    }
                }
            }
            s = StoryboardOps(conf, new)
            get_all.return_value = [FakeItem('pg1', 1)]

            fake_subprojects = [
                FakeItem('project1', 1),
                FakeItem('project2', 2)]
            mput = Mock()
            mdelete = Mock()

            class fprojects():
                def get_all(self):
                    return fake_subprojects

                def put(self, id):
                    mput(id)

                def delete(self, id):
                    mdelete(id)

            class NestedProjects():
                def __init__(self):
                    self.projects = fprojects()

            get.return_value = NestedProjects()
            update.return_value = NestedProjects()
            p_get_all.return_value = fake_subprojects

            # Here projects are already included in the project
            # group so nothing will be added/removed in the project
            # group. Just projects will be updated.
            s.update_project_groups(
                **{'name': 'pg1',
                   'source-repositories': ['project1', 'project2']})
            self.assertFalse(mput.called)
            self.assertFalse(mdelete.called)
            self.assertTrue(len(update_project.mock_calls), 2)

            # Here project1 and project2 are already included but
            # the resources project decription only defines the
            # project2 to be included. So we make sure the delete
            # is called with id 1.
            mput.reset_mock()
            mdelete.reset_mock()
            update_project.reset_mock()
            s.update_project_groups(
                **{'name': 'pg1',
                   'source-repositories': ['project2']})
            self.assertFalse(mput.called)
            self.assertTrue(mdelete.called)
            self.assertListEqual(mdelete.call_args_list, [call(1)])
            self.assertTrue(len(update_project.mock_calls), 1)

            # Here only project1 is already included but
            # the resources project decription defines the
            # project1 and project2 to be included. So we make sure
            # the put is called with id 2.
            mput.reset_mock()
            mdelete.reset_mock()
            update_project.reset_mock()
            fake_subprojects = [
                FakeItem('project1', 1)]
            s.update_project_groups(
                **{'name': 'pg1',
                   'source-repositories': ['project1', 'project2']})
            self.assertTrue(mput.called)
            self.assertListEqual(mput.call_args_list, [call(2)])
            self.assertFalse(mdelete.called)
            self.assertTrue(len(update_project.mock_calls), 1)

            # Here the project group does not exist. So we verify
            # it is created and provisionned with two projects
            # included.
            get_all.return_value = []
            p_get_all.return_value = [
                FakeItem('project1', 1),
                FakeItem('project2', 2)]
            fake_subprojects = []
            get.return_value = NestedProjects()
            update.return_value = NestedProjects()
            mput.reset_mock()
            mdelete.reset_mock()
            update_project.reset_mock()
            s.update_project_groups(
                **{'name': 'pg1',
                   'source-repositories': ['project1', 'project2']})
            self.assertTrue(create.called)
            self.assertTrue(len(update_project.mock_calls), 2)
            self.assertTrue(len(mput.mock_calls), 2)
            self.assertFalse(mdelete.called)
示例#18
0
 def setupClass(cls):
     cls.conf = dummy_conf()
     cls.htp = htp.Htpasswd(cls.conf)
 def setupClass(cls):
     cls.conf = dummy_conf()
 def setupClass(cls):
     cls.conf = dummy_conf()
     cls.nodepool = nodepool.SoftwareFactoryNodepool(cls.conf)
     nodepool.image.model.conf = cls.conf
示例#21
0
 def setupClass(cls):
     cls.conf = dummy_conf()
     utils.conf = cls.conf
     cls.ru = utils.RemoteUser('john',
                               'dummy_host',
                               sshkey_path='dummy_key')
示例#22
0
 def setupClass(cls):
     cls.conf = dummy_conf()
     cls.service = BaseServiceForTest(cls.conf)
 def setupClass(cls):
     cls.conf = dummy_conf()
     cls.storyboard = storyboard.SoftwareFactoryStoryboard(cls.conf)
示例#24
0
 def setupClass(cls):
     cls.conf = dummy_conf()
     cls.nodepool = nodepool.SoftwareFactoryNodepool(cls.conf)
     nodepool.image.model.conf = cls.conf
示例#25
0
 def setupClass(cls):
     cls.conf = dummy_conf()
     cls.gerrit = gerrit.SoftwareFactoryGerrit(cls.conf)
     cls.auth_patch = patch('managesf.services.gerrit.get_cookie')
     cls.auth_patch.start()
示例#26
0
 def setupClass(cls):
     cls.conf = dummy_conf()
     cls.service = BaseServiceForTest(cls.conf)
示例#27
0
 def setupClass(cls):
     cls.auth_patch = patch('managesf.services.gerrit.get_cookie')
     cls.auth_patch.start()
     cls.conf = dummy_conf()
 def setupClass(cls):
     cls.conf = dummy_conf()
     cls.storyboard = storyboard.SoftwareFactoryStoryboard(cls.conf)