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

Test/increase test coverage #84

Merged
merged 6 commits into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
Change log
==========

1.0.9 - 20201-02-21
1.1.1 - 2021-12-17
------------------

## What's Changed
- chore: add fixed version 1.1.1. by @wagnerdelima in https://github.com/wagnerdelima/drf-social-oauth2/pull/83


1.1.0 - 2021-12-16
------------------

## What's Changed
- Fix readme file by @zubrzubr in https://github.com/wagnerdelima/drf-social-oauth2/pull/43
- Reference the User model with get_user_model() by @bmpenuelas in https://github.com/wagnerdelima/drf-social-oauth2/pull/46
- Feat/django 4 support by @wagnerdelima in https://github.com/wagnerdelima/drf-social-oauth2/pull/82

## New Contributors
- @zubrzubr made their first contribution in https://github.com/wagnerdelima/drf-social-oauth2/pull/43
- @bmpenuelas made their first contribution in https://github.com/wagnerdelima/drf-social-oauth2/pull/46


1.0.9 - 2021-02-21
------------------

- Add general README info.
Expand Down
17 changes: 17 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,20 @@ https://developers.google.com/oauthplayground/.

For more information on how to configure python-social-auth with Google visit
https://python-social-auth.readthedocs.io/en/latest/backends/google.html#google-oauth2.


Running local tests
^^^^^^^^^^^^^^^^^^^

You may find drf-social-oauth2's unit tests in the tests/ directory. In order to run the tests locally, you can either
use pytest directly or coverage itself. Prior to running the test cases you need to install the local dependencies by:

$ pip3 install -r requirements.tests.txt

Then you can just run pytest in your terminal:

$ pytest

or call coverage to get the most updated test coverage:

$ coverage run --source='.' -m pytest && coverage html
2 changes: 1 addition & 1 deletion drf_social_oauth2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""python-social-auth and oauth2 support for django-rest-framework"""
__version__ = '1.1.1'
__version__ = '1.1.2'

try:
from secrets import SystemRandom
Expand Down
4 changes: 4 additions & 0 deletions requirements.test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pytest==6.2.5
djangorestframework==3.13.1
pytest-mock==3.6.1
coverage==6.2
30 changes: 25 additions & 5 deletions tests/drf_social_oauth2/test_authentication.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import pytest
import os

from requests.exceptions import HTTPError
from requests.models import Response
from rest_framework.exceptions import AuthenticationFailed
from pytest import raises

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'drf_social_oauth2.test_settings')

from drf_social_oauth2.authentication import SocialAuthentication
from django.http.request import HttpRequest
from django import setup

setup()

from drf_social_oauth2.authentication import SocialAuthentication


def create_request(content: str = 'Bearer'):
request = HttpRequest()
request.META = {'HTTP_AUTHORIZATION': content}
request.session = None
return request


Expand All @@ -20,15 +31,15 @@ def test_authenticate_no_backend_fail():
request = create_request('Bearer')
authenticated = SocialAuthentication()

with pytest.raises(AuthenticationFailed):
with raises(AuthenticationFailed):
authenticated.authenticate(request)


def test_authenticate_empty_bearer_fail():
request = create_request('Bearer facebook')
authenticated = SocialAuthentication()

with pytest.raises(AuthenticationFailed):
with raises(AuthenticationFailed):
authenticated.authenticate(request)


Expand All @@ -37,7 +48,7 @@ def test_authenticate_wrongly_formatted_token_fail():
request = create_request(token)
authenticated = SocialAuthentication()

with pytest.raises(AuthenticationFailed):
with raises(AuthenticationFailed):
authenticated.authenticate(request)


Expand All @@ -53,3 +64,12 @@ def test_authenticate(mocker):
user, token = authenticated.authenticate(request)
assert user
assert token


def test_authenticate_missing_backend():
token = 'Bearer unknown 401f7ac837da42b97f613d789819ff93537bee6a'
request = create_request(token)

authenticated = SocialAuthentication()
with raises(AuthenticationFailed):
authenticated.authenticate(request)