Skip to content

Commit

Permalink
Merge pull request #16 from avallbona/_add_coverage
Browse files Browse the repository at this point in the history
Added coverage
  • Loading branch information
avallbona authored Jun 14, 2020
2 parents a3ff687 + 64d2155 commit 36adbb5
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 20 deletions.
8 changes: 8 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[run]
source=impostor

[report]
omit = */migrations/*,*/tests/*,impostor/admin.py,impostor/apps.py
exclude_lines =
pragma: no cover
noqa
43 changes: 30 additions & 13 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ on:
branches: [ master, _work_in_progress ]

jobs:
build:
test:

runs-on: ubuntu-latest
strategy:
matrix:
# python: [3.5, 3.6, 3.7, 3.8]
python: [3.6, 3.7, 3.8]
django: [dj111, dj20, dj21, dj22, dj30]
exclude:
- python: 3.5
django: dj30

# strategy:
# matrix:
# python: [3.6, 3.7, 3.8]
# django: [dj111, dj20, dj21, dj22, dj30]
# exclude:
# - python: 3.5
# django: dj30
#
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
# with:
# python-version: ${{ matrix.python }}
- name: Install Tox and any other packages
run: |
pip install tox flake8 pytest
- name: Run Tox
# Run tox using the version of Python in `PATH`
run: tox -e py -- -v
# run: tox -e py -- -v
run: tox -- -v

lint:
runs-on: ubuntu-latest
Expand All @@ -47,3 +47,20 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
- name: Install Coverage
run: |
pip install django pytest pytest-django pytest-lazy-fixture pytest-cov
pip install -e .
- name: Execute coverage
run: |
# execute tests with coverage
pytest --cov-report=xml --cov=impostor tests/
export CODECOV_TOKEN="${{ secrets.CODECOV_TOKEN }}"
bash <(curl -s https://codecov.io/bash)
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
htmlcov
*,cover
.hypothesis/

Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 2.0.1 (2020-06-14)

* Added codecov coverage
* Improved code coverage
* Fixed test execution with django versions

## 2.0.0 (2020-06-13)

* Added informative badges on README.md
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Impostor

[![pypi](https://img.shields.io/pypi/v/impostor.svg)](https://pypi.python.org/pypi/impostor/)
[![codecov](https://codecov.io/gh/avallbona/Impostor/branch/master/graph/badge.svg)](https://codecov.io/gh/avallbona/Impostor)
[![Downloads](https://pepy.tech/badge/impostor)](https://pepy.tech/project/impostor)
[![Hit counter](http://hits.dwyl.com/avallbona/impostor.svg)](http://hits.dwyl.com/avallbona/impostor)
[![Python versions](https://img.shields.io/pypi/pyversions/impostor.svg)](https://pypi.org/project/Impostor/)
Expand Down
2 changes: 1 addition & 1 deletion impostor/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__VERSION__ = 2.0
__VERSION__ = "2.0.1"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def read(fname):

setup(
name="Impostor",
version="2.0.0",
version="2.0.1",
url='https://github.com/avallbona/Impostor/',
author='Marko Samastur',
author_email='[email protected]',
Expand Down
47 changes: 46 additions & 1 deletion tests/test_impostor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from django.contrib.auth import authenticate, get_user_model


from impostor.backend import AuthBackend
from impostor.forms import BigAuthenticationForm
from impostor.models import ImpostorLog

Expand Down Expand Up @@ -114,6 +114,17 @@ def test_login_admin_as_user_with_email(self):
])
def test_impersonation(self, first_user, password, impersonated_user, expected, custom_settings, rf):
"""
check diferent use cases of impersonation
:param first_user:
:param password:
:param impersonated_user:
:param expected:
:param custom_settings:
:param rf:
:return:
"""
assert ImpostorLog.objects.count() == 0
composed_username = '{} as {}'.format(first_user.username, impersonated_user.username)
authenticated_user = authenticate(request=rf, username=composed_username, password=password)
Expand All @@ -125,3 +136,37 @@ def test_impersonation(self, first_user, password, impersonated_user, expected,
assert log.imposted_as == impersonated_user
else:
assert authenticated_user is None

@pytest.mark.parametrize('user_passed, user_expected', [
(pytest.lazy_fixture('real_user_with_supergroup'), pytest.lazy_fixture('real_user_with_supergroup')),
(None, None)
])
def test_get_user(self, user_passed, user_expected):
"""
check get_user method
:param user_passed:
:param user_expected:
:return:
"""
try:
user_id = user_passed.id
except AttributeError:
user_id = None
result = AuthBackend.get_user(user_id)
assert result == user_expected

@pytest.mark.parametrize('existing_attr', [
True,
False
])
def test_impostor_group(self, custom_settings, existing_attr):
"""
check impostor_group property
:param custom_settings:
:return:
"""
if existing_attr:
delattr(custom_settings, 'IMPOSTOR_GROUP')
assert AuthBackend().impostor_group is None
else:
assert AuthBackend().impostor_group is not None
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ deps =
pytest==5.4.3
pytest-django==3.9.0
pytest-lazy-fixture==0.6.3
dj111: Django==1.11.29
dj20: Django==2.0.13
dj21: Django>=2.1.15
dj111: Django>=1.11,<2.0
dj20: Django==2.0.13,<2.1
dj21: Django>=2.1.15,<2.2
dj22: Django>=2.2,<3.0
dj30: Django>=3.0
dj30: Django>=3.0,<4.0
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}

Expand Down

0 comments on commit 36adbb5

Please sign in to comment.