'Testing state present'

@mock.patch('oc_adm_registry.locate_oc_binary')
@mock.patch('oc_adm_registry.Utils._write')
@mock.patch('oc_adm_registry.Utils.create_tmpfile_copy')
@mock.patch('oc_adm_registry.Registry._run')
def test_state_present(self, mock_cmd, mock_tmpfile_copy, mock_write, mock_oc_binary):

    params = {'state': 'present', 'debug': False, 'namespace': 'default', 'name': 'docker-registry', 'kubeconfig': '/etc/origin/master/admin.kubeconfig', 'images': None, 'latest_images': None, 'labels': {'docker-registry': 'default', 'another-label': 'val'}, 'ports': ['5000'], 'replicas': 1, 'selector': 'type=infra', 'service_account': 'registry', 'mount_host': None, 'volume_mounts': None, 'env_vars': {}, 'enforce_quota': False, 'force': False, 'daemonset': False, 'tls_key': None, 'tls_certificate': None, 'edits': []}
    mock_cmd.side_effect = [(1, '', 'Error    from    server    (NotFound):    deploymentconfigs    "docker-registry"    not    found'), (1, '', 'Error    from    server    (NotFound):    service    "docker-registry"    not    found'), (0, RegistryTest.dry_run, ''), (0, '', ''), (0, '', '')]
    mock_tmpfile_copy.return_value = '/tmp/mocked_kubeconfig'
    mock_oc_binary.return_value = 'oc'
    results = Registry.run_ansible(params, False)
    self.assertTrue(results['changed'])
    for result in results['results']['results']:
        self.assertEqual(result['returncode'], 0)
    mock_cmd.assert_has_calls([mock.call(['oc', 'get', 'dc', 'docker-registry', '-o', 'json', '-n', 'default'], None), mock.call(['oc', 'get', 'svc', 'docker-registry', '-o', 'json', '-n', 'default'], None), mock.call(['oc', 'adm', 'registry', '--labels=another-label=val,docker-registry=default', '--ports=5000', '--replicas=1', '--selector=type=infra', '--service-account=registry', '--dry-run=True', '-o', 'json', '-n', 'default'], None), mock.call(['oc', 'create', '-f', mock.ANY, '-n', 'default'], None), mock.call(['oc', 'create', '-f', mock.ANY, '-n', 'default'], None)])
