-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
168 additions
and
28 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
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 was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
from papermerge.core import schema | ||
import uuid | ||
from passlib.hash import pbkdf2_sha256 | ||
from sqlalchemy import select | ||
|
||
from papermerge.core import schema, dbapi, orm | ||
from papermerge.core.tests.types import AuthTestClient | ||
|
||
|
||
|
||
def test_list_users(make_user, auth_api_client: AuthTestClient): | ||
for i in range(3): | ||
make_user(username=f"user {i}") | ||
|
@@ -11,6 +16,79 @@ def test_list_users(make_user, auth_api_client: AuthTestClient): | |
assert response.status_code == 200, response.json() | ||
|
||
|
||
def test_create_user(make_group, auth_api_client: AuthTestClient): | ||
group = make_group(name="demo") | ||
data = { | ||
"username": "friedrich", | ||
"email": "[email protected]", | ||
"group_ids": [str(group.id)], | ||
"scopes": [], | ||
"is_active": True, | ||
"is_superuser": False, | ||
"password": "blah" | ||
} | ||
response = auth_api_client.post("/users/", json=data) | ||
|
||
assert response.status_code == 201, response.json() | ||
|
||
|
||
def test_get_user_details( | ||
make_user, | ||
make_group, | ||
auth_api_client: AuthTestClient, | ||
db_session | ||
): | ||
"""In this scenario user belongs to one group""" | ||
user = make_user(username="Karl") | ||
group = make_group(name="demo") | ||
|
||
attrs = schema.UpdateUser(group_ids=[group.id]) | ||
dbapi.update_user(db_session, user_id=user.id, attrs=attrs) | ||
|
||
response = auth_api_client.get(f"/users/{user.id}") | ||
|
||
assert response.status_code == 200, response.json() | ||
|
||
|
||
def test_delete_user( | ||
make_user, | ||
make_group, | ||
auth_api_client: AuthTestClient, | ||
db_session | ||
): | ||
user = make_user(username="Karl") | ||
group = make_group(name="demo") | ||
|
||
attrs = schema.UpdateUser(group_ids=[group.id]) | ||
dbapi.update_user(db_session, user_id=user.id, attrs=attrs) | ||
|
||
response = auth_api_client.delete(f"/users/{user.id}") | ||
|
||
assert response.status_code == 204, response.text | ||
|
||
|
||
def test_change_user_password( | ||
make_user, | ||
auth_api_client: AuthTestClient, | ||
db_session | ||
): | ||
user = make_user(username="Karl") | ||
|
||
data = { | ||
"userId": str(user.id), | ||
"password": "secret" | ||
} | ||
|
||
response = auth_api_client.post(f"/users/{user.id}/change-password", json=data) | ||
|
||
assert response.status_code == 200, response.text | ||
stmt = select(orm.User).where(orm.User.id == user.id) | ||
|
||
db_user = db_session.execute(stmt).scalar() | ||
|
||
assert pbkdf2_sha256.verify("secret", db_user.password) | ||
|
||
|
||
def test_users_paginated_result__9_items_first_page( | ||
make_user, auth_api_client: AuthTestClient | ||
): | ||
|
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