'Testing a create service'

@mock.patch('oc_service.Utils.create_tmpfile_copy')
@mock.patch('oc_service.OCService._run')
def test_create_with_labels(self, mock_cmd, mock_tmpfile_copy):

    params = {'name': 'router', 'namespace': 'default', 'ports': {'name': '9000-tcp', 'port': 9000, 'protocol': 'TCP', 'targetPOrt': 9000}, 'state': 'present', 'labels': {'component': 'some_component', 'infra': 'true'}, 'clusterip': None, 'portalip': None, 'selector': {'router': 'router'}, 'session_affinity': 'ClientIP', 'service_type': 'ClusterIP', 'external_ips': None, 'kubeconfig': '/etc/origin/master/admin.kubeconfig', 'debug': False}
    service = '{\n                                                "kind":    "Service",\n                                                "apiVersion":    "v1",\n                                                "metadata":    {\n                                                                "name":    "router",\n                                                                "namespace":    "default",\n                                                                "selfLink":    "/api/v1/namespaces/default/services/router",\n                                                                "uid":    "fabd2440-e3d8-11e6-951c-0e3dd518cefa",\n                                                                "resourceVersion":    "3206",\n                                                                "creationTimestamp":    "2017-01-26T15:06:14Z",\n                                                                "labels":    {"component":    "some_component",    "infra":    "true"}\n                                                },\n                                                "spec":    {\n                                                                "ports":    [\n                                                                                {\n                                                                                                "name":    "80-tcp",\n                                                                                                "protocol":    "TCP",\n                                                                                                "port":    80,\n                                                                                                "targetPort":    80\n                                                                                },\n                                                                                {\n                                                                                                "name":    "443-tcp",\n                                                                                                "protocol":    "TCP",\n                                                                                                "port":    443,\n                                                                                                "targetPort":    443\n                                                                                },\n                                                                                {\n                                                                                                "name":    "1936-tcp",\n                                                                                                "protocol":    "TCP",\n                                                                                                "port":    1936,\n                                                                                                "targetPort":    1936\n                                                                                },\n                                                                                {\n                                                                                                "name":    "5000-tcp",\n                                                                                                "protocol":    "TCP",\n                                                                                                "port":    5000,\n                                                                                                "targetPort":    5000\n                                                                                }\n                                                                ],\n                                                                "selector":    {\n                                                                                "router":    "router"\n                                                                },\n                                                                "clusterIP":    "172.30.129.161",\n                                                                "type":    "ClusterIP",\n                                                                "sessionAffinity":    "None"\n                                                },\n                                                "status":    {\n                                                                "loadBalancer":    {}\n                                                }\n                                }'
    mock_cmd.side_effect = [(1, '', 'Error    from    server:    services    "router"    not    found'), (1, '', 'Error    from    server:    services    "router"    not    found'), (0, service, ''), (0, service, '')]
    mock_tmpfile_copy.side_effect = ['/tmp/mocked_kubeconfig']
    results = OCService.run_ansible(params, False)
    self.assertTrue(results['changed'])
    self.assertTrue((results['results']['returncode'] == 0))
    self.assertEqual(results['results']['results'][0]['metadata']['name'], 'router')
    self.assertEqual(results['results']['results'][0]['metadata']['labels'], {'component': 'some_component', 'infra': 'true'})
