'Testing adding a project'

@mock.patch('oc_clusterrole.locate_oc_binary')
@mock.patch('oc_clusterrole.Utils.create_tmpfile_copy')
@mock.patch('oc_clusterrole.Utils._write')
@mock.patch('oc_clusterrole.OCClusterRole._run')
def test_adding_a_clusterrole(self, mock_cmd, mock_write, mock_tmpfile_copy, mock_loc_binary):

    params = copy.deepcopy(OCClusterRoleTest.params)
    clusterrole = '{\n                                                "apiVersion":    "v1",\n                                                "kind":    "ClusterRole",\n                                                "metadata":    {\n                                                                "creationTimestamp":    "2017-03-27T14:19:09Z",\n                                                                "name":    "operations",\n                                                                "resourceVersion":    "23",\n                                                                "selfLink":    "/oapi/v1/clusterrolesoperations",\n                                                                "uid":    "57d358fe-12f8-11e7-874a-0ec502977670"\n                                                },\n                                                "rules":    [\n                                                                {\n                                                                                "apiGroups":    [\n                                                                                                ""\n                                                                                ],\n                                                                                "attributeRestrictions":    null,\n                                                                                "resources":    [\n                                                                                                "persistentvolumes"\n                                                                                ],\n                                                                                "verbs":    [\n                                                                                                "create",\n                                                                                                "delete",\n                                                                                                "deletecollection",\n                                                                                                "get",\n                                                                                                "list",\n                                                                                                "patch",\n                                                                                                "update",\n                                                                                                "watch"\n                                                                                ]\n                                                                }\n                                                ]\n                                }'
    mock_cmd.side_effect = [(1, '', 'Error    from    server:    clusterrole    "operations"    not    found'), (1, '', 'Error    from    server:    namespaces    "operations"    not    found'), (0, '', ''), (0, clusterrole, '')]
    mock_tmpfile_copy.side_effect = ['/tmp/mocked_kubeconfig']
    mock_loc_binary.side_effect = ['oc']
    results = OCClusterRole.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', 'clusterrole', 'operations', '-o', 'json'], None), mock.call(['oc', 'get', 'clusterrole', 'operations', '-o', 'json'], None), mock.call(['oc', 'create', '-f', mock.ANY], None), mock.call(['oc', 'get', 'clusterrole', 'operations', '-o', 'json'], None)])
