Skip to content

Commit

Permalink
Merge pull request #5 from jupyterhub/add-minimal-tests
Browse files Browse the repository at this point in the history
Add minimal tests
  • Loading branch information
leportella authored Dec 5, 2018
2 parents ad7452e + 9630a1b commit 01b3580
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: python
python:
- 3.5
- 3.6
- 3.7
install:
- pip install --upgrade setuptools pip
- pip install . -r dev-requirements.txt
script:
- pytest
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
# nativeauthenticator
JupyterHub-native user authenticator
# Native Authenticator

[JupyterHub](http://github.com/jupyter/jupyterhub/) authenticator


## Installation

While this package is not on package manager, you can clone this repository and
install it with:

`$ pip install -e .`

You can then use this as your authenticator by adding the following line to your jupyterhub_config.py:

`c.JupyterHub.authenticator_class = 'nativeauthenticator.NativeAuthenticator'`


## Running tests

To run the tests locally, you can install the development dependencies:

`$ pip install dev-requirements.txt`

Then run tests with pytest:

`$ pytest`

2 changes: 2 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest
pytest-asyncio
7 changes: 6 additions & 1 deletion nativeauthenticator/nativeauthenticator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from jupyterhub.auth import Authenticator

from tornado import gen


class NativeAuthenticator(Authenticator):
pass

@gen.coroutine
def authenticate(self, handler, data):
return data['username']
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
author_email='leportella@protonmail.com',
license='3 Clause BSD',
packages=find_packages(),
install_requires=['bcrypt'],
install_requires=['jupyterhub>=0.8'],
package_data={
'': ['*.html'],
}
Expand Down
23 changes: 23 additions & 0 deletions tests/test_authenticator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pytest
from unittest.mock import Mock


from nativeauthenticator import NativeAuthenticator


@pytest.fixture
def tmpcwd(tmpdir):
tmpdir.chdir()


# use pytest-asyncio
pytestmark = pytest.mark.asyncio
# run each test in a temporary working directory
pytestmark = pytestmark(pytest.mark.usefixtures("tmpcwd"))


async def test_basic(tmpcwd):
auth = NativeAuthenticator()
response = await auth.authenticate(Mock(), {'username': 'name',
'password': '123'})
assert response == 'name'

0 comments on commit 01b3580

Please sign in to comment.