• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Brunowar12 / TaskManagerSystem / 15166388190

21 May 2025 03:32PM UTC coverage: 92.47% (-0.3%) from 92.77%
15166388190

push

github

web-flow
Merge pull request #27 from Brunowar12/bugfix-and-pep

Bug fixes and code style cleanup

159 of 183 new or added lines in 24 files covered. (86.89%)

10 existing lines in 6 files now uncovered.

1621 of 1753 relevant lines covered (92.47%)

5.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/users/services.py
1
from django.contrib.auth import get_user_model
6✔
2
from rest_framework_simplejwt.tokens import RefreshToken
6✔
3
from rest_framework_simplejwt.exceptions import TokenError
6✔
4

5
from .serializers import (
6✔
6
    UserRegistrationSerializer, UserLoginSerializer, UserProfileSerializer
7
)
8

9
User = get_user_model()
6✔
10

11
class UserService:
6✔
12
    @staticmethod
6✔
13
    def register_user(data):
6✔
14
        """
15
        Handle user registration
16

17
        Validates and saves the user via serializer
18
        """
19
        serializer = UserRegistrationSerializer(data=data)
6✔
20
        serializer.is_valid(raise_exception=True)
6✔
21
        serializer.save()        
6✔
22
        return serializer.data
6✔
23

24
    @staticmethod
6✔
25
    def login_user(data):
6✔
26
        """
27
        Handle user login
28

29
        Validates credentials and returns JWT token payload
30
        """
31
        serializer = UserLoginSerializer(data=data)
6✔
32
        serializer.is_valid(raise_exception=True)
6✔
33
        return serializer.validated_data
6✔
34

35
    @staticmethod
6✔
36
    def logout_user(refresh_token):
6✔
37
        """
38
        Handle user logout by blacklisting the refresh token
39
        """
40
        try:
6✔
41
            token = RefreshToken(refresh_token)
6✔
42
            token.blacklist()
6✔
43
            return {"message": "Successfully logged out"}
6✔
44
        except TokenError as e:
6✔
45
            msg = str(e).lower()
6✔
46
            if "token is invalid or expired" in msg:
6✔
47
                raise ValueError("Token expired")
6✔
NEW
48
            elif "token is already blacklisted" in msg:
×
NEW
49
                raise ValueError("Token already revoked")
×
50
            else:
NEW
51
                raise ValueError("Invalid token format")
×
52

53
    @staticmethod
6✔
54
    def update_profile(user, data):
6✔
55
        """
56
        Handle profile update for the authenticated user
57
        """
58
        serializer = UserProfileSerializer(user, data=data, partial=True)
6✔
59
        serializer.is_valid(raise_exception=True)
6✔
60
        serializer.save()
6✔
61
        return serializer.data
6✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc