Django/Selenium : request contains Anonymous user after successfully login

347 views Asked by At

I have a set of fixtures:

@pytest.fixture
def user()
    # A Django user

@pytest.fixture
def browser()
    # Splinter browser

@pytest.fixture
def logged_user(live_server, browser, user)
    browser.visit(url)
    browser.fill('username', user.username)
    browser.fill('password', 'abc')
    browser.find_by_id('login').first.click()
    return user

and when I run a test that uses them I got an

HttpResponseError: 403 - Forbidden

The browser (firefox) executes four actions:

  • Visit login page (success)
  • Fill login form (success)
  • Browser is automatically redirected to an index page (success, user is authenticated)
  • Browser visits another page of the site : Failure

The body of my test is essentially the following:

@pytest.mark.django_db(transaction=True)
@pytest.mark.selenium
def test_children_fed_report(live_server, browser, logged_user, page_data):
    url = reverse('app.myview')
    browser.visit(live_server.url + url)

The Auth context processor fills user variable with correct value (logged user) except for the last call where it fills with Anonymous user.

Both these answers (first, second) cannot help me: auth_login is called and the user is really authenticated before last step.

Thank you in advance for any advice!

0

There are 0 answers