Skip to content

AttributeError: object has no attribute '_request' #56

@lexicalunit

Description

@lexicalunit

Using the example for testing results in an exception at runtime.

import pytest
from django.contrib.admin import AdminSite

from yourapp.module.admin import MyAdmin


@pytest.fixture
def admin_site():
    return AdminSite()

@pytest.mark.django_db
def test_action_XXX(admin_site):
    """Test action XXX"""
    fake_request = {}  # you might need to use a RequestFactory here
    obj = ...  # create an instance

    admin = MyAdmin(obj, admin_site)

    admin.render_inline_actions(article)
    response = admin.action_XXX(fake_request, obj)
    # assert the state of the application

This will fail on the line admin.render_inline_actions(article) because this code is invalid:

for action_name in self.get_inline_actions(self._request, obj):

At this point in the code the HTTP Request has not been given to the Admin object, so this attribute does not exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions