def test_authentication_failure_raise_exception(monkeypatch): response = create_fake_response({}, 401) monkeypatch.setattr('requests.post', MagicMock(return_value=response)) with pytest.raises(NuException): nu = Nubank() nu.authenticate('12345678912', 'hunter12')
def test_authentication_succeeds(monkeypatch, authentication_return, proxy_list_return): proxy_list = create_fake_response(proxy_list_return) monkeypatch.setattr('requests.get', MagicMock(return_value=proxy_list)) response = create_fake_response(authentication_return) monkeypatch.setattr('requests.post', MagicMock(return_value=response)) nubank_client = Nubank() nubank_client.authenticate('12345678912', 'hunter12') assert nubank_client.feed_url == 'https://prod-s0-webapp-proxy.nubank.com.br/api/proxy/events_123' assert nubank_client.headers['Authorization'] == 'Bearer access_token_123'