import unittest
import mock
from ..client import Client


class TestClient(unittest.TestCase):

    @mock.patch('auth0.v2.client.RestClient')
    def test_all(self, mock_rc):
        mock_instance = mock_rc.return_value

        c = Client(domain='domain', jwt_token='jwttoken')
        c.all()

        args, kwargs = mock_instance.get.call_args

        self.assertEqual('https://domain/api/v2/clients', args[0])
        self.assertEqual(kwargs['params'], {'fields': None,
                                            'include_fields': 'true'})

        c.all(fields=['a', 'b'], include_fields=False)

        args, kwargs = mock_instance.get.call_args

        self.assertEqual('https://domain/api/v2/clients', args[0])
        self.assertEqual(kwargs['params'], {'fields': 'a,b',
                                            'include_fields': 'false'})

    @mock.patch('auth0.v2.client.RestClient')
    def test_create(self, mock_rc):
        mock_instance = mock_rc.return_value

        c = Client(domain='domain', jwt_token='jwttoken')
        c.create({'a': 'b', 'c': 'd'})

        mock_instance.post.assert_called_with(
            'https://domain/api/v2/clients',
            data={'a': 'b', 'c': 'd'}
        )

    @mock.patch('auth0.v2.client.RestClient')
    def test_get(self, mock_rc):
        mock_instance = mock_rc.return_value

        c = Client(domain='domain', jwt_token='jwttoken')
        c.get('this-id')

        args, kwargs = mock_instance.get.call_args

        self.assertEqual('https://domain/api/v2/clients/this-id', args[0])
        self.assertEqual(kwargs['params'], {'fields': None,
                                            'include_fields': 'true'})

        c.get('this-id', fields=['a', 'b'], include_fields=False)

        args, kwargs = mock_instance.get.call_args

        self.assertEqual('https://domain/api/v2/clients/this-id', args[0])
        self.assertEqual(kwargs['params'], {'fields': 'a,b',
                                            'include_fields': 'false'})

    @mock.patch('auth0.v2.client.RestClient')
    def test_delete(self, mock_rc):
        mock_instance = mock_rc.return_value

        c = Client(domain='domain', jwt_token='jwttoken')
        c.delete('this-id')

        mock_instance.delete.assert_called_with(
            'https://domain/api/v2/clients/this-id'
        )

    @mock.patch('auth0.v2.client.RestClient')
    def test_update(self, mock_rc):
        mock_instance = mock_rc.return_value

        c = Client(domain='domain', jwt_token='jwttoken')
        c.update('this-id', {'a': 'b', 'c': 'd'})

        args, kwargs = mock_instance.patch.call_args

        self.assertEqual('https://domain/api/v2/clients/this-id', args[0])
        self.assertEqual(kwargs['data'], {'a': 'b', 'c': 'd'})

@@ -34,16 +34,17 @@
 ..client
+s
  import 
@@ -49,16 +49,17 @@
 t Client
+s
 %0A%0A%0Aclass
@@ -69,16 +69,17 @@
 stClient
+s
 (unittes
@@ -116,32 +116,33 @@
 'auth0.v2.client
+s
 .RestClient')%0A  
@@ -228,32 +228,33 @@
       c = Client
+s
 (domain='domain'
@@ -878,32 +878,33 @@
 'auth0.v2.client
+s
 .RestClient')%0A  
@@ -993,32 +993,33 @@
       c = Client
+s
 (domain='domain'
@@ -1247,32 +1247,33 @@
 'auth0.v2.client
+s
 .RestClient')%0A  
@@ -1359,32 +1359,33 @@
       c = Client
+s
 (domain='domain'
@@ -2045,32 +2045,33 @@
 'auth0.v2.client
+s
 .RestClient')%0A  
@@ -2160,32 +2160,33 @@
       c = Client
+s
 (domain='domain'
@@ -2382,16 +2382,17 @@
 2.client
+s
 .RestCli
@@ -2497,16 +2497,17 @@
 = Client
+s
 (domain=

Refactor test_clients to work with Clients()