'Testing adding a project'

@mock.patch('oc_project.locate_oc_binary')
@mock.patch('oc_project.Utils.create_tmpfile_copy')
@mock.patch('oc_project.Utils._write')
@mock.patch('oc_project.OCProject._run')
def test_adding_a_project(self, mock_cmd, mock_write, mock_tmpfile_copy, mock_loc_oc_bin):

    params = copy.deepcopy(OCProjectTest.params)
    project_results = '{\n                                                "kind":    "Project",\n                                                "apiVersion":    "v1",\n                                                "metadata":    {\n                                                                "name":    "operations",\n                                                                "selfLink":    "/oapi/v1/projects/operations",\n                                                                "uid":    "5e52afb8-ee33-11e6-89f4-0edc441d9666",\n                                                                "resourceVersion":    "1584",\n                                                                "labels":    {},\n                                                                "annotations":    {\n                                                                                "openshift.io/node-selector":    "ops_only=True",\n                                                                                "openshift.io/sa.initialized-roles":    "true",\n                                                                                "openshift.io/sa.scc.mcs":    "s0:c3,c2",\n                                                                                "openshift.io/sa.scc.supplemental-groups":    "1000010000/10000",\n                                                                                "openshift.io/sa.scc.uid-range":    "1000010000/10000"\n                                                                }\n                                                },\n                                                "spec":    {\n                                                                "finalizers":    [\n                                                                                "kubernetes",\n                                                                                "openshift.io/origin"\n                                                                ]\n                                                },\n                                                "status":    {\n                                                                "phase":    "Active"\n                                                }\n                                }'
    mock_cmd.side_effect = [(1, '', 'Error    from    server:    namespaces    "operations"    not    found'), (1, '', 'Error    from    server:    namespaces    "operations"    not    found'), (0, '', ''), (0, project_results, '')]
    mock_tmpfile_copy.side_effect = ['/tmp/mocked_kubeconfig']
    mock_loc_oc_bin.side_effect = ['oc']
    results = OCProject.run_ansible(params, False)
    self.assertTrue(results['changed'])
    self.assertEqual(results['results']['returncode'], 0)
    self.assertEqual(results['results']['results']['metadata']['name'], 'operations')
    self.assertEqual(results['state'], 'present')
    mock_cmd.assert_has_calls([mock.call(['oc', 'get', 'namespace', 'operations', '-o', 'json'], None), mock.call(['oc', 'get', 'namespace', 'operations', '-o', 'json'], None), mock.call(['oc', 'adm', 'new-project', 'operations', mock.ANY, mock.ANY, mock.ANY, mock.ANY], None), mock.call(['oc', 'get', 'namespace', 'operations', '-o', 'json'], None)])
