'Testing adding a storageclass'

@mock.patch('oc_storageclass.locate_oc_binary')
@mock.patch('oc_storageclass.Utils.create_tmpfile_copy')
@mock.patch('oc_storageclass.OCStorageClass._run')
def test_adding_a_storageclass(self, mock_cmd, mock_tmpfile_copy, mock_oc_binary):

    valid_result_json = '{\n                                                "kind":    "StorageClass",\n                                                "apiVersion":    "v1",\n                                                "metadata":    {\n                                                                "name":    "testsc",\n                                                                "selfLink":    "/apis/storage.k8s.io/v1/storageclasses/gp2",\n                                                                "uid":    "4d8320c9-e66f-11e6-8edc-0eece8f2ce22",\n                                                                "resourceVersion":    "2828",\n                                                                "creationTimestamp":    "2017-01-29T22:07:19Z",\n                                                                "annotations":    {"storageclass.beta.kubernetes.io/is-default-class":    "true"}\n                                                },\n                                                "provisioner":    "kubernetes.io/aws-ebs",\n                                                "parameters":    {"type":    "gp2"}\n                                }'
    mock_cmd.side_effect = [(1, '', 'Error    from    server:    storageclass    "testsc"    not    found'), (0, 'storageclass    "testsc"    created', ''), (0, valid_result_json, '')]
    mock_oc_binary.side_effect = ['oc']
    mock_tmpfile_copy.side_effect = ['/tmp/mocked_kubeconfig']
    results = OCStorageClass.run_ansible(OCStorageClassTest.params, False)
    self.assertTrue(results['changed'])
    self.assertEqual(results['results']['returncode'], 0)
    self.assertEqual(results['state'], 'present')
    mock_cmd.assert_has_calls([mock.call(['oc', 'get', 'storageclass', 'testsc', '-o', 'json'], None), mock.call(['oc', 'create', '-f', mock.ANY], None), mock.call(['oc', 'get', 'storageclass', 'testsc', '-o', 'json'], None)])
