From bd769f9e3f8c274faa19cb2c888fc1dce70536e7 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Mon, 11 Nov 2024 09:20:18 +0200 Subject: [PATCH] Fix test for same dicts --- nc_password_client/nc_password_client.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/nc_password_client/nc_password_client.py b/nc_password_client/nc_password_client.py index 877247f..3b1af06 100755 --- a/nc_password_client/nc_password_client.py +++ b/nc_password_client/nc_password_client.py @@ -615,13 +615,22 @@ class NextcloudHandler: else: self.exit.status_code_error(r.status_code) + def is_same_key(self, key, dict1, dict2): + '''Test if two dictionaries have the same key with the same value''' + if key in dict1 and key in dict2: + if dict1[key] == dict2[key]: + return True + return False + def is_same_password(self, obj1, obj2): '''Test if two password objects are the same or similar''' if obj1 == obj2: return True - if (obj1['username'] == obj2['username'] and - obj1['password'] == obj2['password'] and - obj1['url'] == obj2['url']): + if ( + self.is_same_key('username', obj1, obj2) and + self.is_same_key('password', obj1, obj2) and + self.is_same_key('url', obj1, obj2) + ): return True return False