From dcb8e1cd4bac7a3422b143b30a79b6b07978c12c Mon Sep 17 00:00:00 2001 From: Cyril Jouve Date: Fri, 28 Aug 2020 22:28:23 +0200 Subject: [PATCH 7/7] fix change_password tests --- .../browser/tests/test_change_password.py | 12 ++++++------ web/pgadmin/browser/tests/utils.py | 6 ++---- web/regression/runtests.py | 18 ++++++++++++++++++ web/regression/test_config.json.in | 2 +- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/web/pgadmin/browser/tests/test_change_password.py b/web/pgadmin/browser/tests/test_change_password.py index bbc81c685..1151643c7 100644 --- a/web/pgadmin/browser/tests/test_change_password.py +++ b/web/pgadmin/browser/tests/test_change_password.py @@ -38,12 +38,12 @@ class ChangePasswordTestCase(BaseTestGenerator): # This testcase validates if confirmation password is less than # minimum length ('TestCase for Validating New_Password_Less_Than_Min_Length', - dict(password=( - config_data['pgAdmin4_login_credentials'] - ['login_password']), - new_password=str(uuid.uuid4())[4:8], - new_password_confirm=str(uuid.uuid4())[4:8], - respdata='Password must be at least 6 characters')), + [dict(password=( + config_data['pgAdmin4_login_credentials']['login_password']), + new_password=new_password, + new_password_confirm=new_password, + respdata='Password must be at least 8 characters') + for new_password in [str(uuid.uuid4())[4:8]]][0]), # This testcase validates if both password fields are left blank ('TestCase for Validating Empty_New_Password', dict( diff --git a/web/pgadmin/browser/tests/utils.py b/web/pgadmin/browser/tests/utils.py index 458ed6117..33782b755 100644 --- a/web/pgadmin/browser/tests/utils.py +++ b/web/pgadmin/browser/tests/utils.py @@ -12,9 +12,7 @@ def change_password(self): response = self.tester.get( '/browser/change_password', follow_redirects=True ) - self.assertTrue( - 'Password Change' in response.data.decode('utf-8') - ) + self.assertIn('Password Change', response.data.decode('utf-8')) csrf_token = self.tester.fetch_csrf(response) @@ -28,4 +26,4 @@ def change_password(self): ), follow_redirects=True ) - self.assertTrue(self.respdata in response.data.decode('utf-8')) + self.assertIn(self.respdata, response.data.decode('utf-8')) diff --git a/web/regression/runtests.py b/web/regression/runtests.py index 94c39cdf5..331f402dd 100644 --- a/web/regression/runtests.py +++ b/web/regression/runtests.py @@ -127,6 +127,24 @@ app.test_client_class = TestClient test_client = app.test_client() test_client.setApp(app) + +class CaptureMail: + # A hack Mail service that simply captures what would be sent. + def __init__(self, app): + app.extensions["mail"] = self + self.sent = [] + self.ascii_attachments = [] + + def send(self, msg): + self.sent.append(msg.body) + + def pop(self): + if len(self.sent): + return self.sent.pop(0) + return None + +CaptureMail(app) + setattr(unittest.result.TestResult, "passed", []) unittest.runner.TextTestResult.addSuccess = test_utils.add_success diff --git a/web/regression/test_config.json.in b/web/regression/test_config.json.in index fc1953368..690f46c1c 100644 --- a/web/regression/test_config.json.in +++ b/web/regression/test_config.json.in @@ -9,7 +9,7 @@ "pgAdmin4_test_user_credentials": { "new_password": "NEWPASSWORD", "login_password": "PASSWORD", - "login_username": "USER@EXAMPLE.COM" + "login_username": "USER2@EXAMPLE.COM" }, "pgAdmin4_ldap_credentials": { "login_password": "PASSWORD", -- 2.28.0