Skip to content

Commit

Permalink
- adds User.set_password unittest
Browse files Browse the repository at this point in the history
- defines settings variable to control admin-related keycloak API

Ref: #71
  • Loading branch information
oliveratfoodcoopx authored and mk2301 committed Jan 9, 2023
1 parent 50936e8 commit 71b3b38
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
1 change: 0 additions & 1 deletion tapir/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ class TapirUser(LdapUser):
"unique": _("A user with that username already exists."),
},
)

phone_number = PhoneNumberField(_("Phone number"), blank=True)
birthdate = models.DateField(_("Birthdate"), blank=True, null=True)
street = models.CharField(_("Street and house number"), max_length=150, blank=True)
Expand Down
12 changes: 7 additions & 5 deletions tapir/accounts/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
from unittest import mock
from django.core.exceptions import ValidationError
from django.contrib.auth import get_user_model
from tapir.utils.tests_utils import KeycloakTestCase
from tapir.utils.tests_utils import LadapCleanupTestMixin, KeycloakTestCase

User = get_user_model()

class TapirUserTests(KeycloakTestCase):
class TapirUserTests(LadapCleanupTestMixin, KeycloakTestCase):

def test_model_validates_usernames(self):
self.has_ldap.return_value = False
self.ldap_save.return_value = None

usernames = [
"asd$",
]
Expand All @@ -20,4 +17,9 @@ def test_model_validates_usernames(self):
except ValidationError:
continue
self.fail(f"validation error not raised for username: {username}")

def test_user_can_set_its_password(self):
user = self.create_user()
user.set_password("anypassword")
self.assertTrue(user.check_password("anypassword"))

4 changes: 1 addition & 3 deletions tapir/accounts/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,5 @@ def test_product_view_buttons_only_available_with_proper_perm(self):
r = self.app.get(url, user=user)
for selector in selectors:
self.assertIsNotNone(r.html.select_one(selector), selectors)





10 changes: 9 additions & 1 deletion tapir/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,15 @@
SERVER_URL=env("KEYCLOCK_SERVER_URL", default="http://keycloak-server:8080"),
CLIENT_ID=env("KEYCLOCK_CLIENT_ID", default="tapirweb"),
REALM_NAME=env("KEYCLOCK_REALM_NAME", default="tapir"),
CLIENT_SECRET_KEY=env("KEYCLOCK_CLIENT_SECRET_KEY", default="UYAoNSPYkJd8IpktSYOXp24PBHT6LN1r"),
CLIENT_SECRET_KEY=env("KEYCLOCK_CLIENT_SECRET_KEY", default="eMZVvyfmAsjbxykV4GtIEeikfQUfHfkO"),
)
KEYCLOAK_ADMIN_CONFIG = dict(
SERVER_URL=env("KEYCLOCK_ADMIN_SERVER_URL", default="http://keycloak-server:8080"),
USERNAME=env("KEYCLOCK_ADMIN_USERNAME", default="admin"),
PASSWORD=env("KEYCLOCK_ADMIN_PASSWORD", default="admin"),
REALM_NAME=env("KEYCLOCK_ADMIN_REALM_NAME", default="master"),
USER_REALM_NAME=env("KEYCLOCK_ADMIN_USER_REALM_NAME", default="tapir"),
CLIENT_SECRET_KEY=env("KEYCLOCK_ADMIN_CLIENT_SECRET_KEY", default="CPE1r5Uf37ICNU9Wce7w9vDEeZ6cbNSF"),
)
AUTHENTICATION_BACKENDS = [
'tapir.accounts.backends.KeycloakAuthorizationCredentialsBackend',
Expand Down

0 comments on commit 71b3b38

Please sign in to comment.