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

add basic tests #9

Merged
merged 2 commits into from Dec 17, 2018
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+47 −2
Diff settings

Always

Just for now

Copy path View file
@@ -42,6 +42,7 @@ htmlcov/
nosetests.xml
coverage.xml
*,cover
.pytest_cache

# Translations
*.mo
Copy path View file
@@ -0,0 +1,9 @@
language: python
python:
- 3.5
- 3.6
install:
- pip install --upgrade setuptools pip
- pip install . -r dev-requirements.txt
script:
- pytest
Copy path View file
@@ -0,0 +1,2 @@
pytest
pytest-asyncio
Copy path View file
@@ -9,8 +9,8 @@
author_email='yuvipanda@gmail.com',
license='3 Clause BSD',
packages=find_packages(),
install_requires=['bcrypt'],
install_requires=['bcrypt', 'jupyterhub>=0.8'],
package_data={
'': ['*.html'],
}
},
)
Copy path View file
@@ -0,0 +1,33 @@
"""tests for first-use authenticator"""

import pytest
from unittest.mock import Mock

from firstuseauthenticator import FirstUseAuthenticator


@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 = FirstUseAuthenticator()
name = "name"
password = "firstpassword"
username = await auth.authenticate(Mock(), {"username": name, "password": password})
assert username == "name"
# second login, same password
username = await auth.authenticate(Mock(), {"username": name, "password": password})
assert username == "name"

# another login, reusing name but different password
username = await auth.authenticate(
Mock(), {"username": name, "password": "differentpassword"}
)
assert username is None
ProTip! Use n and p to navigate between commits in a pull request.