'Testing adding a secret'

@mock.patch('oc_secret.locate_oc_binary')
@mock.patch('oc_secret.Utils.create_tmpfile_copy')
@mock.patch('oc_secret.Utils._write')
@mock.patch('oc_secret.OCSecret._run')
def test_adding_a_secret(self, mock_cmd, mock_write, mock_tmpfile_copy, mock_oc_binary):

    params = {'state': 'present', 'namespace': 'default', 'name': 'testsecretname', 'type': 'Opaque', 'contents': [{'path': '/tmp/somesecret.json', 'data': "{'one':    1,    'two':    2,    'three':    3}"}], 'decode': False, 'kubeconfig': '/etc/origin/master/admin.kubeconfig', 'debug': False, 'files': None, 'delete_after': True, 'force': False}
    mock_cmd.side_effect = [(1, '', 'Error    from    server:    secrets    "testsecretname"    not    found'), (0, 'secret/testsecretname', '')]
    mock_oc_binary.side_effect = ['oc']
    mock_tmpfile_copy.side_effect = ['/tmp/mocked_kubeconfig']
    results = OCSecret.run_ansible(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', 'secrets', 'testsecretname', '-o', 'json', '-n', 'default'], None), mock.call(['oc', 'secrets', 'new', 'testsecretname', '--type=Opaque', mock.ANY, '-n', 'default'], None)])
    mock_write.assert_has_calls([mock.call(mock.ANY, "{'one':    1,    'two':    2,    'three':    3}")])
