utils¶
Functions
- login(user: Literal['admin', 'teacher', 'student']) Callable[[Callable[[P], T]], Callable[[P], T]][source]¶
Login
clientas 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)
- model_to_dict(model: models.Model, *, remove_relations: bool = True) dict[str, Any][source]¶
Convert a Django model to a dictionary.
Note
This ignores fields that are
None, as that is what is usually desired when POST-ing model data to a view.- Parameters:
model – the model to dictionarify
remove_relations – whether to exclude foreignkeys, m2m, and o2o relationships.
- 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'