From 25bebc1cc97e8382795f1a2202b12703368c4aaa Mon Sep 17 00:00:00 2001 From: blagoja Date: Wed, 28 Feb 2024 10:44:58 +0100 Subject: [PATCH] Add helpers testst --- ckanext/keycloak/tests/test_helpers.py | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 ckanext/keycloak/tests/test_helpers.py diff --git a/ckanext/keycloak/tests/test_helpers.py b/ckanext/keycloak/tests/test_helpers.py new file mode 100644 index 0000000..8d0334e --- /dev/null +++ b/ckanext/keycloak/tests/test_helpers.py @@ -0,0 +1,33 @@ +import pytest +import ckan.model as model +import ckan.tests.factories as factories +from ckanext.keycloak import helpers as h + + +def test_generate_password(): + password = h.generate_password() + assert len(password) >= 8 + assert type(password) is str + + +@pytest.mark.usefixtures(u'clean_db', u'clean_index') +def test_activate_user_if_deleted(): + user = factories.User() + user = model.User.get(user[u'name']) + user.delete() + h.activate_user_if_deleted(user) + assert not user.is_deleted() + + +@pytest.mark.usefixtures(u'clean_db') +def test_ensure_unique_user_name_existing_user(): + + user = factories.User( + name='existing-user', + email=u'existing-user@example.com' + ) + + user_name = h.ensure_unique_username_from_email(user['email']) + + assert user_name != user['email'].split('@')[0] + assert user_name.startswith(user['email'].split('@')[0]) \ No newline at end of file