Coverage for src/paperap/resources/users.py: 77%

1"""

2----------------------------------------------------------------------------

3

4 METADATA:

5

6 File: users.py

7 Project: paperap

8 Created: 2025-03-04

9 Version: 0.0.5

10 Author: Jess Mann

11 Email: jess@jmann.me

12 Copyright (c) 2025 Jess Mann

13

14----------------------------------------------------------------------------

15

16 LAST MODIFIED:

17

18 2025-03-04 By Jess Mann

19

20"""

21

22 from __future__ import annotations

23

24 from typing import Any, Optional

25

26 from paperap.exceptions import ObjectNotFoundError

27 from paperap.models.user import Group, GroupQuerySet, User, UserQuerySet

28 from paperap.resources.base import BaseResource, StandardResource

29

30

31 class UserResource(StandardResource[User, UserQuerySet]):

32 """Resource for managing users."""

33

34 model_class = User

35

36 def get_current(self) -> User:

37 """

38 Get the current authenticated user.

39

40 Returns:

41 The current user.

42

43 """

44 if not (response := self.client.request("GET", "users/me/")):

45 raise ObjectNotFoundError("Failed to get current user")

46 return User.from_dict(response)

47

48

49 class GroupResource(StandardResource[Group, GroupQuerySet]):

50 """Resource for managing groups."""

51

52 model_class = Group