Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

906
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!