1

What are 'rf' and 'user_context' parameters and when are they assigned?

import pytest
from rest_framework import status
from rest_framework.reverse import reverse

from request_helper import pytest_request


@pytest.mark.urls(urls='api.urls')
@pytest.mark.django_db
def test_user_name_check_200(rf, users_context):
    data = {
        'username': 'test_jay_2'
    }
    url = reverse(viewname="users-check")
    response = pytest_request(rf,
                              method='get',
                              url=url,
                              user=None,
                              data=data)

    assert response.status_code == status.HTTP_200_OK
1
  • from where did you copy this snippet code? have your access to request_helper module? Commented Apr 15, 2022 at 12:40

1 Answer 1

1

Both are pytest fixtures (read about fixtures here: About fixtures). rf is defined in pytest-django (reference); a RequestFactory instance will be automatically injected for the rf argument in test. users_context is a fixture defined somewhere in your test project; search for something like

@pytest.fixture
def users_context():
    ...

in project code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.