utils

Functions

login(user: Literal['admin', 'teacher', 'student']) Callable[[Callable[P, T]], Callable[P, T]][source]

Login client as a tin user type.

@login("admin")
def test_no_redirect(client, course):
    response = client.post(reverse("courses:index"), {})
    assert not_login_redirect(response)

@login("teacher")
def test_teacher_thing(client):
    # client is logged in as a teacher

@login("student")
def test_redirect(client):
    # client is a student

def test_something(client):
    response = client.post(reverse("courses:index"), {})
    assert is_login_redirect(response)
str_to_html(s: str) str[source]

Converts a string to it’s html representation

>>> text = "It's annoying to remember HTML escape codes"
>>> str_to_html(text)
'It's annoying to remember HTML escape codes'
to_html(s: str, ctx: dict[str, Any]) str[source]

Convert template code to an html string

>>> template_logic = "Hello, my name is {{ username }}!"
>>> context = {"username": "2027adeshpan"}
>>> to_html(template_logic, context)
'Hello, my name is 2027adeshpan!'
Parameters:
  • s – The template string (see Template)

  • ctx – The variables/context to use for s (see Context)