Skip to content

Commit fb4df7f

Browse files
committed
Add test for decorator with allowPublicPost set
1 parent 76f1bc8 commit fb4df7f

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

test/unit/test_login_required.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
rf = RequestFactory()
2727
decorator = login_required()
28+
decorator_allow_public_post = login_required(allowPublicPost=True)
2829

2930

3031
def test_is_valid_public_url_default(monkeypatch):
@@ -157,3 +158,16 @@ def test_is_valid_public_url_any_method(monkeypatch):
157158
assert decorator.is_valid_public_url(1, rf.post("/api/v0/login")) is True
158159
assert decorator.is_valid_public_url(1, rf.get("/webgateway/")) is False
159160
assert decorator.is_valid_public_url(1, rf.get("/webclient/")) is False
161+
162+
163+
def test_is_valid_table_slice_call(monkeypatch):
164+
monkeypatch.setattr(settings, "PUBLIC_ENABLED", True)
165+
monkeypatch.setattr(settings, "PUBLIC_USER", "public.user", raising=False)
166+
monkeypatch.setattr(settings, "PUBLIC_PASSWORD", "password", raising=False)
167+
monkeypatch.setattr(settings, "PUBLIC_GET_ONLY", True)
168+
monkeypatch.setattr(settings, "PUBLIC_URL_FILTER", re.compile("^/api"))
169+
assert decorator_allow_public_post.is_valid_public_url(1, rf.get("/webgateway/table/123/slice")) is False
170+
assert decorator_allow_public_post.is_valid_public_url(1, rf.post("/webgateway/table/123/slice")) is False
171+
monkeypatch.setattr(settings, "PUBLIC_URL_FILTER", re.compile("^/api|webgateway"))
172+
assert decorator_allow_public_post.is_valid_public_url(1, rf.get("/webgateway/table/123/slice")) is True
173+
assert decorator_allow_public_post.is_valid_public_url(1, rf.post("/webgateway/table/123/slice")) is True

0 commit comments

Comments
 (0)