-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add uid, name, mail args support, write tests
- Loading branch information
Showing
14 changed files
with
160 additions
and
87 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 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,6 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
|
||
from ckan import types | ||
|
||
|
||
|
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,17 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
import ckan.plugins.toolkit as tk | ||
from ckan import types | ||
|
||
|
||
def user_email_exists(email: str, context: types.Context) -> Any: | ||
"""Ensures that user with a specific email exists. | ||
Transform the email to user ID""" | ||
result = context["model"].User.by_email(email) | ||
|
||
if not result: | ||
raise tk.Invalid(tk._("Not found: User")) | ||
|
||
return result.id |
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,26 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
import ckan.model as model | ||
import ckan.plugins.toolkit as tk | ||
from ckan.tests.helpers import call_auth | ||
|
||
|
||
class TestGenerateOTLAuth: | ||
def test_anon(self): | ||
with pytest.raises(tk.NotAuthorized): | ||
call_auth("lmi_generate_otl", context={"user": None, "model": model}) | ||
|
||
@pytest.mark.usefixtures("clean_db") | ||
def test_regular_user(self, user): | ||
with pytest.raises(tk.NotAuthorized): | ||
call_auth( | ||
"lmi_generate_otl", context={"user": user["name"], "model": model} | ||
) | ||
|
||
@pytest.mark.usefixtures("clean_db") | ||
def test_sysadmin(self, sysadmin): | ||
call_auth( | ||
"lmi_generate_otl", context={"user": sysadmin["name"], "model": model} | ||
) |
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,46 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
import ckan.plugins.toolkit as tk | ||
from ckan.tests.helpers import call_action | ||
|
||
|
||
class TestGenerateOTL: | ||
def test_generate_no_params(self): | ||
with pytest.raises( | ||
tk.ValidationError, match="Please, provide uid, name or mail option" | ||
): | ||
call_action("lmi_generate_otl") | ||
|
||
@pytest.mark.usefixtures("clean_db") | ||
def test_more_than_one_param(self, user): | ||
with pytest.raises( | ||
tk.ValidationError, | ||
match="One param could be used at a time: uid, name or mail", | ||
): | ||
call_action("lmi_generate_otl", uid=user["id"], name=user["name"]) | ||
|
||
def test_uid_not_exist(self): | ||
with pytest.raises(tk.ValidationError, match="Not found: User"): | ||
call_action("lmi_generate_otl", uid="xxx") | ||
|
||
def test_name_not_exist(self): | ||
with pytest.raises(tk.ValidationError, match="Not found: User"): | ||
call_action("lmi_generate_otl", name="xxx") | ||
|
||
def test_mail_not_exist(self): | ||
with pytest.raises(tk.ValidationError, match="Not found: User"): | ||
call_action("lmi_generate_otl", mail="xxx") | ||
|
||
@pytest.mark.usefixtures("clean_db") | ||
def test_by_uid(self, user): | ||
call_action("lmi_generate_otl", uid=user["id"]) | ||
|
||
@pytest.mark.usefixtures("clean_db") | ||
def test_by_name(self, user): | ||
call_action("lmi_generate_otl", name=user["name"]) | ||
|
||
@pytest.mark.usefixtures("clean_db") | ||
def test_by_male(self, user): | ||
call_action("lmi_generate_otl", mail=user["email"]) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
import ckan.plugins.toolkit as tk | ||
from ckan import model | ||
|
||
from ckanext.let_me_in.logic.validators import user_email_exists | ||
|
||
|
||
class TestEmailExistValidator: | ||
def test_no_user(self): | ||
with pytest.raises(tk.Invalid, match="User not found"): | ||
user_email_exists("test", {"model": model}) | ||
|
||
@pytest.mark.usefixtures("clean_db") | ||
def test_user_exists(self, user): | ||
assert user_email_exists(user["email"], {"model": model}) |
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