Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

908
Visualizações
Pytest Flask, error 308 Permanent Redirect when login

I want to try my app, here is the test code :

import sys
import pytest
from flask_simplelogin import SimpleLogin

sys.path.insert(1, '')
from app import app as myapp


#---------------------------------------------------
#SETUP
#---------------------------------------------------

myapp.config['SECRET_KEY'] = 'something-secret'
myapp.config['SIMPLELOGIN_USERNAME'] = 'admin'
myapp.config['SIMPLELOGIN_PASSWORD'] = 'secret'
SimpleLogin(myapp)

@pytest.fixture
def app():
    return myapp

@pytest.fixture
def setup_url():
    return "http://127.0.0.1:8080/"

def login(client):
    return client.post("http://127.0.0.1:8080/login", data=dict(
        username="admin",
        password="secret"
    ))

#---------------------------------------------------
#TESTS
#---------------------------------------------------

def test_get_list_campagne(client,setup_url):
    resp = login(client)
    assert resp.status_code==200

    resp = client.get("/Campagne")
    assert resp.status_code==200

But it returns a permanent redirection, so i tried with the attribute "follow_redirects=True" :

def login(client):
    return client.post("http://127.0.0.1:8080/login", data=dict(
        username="admin",
        password="taleinfo"
    ), follow_redirects=True)

But i think it is just a way to get around the problem, i don't think i'm logged after that.

here the error : E AssertionError: assert 308 == 200 E + where 308 = < 263 bytes [308 PERMANENT REDIRECT]>.status_code

I do not found any similar problem. Thank you for your help.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I got this same error as a result of having two slashes in my path. It was something like:

def test_my_annoying_failing_test(client):
   response = client.post('/api//my_path/to-somewhere') # notice the double slash
   # ...test continues here..

Changing that double slash to a single slash fixed it for me:

def test_my_annoying_failing_test(client):
   response = client.post('/api/my_path/to-somewhere')
   # ...test continues here..

I am not sure what the root cause of that issue is though.

over 4 years ago · Santiago Trujillo Relatório

0

Had the same problem I solved it by adding a Slash /

try this code:

def login(client):
return client.post("http://127.0.0.1:8080/login/", data=dict(
    username="admin",
    password="secret"
))

as you can see add the Slash in the login/ like that. it sounds stupid I know but give it a try and let me know.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda