Skip to content

Commit

Permalink
debug test
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquesfize committed Jul 5, 2024
1 parent 5a3aeef commit 62f24e9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
28 changes: 13 additions & 15 deletions src/pypnusershub/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,28 +302,26 @@ def insert_or_update_role(
)
).scalar_one()
if user_exists:
user = UserSchema().load(UserSchema().dump(user))
if not provider in user.providers:
user.providers.append(provider)
db.session.add(user)
db.session.commit()

if not provider in user_exists.providers:
user_exists.providers.append(provider)
db.session.commit()
return user_exists
else:
group_id = ""
# No group mapping indicated
if not (provider_instance.group_mapping and group_keys):
if not "DEFAULT_RECONCILIATION_GROUP_ID" in current_app.config.get(

if "DEFAULT_RECONCILIATION_GROUP_ID" in current_app.config.get(
"AUTHENTICATION", {}
):
raise Exception(
f"If no group mapping indicated for the provider {provider.id_provider}, DEFAULT_RECONCILIATION_GROUP_ID must be set !"
)
group_id = current_app.config["AUTHENTICATION"][
"DEFAULT_RECONCILIATION_GROUP_ID"
]
group = db.session.get(models.User, group_id)
if group:
user.groups.append(group)

group_id = current_app.config["AUTHENTICATION"][
"DEFAULT_RECONCILIATION_GROUP_ID"
]
group = db.session.get(models.User, group_id)
if group:
user.groups.append(group)
# Group Mapping indicated
else:
for key in group_keys:
Expand Down
2 changes: 1 addition & 1 deletion src/pypnusershub/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def app():

app.testing = True
app.test_client_class = JSONClient
app.config["AUTHENTICATION"] = {"DEFAULT_RECONCILIATION_GROUP_ID": 2}
app.config["AUTHENTICATION"] = {}
app.config.from_envvar("USERSHUB_AUTH_MODULE_SETTINGS")
app.testing = True
db.init_app(app)
Expand Down
17 changes: 12 additions & 5 deletions src/pypnusershub/tests/test_utilisateurs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def provider_instance():

@pytest.mark.usefixtures("client_class", "temporary_transaction")
class TestUtilisateurs:
def test_insert_user(self, organism, group_and_users, provider_instance):
def test_insert_user(self, app, organism, group_and_users, provider_instance):
user_schema = UserSchema(exclude=["nom_complet", "max_level_profil"])
group = group_and_users["group1"]

Expand All @@ -36,17 +36,24 @@ def test_insert_user(self, organism, group_and_users, provider_instance):
"groups": [group],
}
user_ = User(**user_dict)
insert_or_update_role(user_, provider_instance)
user_dict["identifiant"] = "update"
user_ = User(**user_dict)
insert_or_update_role(user_, provider_instance)
user_ = insert_or_update_role(user_, provider_instance)
user_.identifiant = "update"
db.session.commit()

created_user = db.session.get(User, 99999)
user_schema = UserSchema(only=["groups"])
created_user_as_dict = user_schema.dump(created_user)
assert created_user_as_dict["identifiant"] == "update"
assert created_user_as_dict["id_role"] == 99999
assert len(created_user_as_dict["groups"]) == 1

app.config["AUTHENTICATION"]["DEFAULT_RECONCILIATION_GROUP_ID"] = 2
user_dict["id_role"] = 99998
user_dict["email"] = "[email protected]"
user_ = User(**user_dict)
user_ = insert_or_update_role(user_, provider_instance)
assert len(user_.groups) == 2

def test_insert_organisme(self):
organism = {
"nom_organisme": "test",
Expand Down

0 comments on commit 62f24e9

Please sign in to comment.