'Testing when both all objects are valid'

@mock.patch('oc_objectvalidator.locate_oc_binary')
@mock.patch('oc_objectvalidator.Utils.create_tmpfile_copy')
@mock.patch('oc_objectvalidator.OCObjectValidator._run')
def test_valid_both(self, mock_cmd, mock_tmpfile_copy, mock_oc_binary):

    params = {'kubeconfig': '/etc/origin/master/admin.kubeconfig'}
    valid_hostsubnet = '{\n                "apiVersion":    "v1",\n                "items":    [\n                                {\n                                                "apiVersion":    "v1",\n                                                "host":    "bar0",\n                                                "hostIP":    "1.1.1.1",\n                                                "kind":    "HostSubnet",\n                                                "metadata":    {\n                                                                "creationTimestamp":    "2017-02-16T18:47:09Z",\n                                                                "name":    "bar0",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "986",\n                                                                "selfLink":    "/oapi/v1/hostsubnetsbar0",\n                                                                "uid":    "528dbb41-f478-11e6-aae0-507b9dac97ff"\n                                                },\n                                                "subnet":    "1.1.0.0/24"\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "host":    "bar1",\n                                                "hostIP":    "1.1.1.1",\n                                                "kind":    "HostSubnet",\n                                                "metadata":    {\n                                                                "creationTimestamp":    "2017-02-16T18:47:18Z",\n                                                                "name":    "bar1",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "988",\n                                                                "selfLink":    "/oapi/v1/hostsubnetsbar1",\n                                                                "uid":    "57710d84-f478-11e6-aae0-507b9dac97ff"\n                                                },\n                                                "subnet":    "1.1.0.0/24"\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "host":    "bar2",\n                                                "hostIP":    "1.1.1.1",\n                                                "kind":    "HostSubnet",\n                                                "metadata":    {\n                                                                "creationTimestamp":    "2017-02-16T18:47:26Z",\n                                                                "name":    "bar2",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "991",\n                                                                "selfLink":    "/oapi/v1/hostsubnetsbar2",\n                                                                "uid":    "5c59a28c-f478-11e6-aae0-507b9dac97ff"\n                                                },\n                                                "subnet":    "1.1.0.0/24"\n                                }\n                ],\n                "kind":    "List",\n                "metadata":    {},\n                "resourceVersion":    "",\n                "selfLink":    ""\n                }'
    valid_netnamespace = '{\n                "apiVersion":    "v1",\n                "items":    [\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "NetNamespace",\n                                                "metadata":    {\n                                                                "creationTimestamp":    "2017-02-16T18:45:16Z",\n                                                                "name":    "foo0",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "959",\n                                                                "selfLink":    "/oapi/v1/netnamespacesfoo0",\n                                                                "uid":    "0f1c85b2-f478-11e6-aae0-507b9dac97ff"\n                                                },\n                                                "netid":    100,\n                                                "netname":    "foo0"\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "NetNamespace",\n                                                "metadata":    {\n                                                                "creationTimestamp":    "2017-02-16T18:45:26Z",\n                                                                "name":    "foo1",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "962",\n                                                                "selfLink":    "/oapi/v1/netnamespacesfoo1",\n                                                                "uid":    "14effa0d-f478-11e6-aae0-507b9dac97ff"\n                                                },\n                                                "netid":    100,\n                                                "netname":    "foo1"\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "NetNamespace",\n                                                "metadata":    {\n                                                                "creationTimestamp":    "2017-02-16T18:45:36Z",\n                                                                "name":    "foo2",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "965",\n                                                                "selfLink":    "/oapi/v1/netnamespacesfoo2",\n                                                                "uid":    "1aabdf84-f478-11e6-aae0-507b9dac97ff"\n                                                },\n                                                "netid":    100,\n                                                "netname":    "foo2"\n                                }\n                ],\n                "kind":    "List",\n                "metadata":    {},\n                "resourceVersion":    "",\n                "selfLink":    ""\n                }'
    valid_namespace = '{\n                "apiVersion":    "v1",\n                "items":    [\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "Namespace",\n                                                "metadata":    {\n                                                                "annotations":    {\n                                                                                "openshift.io/sa.scc.mcs":    "s0:c1,c0",\n                                                                                "openshift.io/sa.scc.supplemental-groups":    "1000000000/10000",\n                                                                                "openshift.io/sa.scc.uid-range":    "1000000000/10000"\n                                                                },\n                                                                "creationTimestamp":    "2017-03-02T00:49:49Z",\n                                                                "name":    "default",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "165",\n                                                                "selfLink":    "/api/v1/namespacesdefault",\n                                                                "uid":    "23c0c6aa-fee2-11e6-b45a-507b9dac97ff"\n                                                },\n                                                "spec":    {\n                                                                "finalizers":    [\n                                                                                "kubernetes",\n                                                                                "openshift.io/origin"\n                                                                ]\n                                                },\n                                                "status":    {\n                                                                "phase":    "Active"\n                                                }\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "Namespace",\n                                                "metadata":    {\n                                                                "annotations":    {\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                                                                "creationTimestamp":    "2017-03-02T00:49:49Z",\n                                                                "name":    "kube-system",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "533",\n                                                                "selfLink":    "/api/v1/namespaceskube-system",\n                                                                "uid":    "23c21758-fee2-11e6-b45a-507b9dac97ff"\n                                                },\n                                                "spec":    {\n                                                                "finalizers":    [\n                                                                                "kubernetes",\n                                                                                "openshift.io/origin"\n                                                                ]\n                                                },\n                                                "status":    {\n                                                                "phase":    "Active"\n                                                }\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "Namespace",\n                                                "metadata":    {\n                                                                "annotations":    {\n                                                                                "openshift.io/description":    "",\n                                                                                "openshift.io/display-name":    "",\n                                                                                "openshift.io/requester":    "developer",\n                                                                                "openshift.io/sa.scc.mcs":    "s0:c9,c4",\n                                                                                "openshift.io/sa.scc.supplemental-groups":    "1000080000/10000",\n                                                                                "openshift.io/sa.scc.uid-range":    "1000080000/10000"\n                                                                },\n                                                                "creationTimestamp":    "2017-03-02T02:17:16Z",\n                                                                "name":    "myproject",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "2898",\n                                                                "selfLink":    "/api/v1/namespacesmyproject",\n                                                                "uid":    "5ae3764d-feee-11e6-b45a-507b9dac97ff"\n                                                },\n                                                "spec":    {\n                                                                "finalizers":    [\n                                                                                "openshift.io/origin",\n                                                                                "kubernetes"\n                                                                ]\n                                                },\n                                                "status":    {\n                                                                "phase":    "Active"\n                                                }\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "Namespace",\n                                                "metadata":    {\n                                                                "annotations":    {\n                                                                                "openshift.io/sa.scc.mcs":    "s0:c6,c0",\n                                                                                "openshift.io/sa.scc.supplemental-groups":    "1000030000/10000",\n                                                                                "openshift.io/sa.scc.uid-range":    "1000030000/10000"\n                                                                },\n                                                                "creationTimestamp":    "2017-03-02T00:49:51Z",\n                                                                "name":    "openshift",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "171",\n                                                                "selfLink":    "/api/v1/namespacesopenshift",\n                                                                "uid":    "24f7b34d-fee2-11e6-b45a-507b9dac97ff"\n                                                },\n                                                "spec":    {\n                                                                "finalizers":    [\n                                                                                "kubernetes",\n                                                                                "openshift.io/origin"\n                                                                ]\n                                                },\n                                                "status":    {\n                                                                "phase":    "Active"\n                                                }\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "Namespace",\n                                                "metadata":    {\n                                                                "annotations":    {\n                                                                                "openshift.io/sa.scc.mcs":    "s0:c5,c0",\n                                                                                "openshift.io/sa.scc.supplemental-groups":    "1000020000/10000",\n                                                                                "openshift.io/sa.scc.uid-range":    "1000020000/10000"\n                                                                },\n                                                                "creationTimestamp":    "2017-03-02T00:49:51Z",\n                                                                "name":    "openshift-infra",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "169",\n                                                                "selfLink":    "/api/v1/namespacesopenshift-infra",\n                                                                "uid":    "24a2ed75-fee2-11e6-b45a-507b9dac97ff"\n                                                },\n                                                "spec":    {\n                                                                "finalizers":    [\n                                                                                "kubernetes",\n                                                                                "openshift.io/origin"\n                                                                ]\n                                                },\n                                                "status":    {\n                                                                "phase":    "Active"\n                                                }\n                                },\n                                {\n                                                "apiVersion":    "v1",\n                                                "kind":    "Namespace",\n                                                "metadata":    {\n                                                                "annotations":    {\n                                                                                "openshift.io/description":    "",\n                                                                                "openshift.io/display-name":    "",\n                                                                                "openshift.io/requester":    "developer1",\n                                                                                "openshift.io/sa.scc.mcs":    "s0:c10,c0",\n                                                                                "openshift.io/sa.scc.supplemental-groups":    "1000090000/10000",\n                                                                                "openshift.io/sa.scc.uid-range":    "1000090000/10000"\n                                                                },\n                                                                "creationTimestamp":    "2017-03-02T02:17:56Z",\n                                                                "name":    "yourproject",\n                                                                "namespace":    "",\n                                                                "resourceVersion":    "2955",\n                                                                "selfLink":    "/api/v1/namespacesyourproject",\n                                                                "uid":    "72df7fb9-feee-11e6-b45a-507b9dac97ff"\n                                                },\n                                                "spec":    {\n                                                                "finalizers":    [\n                                                                                "openshift.io/origin",\n                                                                                "kubernetes"\n                                                                ]\n                                                },\n                                                "status":    {\n                                                                "phase":    "Active"\n                                                }\n                                }\n                ],\n                "kind":    "List",\n                "metadata":    {},\n                "resourceVersion":    "",\n                "selfLink":    ""\n}'
    mock_cmd.side_effect = [(0, valid_hostsubnet, ''), (0, valid_netnamespace, ''), (0, valid_namespace, '')]
    mock_tmpfile_copy.side_effect = ['/tmp/mocked_kubeconfig']
    mock_oc_binary.side_effect = ['oc']
    results = OCObjectValidator.run_ansible(params)
    self.assertNotIn('failed', results)
    self.assertEqual(results['msg'], 'All    objects    are    valid.')
    mock_cmd.assert_has_calls([mock.call(['oc', 'get', 'hostsubnet', '-o', 'json', '-n', 'default'], None), mock.call(['oc', 'get', 'netnamespace', '-o', 'json', '-n', 'default'], None), mock.call(['oc', 'get', 'namespace', '-o', 'json', '-n', 'default'], None)])
