def test_login(self): transport = self.StubTransport() client = BaseAPIClient(transport, None, None, None) client.login("foobear", "secret") self.assertEqual("foobear", client.username) self.assertEqual("secret", client.password) self.assertIs(self.StubTransport.FAKE_USER, transport.user) self.assertIs(self.StubTransport.FAKE_PARTNER, transport.partner)
def test_call_should_retry_on_token_error(self): transport = Mock(side_effect=[errors.InvalidAuthToken(), None]) client = BaseAPIClient(transport, None, None, None) client._authenticate = Mock() client.login("foo", "bar") client("method") client._authenticate.assert_called_with() transport.assert_has_calls([call("method"), call("method")])
def test_call_should_retry_on_token_error(self): transport = Mock(side_effect=[InvalidAuthToken(), None]) client = BaseAPIClient(transport, None, None, None) client._authenticate = Mock() client.login("foo", "bar") client("method") client._authenticate.assert_called_with() transport.assert_has_calls([call("method"), call("method")])
def test_with_valid_quality(self): result = BaseAPIClient.get_qualities( BaseAPIClient.MED_AUDIO_QUALITY, False) expected = [ BaseAPIClient.LOW_AUDIO_QUALITY, BaseAPIClient.MED_AUDIO_QUALITY] self.assertEqual(expected, result)
def test_with_valid_quality(self): result = BaseAPIClient.get_qualities(BaseAPIClient.MED_AUDIO_QUALITY, False) expected = [ BaseAPIClient.LOW_AUDIO_QUALITY, BaseAPIClient.MED_AUDIO_QUALITY ] self.assertEqual(expected, result)
def test_with_invalid_quality_returning_none(self): result = BaseAPIClient.get_qualities("foo", False) self.assertEqual([], result)
def test_with_invalid_quality_returning_all(self): result = BaseAPIClient.get_qualities("foo", True) self.assertEqual(BaseAPIClient.ALL_QUALITIES, result)
def test_login_user_error(self): with self.assertRaises(errors.InvalidUserLogin): transport = Mock(side_effect=[None, errors.InvalidPartnerLogin]) client = BaseAPIClient(transport, None, None, None) client.login("foobear", "secret")