Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test coverage #1190

Merged
merged 10 commits into from
Nov 8, 2021
Merged

Improve test coverage #1190

merged 10 commits into from
Nov 8, 2021

Conversation

gorkemarslan
Copy link
Collaborator

@gorkemarslan gorkemarslan commented Nov 7, 2021

  • I try to improve the unit test coverage discussed in Improve unit test coverage #952. Coverage increases from 54% to 65%.
  • I fix the errors that I detect in the backend.
    For example:
    When we want to get draft threads we get published ones, not draft ones.
    Notice how is_draft parameters are used in these functions:
    @action(detail=True)
    def drafts(self, request, user__username=None):
    """
    Gets the draft threads of the selected account
    /accounts/{username}/drafts
    """
    user = get_user_model().objects.get(username=user__username)
    draft_threads = Thread.objects.filter(author=user, is_draft=False)
    serializer = ThreadSerializer(
    draft_threads, many=True, context={"request": request}
    )
    return Response(serializer.data)

    and vice versa
    @action(detail=True)
    def threads(self, request, user__username=None):
    """
    Gets the preferred categories of the selected account
    /accounts/{username}/categories
    """
    user = get_user_model().objects.get(username=user__username)
    draft_threads = Thread.objects.filter(author=user).exclude(is_draft=False)
    serializer = ThreadSerializer(
    draft_threads, many=True, context={"request": request}
    )
    return Response(serializer.data)

Another example:

problems = []
for idx, item in enumerate(c_data):
problems[idx]["score"] = c_scores[idx]

Since problems is an empty array, it is not appropriate to add elements by inserting them via index. The correct way is to use append() method.

  • I add api_view(['GET']) decorators to get_user(), get_profile(), and get_card() functions to give them DRF permissions defined in settings.py. Thus AnonymousUser cannot get sensitive user data.

  • Interestingly, GitHub shows my changes as removing files and recreating them. 🤔

@gorkemarslan gorkemarslan changed the title Unit tests Improve test coverage Nov 7, 2021
@brylie brylie merged commit 1ad868b into CiviWiki:develop Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants