def setUp(self):
     self.client = Watchlist()
     self.url = self.client.url
     self.client.token = '123.456.789'
     self.client._set_header()
class TestMymovieWatchlist(unittest.TestCase):

    def setUp(self):
        self.client = Watchlist()
        self.url = self.client.url
        self.client.token = '123.456.789'
        self.client._set_header()

    @mock.patch('requests.post')
    def test_setup(self, mock_post):
        user = '******'
        password = '******'
        token = '123.456.789'
        mock_post.return_value = MockResponse(
            json_data=dict(token=token),
            status_code=200,
        )
        client = Watchlist(user, password)
        mock_post.assert_called_with(
            data=dict(
                username=user,
                password=password,
            ),
            url=self.url + '/auth/login',
        )
        self.assertEqual(
            token, client.token, 'watchlist client has incorrect token {0}'.format(client.token))
        self.assertEqual(
            client.headers.get('content_type'), 'application/json', 'incorrect content-type header')
        self.assertEqual(
            client.headers.get('authorization'), 'JWT {0}'.format(token), 'incorrect jwt auth header')

    @mock.patch('requests.post')
    def test_auth(self, mock_post):
        user = '******'
        password = '******'
        self.client.auth(user, password)
        mock_post.assert_called_with(
            data=dict(
                username=user,
                password=password,
            ),
            url=self.url + '/auth/login',
        )

    @mock.patch('requests.get')
    def test_user_details(self, mock_get):
        self.client.user_details()
        mock_get.assert_called_with(
            url=self.url + '/users/me',
            headers=self.client.headers,
        )

    @mock.patch('requests.get')
    def test_list(self, mock_get):
        self.client.list()
        mock_get.assert_called_with(
            url=self.url + '/watchlists',
            headers=self.client.headers,
        )

    @mock.patch('requests.get')
    def test_get(self, mock_get):
        list_id = "1"
        self.client.get(list_id)
        mock_get.assert_called_with(
            url=self.url + '/watchlists/' + list_id,
            headers=self.client.headers,
        )

    @mock.patch('requests.delete')
    def test_delete(self, mock_delete):
        list_id = "1"
        self.client.delete(list_id)
        mock_delete.assert_called_with(
            url=self.url + '/watchlists/' + list_id,
            headers=self.client.headers,
        )

    @mock.patch('requests.post')
    def test_create(self, mock_post):
        movie_data = dict(
            moviename="Star Trek",
            service="omdb",
            service_id="tt0796366",
            notifywhen=[0, 2, 3],
        )

        self.client.create(movie_data)
        mock_post.assert_called_with(
            url=self.url + '/watchlists',
            headers=self.client.headers,
            params=movie_data,
        )

    @mock.patch('requests.put')
    def test_update(self, mock_put):
        list_id = "1"
        movie_data = dict()
        self.client.update(list_id, movie_data)
        mock_put.assert_called_with(
            url=self.url + '/watchlists/' + list_id,
            headers=self.client.headers,
            params=movie_data,
        )