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

Brunowar12 / TaskManagerSystem / 15567645473

10 Jun 2025 06:42PM UTC coverage: 92.548% (+0.07%) from 92.479%
15567645473

push

github

web-flow
fix: minor style corrections and enhancements (#31)

* fix: corrections to style and minor errors in the code

- unused imports (commented where necessary)
+ fix docstrings
+ fix assert checks in create test user method
+ 2 blank lines before classes and funcs

* fix: small style patch

* fix: style fixes

* fix: style patch

* feat: serializers return user/owner name and some style patch

+ category and project serializer now return user/owner username

57 of 76 new or added lines in 20 files covered. (75.0%)

1 existing line in 1 file now uncovered.

1627 of 1758 relevant lines covered (92.55%)

5.55 hits per line

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

94.29
/api/tests/utils.py
1
from datetime import timedelta
6✔
2
from django.urls import reverse
6✔
3
from django.contrib.auth import get_user_model
6✔
4
from django.utils import timezone
6✔
5
from rest_framework import status
6✔
6
from rest_framework_simplejwt.tokens import RefreshToken
6✔
7

8
User = get_user_model()
6✔
9

10

11
class TokenService:
6✔
12
    """
13
    Utility class for generating tokens
14

15
    Methods:
16
        generate_tokens_for: Generates access and refresh tokens for the specified user
17
    """
18

19
    @staticmethod
6✔
20
    def generate_tokens_for(user):
6✔
21
        refresh_obj = RefreshToken.for_user(user)
6✔
22
        return {
6✔
23
            "access": str(refresh_obj.access_token),
24
            "refresh": str(refresh_obj),
25
        }
26

27

28
class TestHelper:
6✔
29
    @staticmethod
6✔
30
    def create_test_user(client, email="testuser@example.com", password="testpassword123"):
6✔
31
        """
32
        Creates a test user by registering and logging in through the API
33

34
        Args:
35
            client: The test client instance.
36
            email (str): The email address of the test user. 
37
                Defaults to "testuser@example.com"
38
            password (str): The password of the test user. 
39
                Defaults to "testpassword123"
40

41
        Returns:
42
            tuple: A tuple containing the created user instance, access token, and 
43
                refresh token
44

45
        Raises:
46
            AssertionError: If user registration or login fails
47
        """
48
        user_data = {"email": email, "password": password}
6✔
49
        response = client.post(reverse("auth-register"), user_data)
6✔
50
        if response.status_code != status.HTTP_201_CREATED:
6✔
NEW
51
            raise AssertionError(f"User registration failed: {response.data}")
×
52

53
        user = User.objects.get(email=email)
6✔
54
        response = client.post(reverse("auth-login"), user_data)
6✔
55
        if response.status_code != status.HTTP_200_OK:
6✔
NEW
56
            raise AssertionError(f"User login failed: {response.data}")
×
57

58
        token = response.data.get("access")
6✔
59
        refresh = response.data.get("refresh")
6✔
60

61
        return user, token, refresh
6✔
62

63
    @staticmethod
6✔
64
    def create_test_user_via_orm(email="testuser@example.com", password="testpassword123"):
6✔
65
        """
66
        Creates a test user via ORM
67

68
        Args:
69
            email (str): The email address of the test user. 
70
                Defaults to "testuser@example.com"
71
            password (str): The password of the test user. 
72
                Defaults to "testpassword123"
73

74
        Returns:
75
            tuple: A tuple containing the created user instance, access token, 
76
                and refresh token
77
        """
78
        user = User.objects.create_user(
6✔
79
            username=email.split("@")[0], email=email, password=password
80
        )
81
        tokens = TokenService.generate_tokens_for(user)
6✔
82

83
        return user, tokens["access"], tokens["refresh"]
6✔
84

85
    @staticmethod
6✔
86
    def get_valid_due_date(days: int = 14):
6✔
87
        """
88
        Returns a valid due date in ISO format
89

90
        Args:
91
            days (int): The number of days from the current date. Defaults to 14
92

93
        Returns:
94
            str: A future date in ISO format (YYYY-MM-DDTHH:MM:SSZ)
95
                with microseconds set to 0
96
        """
97
        future_date = timezone.now() + timedelta(days=days)
6✔
98
        return future_date.replace(microsecond=0).isoformat() + "Z"
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

© 2026 Coveralls, Inc