From a6d8be34e37d16a4364673a6597c27113e1af622 Mon Sep 17 00:00:00 2001 From: Thorge Petersen <petersen@rz.uni-kiel.de> Date: Mon, 5 Jun 2023 13:19:03 +0200 Subject: [PATCH] Some fixes for tpsh testcases --- ckanext/odsh/helpers_tpsh.py | 2 +- ckanext/odsh/logic/action.py | 10 ++++++---- ckanext/odsh/tests_tpsh/test_checksum.py | 8 ++++---- ckanext/odsh/tests_tpsh/test_helpers_tpsh.py | 3 +-- ckanext/odsh/tests_tpsh/test_password_validation.py | 4 ++-- ckanext/odsh/tests_tpsh/test_profiles.py | 2 +- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/ckanext/odsh/helpers_tpsh.py b/ckanext/odsh/helpers_tpsh.py index b30182d5..e543c5cc 100644 --- a/ckanext/odsh/helpers_tpsh.py +++ b/ckanext/odsh/helpers_tpsh.py @@ -67,7 +67,7 @@ def correct_missing_relationship(pkg_dict, pkg_relationships_from_model): relationship_for_package = { '__extras': { 'object_package_id': relationship_from_model.object_package_id, - #'revision_id': relationship_from_model.revision_id, + 'revision_id': relationship_from_model.revision_id, 'subject_package_id': relationship_from_model.subject_package_id, }, 'comment': relationship_from_model.subject_package_id, diff --git a/ckanext/odsh/logic/action.py b/ckanext/odsh/logic/action.py index 5dd9e29e..bf1333c3 100644 --- a/ckanext/odsh/logic/action.py +++ b/ckanext/odsh/logic/action.py @@ -90,10 +90,12 @@ def add_to_collection(collection_id, package_name): def check_password(password): - return (len(password) >= 8 and - any(c.islower() for c in password) and - any(c.isupper() for c in password) and - any((c.isalpha()==False) for c in password)) #Number or Special character + return ( + len(password) >= 8 and + any(c.islower() for c in password) and + any(c.isupper() for c in password) and + any(not c.isalpha() for c in password) + ) PASSWORD_ERROR_MESSAGE = {'security': ['Passwort muss mindestens acht Zeichen, einen Gross-, einen Kleinbuchstaben und entweder eine Zahl oder ein Sondernzeichen enthalten!']} diff --git a/ckanext/odsh/tests_tpsh/test_checksum.py b/ckanext/odsh/tests_tpsh/test_checksum.py index 06560b74..1d4dda63 100644 --- a/ckanext/odsh/tests_tpsh/test_checksum.py +++ b/ckanext/odsh/tests_tpsh/test_checksum.py @@ -24,19 +24,19 @@ class testHashException(unittest.TestCase): def test_with_correct_hash(self): resource = {'package_id':'Test_id', 'hash':self.hash_for_text} - with patch("builtins.open", mock_open(read_data=self.text)) as mock_file: + with patch("builtins.open", mock_open(read_data=self.text.encode('utf-8'))) as mock_file: with open('some/file') as f: assert _raise_validation_error_if_hash_values_differ(f, resource) == None def test_with_wrong_hash(self): resource = {'package_id':'Test_id', 'hash':'incorrect_hash'} - with patch("builtins.open", mock_open(read_data=self.text)) as mock_file: + with patch("builtins.open", mock_open(read_data=self.text.encode('utf-8'))) as mock_file: with open('some/file') as f: with pytest.raises(logic.ValidationError) as e: _raise_validation_error_if_hash_values_differ(f, resource) - exception_upload = e.exception.error_dict.get('upload') + exception_upload = e.value.error_dict.get('upload') assert exception_upload[0] == 'Berechneter Hash und mitgelieferter Hash sind unterschiedlich' - + def test_mock_file(self): with patch("builtins.open", mock_open(read_data=self.text)) as mock_file: with open('some/file') as f: diff --git a/ckanext/odsh/tests_tpsh/test_helpers_tpsh.py b/ckanext/odsh/tests_tpsh/test_helpers_tpsh.py index b3ffec48..dc554cef 100644 --- a/ckanext/odsh/tests_tpsh/test_helpers_tpsh.py +++ b/ckanext/odsh/tests_tpsh/test_helpers_tpsh.py @@ -156,8 +156,7 @@ class Test_correct_missing_relationship(unittest.TestCase): for key in ('object_package_id', 'revision_id', 'subject_package_id'): assert pkg_dict is not None - assert from_extras(pkg_dict, key) == from_extras(expected_pkg_dict, key - ) + assert from_extras(pkg_dict, key) == from_extras(expected_pkg_dict, key) class Test_get_language_of_package(unittest.TestCase): diff --git a/ckanext/odsh/tests_tpsh/test_password_validation.py b/ckanext/odsh/tests_tpsh/test_password_validation.py index fbd18760..b31811c9 100644 --- a/ckanext/odsh/tests_tpsh/test_password_validation.py +++ b/ckanext/odsh/tests_tpsh/test_password_validation.py @@ -17,7 +17,7 @@ class Test_PasswordValidation(unittest.TestCase): self.assert_password_valid('Passwort1 :) :P :D') def test_umlaute(self): - self.assert_password_valid('Pässword') + self.assert_password_valid('Pässword1') def test_no_uppercase(self): self.assert_password_invalid('passwort1') @@ -26,7 +26,7 @@ class Test_PasswordValidation(unittest.TestCase): self.assert_password_invalid('PASSWORT1') def test_no_letters(self): - self.assert_password_invalid('37459073245!!?===))/=$§äüöÄÜÖ') + self.assert_password_invalid('37459073245!!?===))/=$§') def test_only_letters(self): self.assert_password_invalid('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') diff --git a/ckanext/odsh/tests_tpsh/test_profiles.py b/ckanext/odsh/tests_tpsh/test_profiles.py index c76c324b..1ec5d80a 100644 --- a/ckanext/odsh/tests_tpsh/test_profiles.py +++ b/ckanext/odsh/tests_tpsh/test_profiles.py @@ -48,7 +48,7 @@ class TestODSHDCATdeProfileParseDatasetWithCollection(unittest.TestCase): def test_parse_type_does_not_add_collection_to_dataset_dict(self): dataset_dict = {} self.profile._parse_type(dataset_dict, self.dataset_ref_with_collection_member) - nt.assert_not_in('type', dataset_dict) + assert 'type' not in dataset_dict def test_belongs_to_collection_returns_true(self): dataset_dict = {} -- GitLab