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
        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)
        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)
        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)
        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)
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
        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)
        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)
        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)
        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)