-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from jupyterhub/add-minimal-tests
Add minimal tests
- Loading branch information
Showing
6 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pytest | ||
pytest-asyncio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |