You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by se...@apache.org on 2022/01/28 22:06:14 UTC
[incubator-ponymail-foal] branch master updated: Add mgmt validation tests
This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git
The following commit(s) were added to refs/heads/master by this push:
new 02ce0ff Add mgmt validation tests
02ce0ff is described below
commit 02ce0ffb03ed3c3b7763ed1da8131e5cf071da20
Author: Sebb <se...@apache.org>
AuthorDate: Fri Jan 28 22:06:03 2022 +0000
Add mgmt validation tests
---
test/itest_integration.py | 52 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 50 insertions(+), 2 deletions(-)
diff --git a/test/itest_integration.py b/test/itest_integration.py
index 549deea..89900d4 100644
--- a/test/itest_integration.py
+++ b/test/itest_integration.py
@@ -33,10 +33,8 @@ def get_cookies(user='user'):
code = res.headers['Location'][1:]
res = requests.get(f"{API_BASE}/oauth.lua?key=ignored{code}&oauth_token={API_BASE}/{testauth}&state={state}&user={user}")
cookies = res.cookies
- print(res.text)
jzon = requests.get(f"{API_BASE}/preferences", cookies=cookies).json()
assert 'credentials' in jzon['login']
- print(jzon['login']['credentials'])
return cookies
def check_access(email, cookies):
@@ -149,3 +147,53 @@ def test_private_stats():
assert email['id'] == email['mid']
assert email['private']
check_access(email, cookies)
+
+def mgmt_get_text(params, cookies, expected=200):
+ res = requests.post(f"{API_BASE}/mgmt.lua", params=params, cookies=cookies)
+ assert res.status_code == expected, res.text
+ return res.text
+
+def mgmt_get_json(params, cookies, expected=200):
+ res = requests.post(f"{API_BASE}/mgmt.lua", params=params, cookies=cookies)
+ assert res.status_code == expected, res.text
+ return res.json()
+
+def test_mgmt_validation():
+ admin_cookies = get_cookies('admin')
+ user_cookies = get_cookies('user')
+ mgmt_get_text({"action": 'log'}, user_cookies, 403)
+ mgmt_get_text({"action": 'any'}, admin_cookies, 404)
+
+ text = mgmt_get_text({"action": 'delete'}, admin_cookies)
+ assert text == "Removed 0 emails from archives."
+
+ text = mgmt_get_text({"action": 'hide'}, admin_cookies)
+ assert text == "Hid 0 emails from archives."
+
+ text = mgmt_get_text({"action": 'unhide'}, admin_cookies)
+ assert text == "Unhid 0 emails from archives."
+
+ text = mgmt_get_text({"action": 'delatt'}, admin_cookies)
+ assert text == "Removed 0 attachments from archives."
+
+ text = mgmt_get_text({"action": 'edit'}, admin_cookies, 500)
+ assert "ValueError: Document ID is missing or invalid" in text
+
+ text = mgmt_get_text({"action": 'edit', "document": '1234'}, admin_cookies, 500)
+ assert "ValueError: Author field" in text
+
+ text = mgmt_get_text({"action": 'edit', "document": '1234', "from": 'sender'}, admin_cookies, 500)
+ assert "ValueError: Subject field" in text
+
+ text = mgmt_get_text({"action": 'edit', "document": '1234', "from": 'sender', "subject": 'Test Email'}, admin_cookies, 500)
+ assert "ValueError: List ID field" in text
+
+ text = mgmt_get_text(
+ {"action": 'edit', "document": '1234', "from": 'sender', "subject": 'Test Email', "list": 'abc'},
+ admin_cookies, 500)
+ assert "ValueError: Email body" in text
+
+ text = mgmt_get_text(
+ {"action": 'edit', "document": '1234', "from": 'sender', "subject": 'Test Email', "list": 'abc', "body": 'body'},
+ admin_cookies, 404)
+ assert "Email not found!" in text