Skip to content

Commit

Permalink
feature: add config_declaration, update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantsan committed Oct 10, 2023
1 parent d2062e9 commit 070e829
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
9 changes: 9 additions & 0 deletions ckanext/let_me_in/config_declaration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 1
groups:
- annotation: ckanext-let_me_in
options:
- key: ckanext.let_me_in.otl_link_ttl
type: int
description: Specify a default TTL for an OTL link in seconds
default: 86400
validators: ignore_missing int_validator is_positive_integer
1 change: 1 addition & 0 deletions ckanext/let_me_in/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@tk.blanket.auth_functions
@tk.blanket.blueprints
@tk.blanket.validators
@tk.blanket.config_declarations
class LetMeInPlugin(p.SingletonPlugin):
p.implements(ILetMeIn, inherit=True)

Expand Down
24 changes: 22 additions & 2 deletions ckanext/let_me_in/tests/test_logic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations
from math import e

import pytest

Expand Down Expand Up @@ -47,5 +48,24 @@ def test_by_male(self, user):
call_action("lmi_generate_otl", mail=user["email"])

@pytest.mark.usefixtures("clean_db")
def test_ttl_option(self, user):
call_action("lmi_generate_otl", mail=user["email"])
@pytest.mark.parametrize(
"ttl,raises_error",
[
(1, False),
(1000, False),
(0, True),
(-1, True),
(-999, True),
],
)
def test_ttl_negative_value(self, ttl, raises_error, user):
if raises_error:
with pytest.raises(tk.ValidationError, match="Must be a positive integer"):
call_action("lmi_generate_otl", mail=user["email"], ttl=ttl)
else:
call_action("lmi_generate_otl", mail=user["email"], ttl=ttl)

@pytest.mark.usefixtures("clean_db")
def test_ttl_not_int(self, user):
with pytest.raises(tk.ValidationError, match="Invalid integer"):
call_action("lmi_generate_otl", mail=user["email"], ttl="xxx")
4 changes: 2 additions & 2 deletions ckanext/let_me_in/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_visit_link_after_user_has_been_deleted(self, app, user):
@pytest.mark.parametrize(
"delta_kwargs,expired",
[
({"days": 1}, True),
({"days": 1, "hours": 1}, True),
({"hours": 23}, False),
],
)
Expand All @@ -77,7 +77,7 @@ def test_user_is_not_active(self, app, user_factory):
@pytest.mark.parametrize(
"delta_kwargs,ttl,expired",
[
({"seconds": SECOND}, SECOND, EXPIRED), # 1 seconds, immediately expires
({"minutes": 5}, SECOND, EXPIRED),
({"hours": 2}, HOUR, EXPIRED),
({"hours": 2}, HOUR * 3, not EXPIRED),
],
Expand Down

0 comments on commit 070e829

Please sign in to comment.