Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

912
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda