diff --git a/ckanext/odsh/tests/test_search.py b/ckanext/odsh/tests/test_search.py index 3bcfc220c98d433af30f5171ccff6724fc587a3b..5989e591a7cfd55ac5e024d1470c4d2695c2a178 100644 --- a/ckanext/odsh/tests/test_search.py +++ b/ckanext/odsh/tests/test_search.py @@ -5,7 +5,6 @@ import ckan.tests.helpers as helpers from bs4 import BeautifulSoup from ckan import model from ckan.lib.mailer import create_reset_key -from nose.tools import assert_true, assert_false, assert_equal, assert_in from routes import url_for import ckan.plugins from .test_helpers import odsh_test diff --git a/ckanext/odsh/tests/test_selenium.py b/ckanext/odsh/tests/test_selenium.py index 5d397af1d9996328c53774fca0182541611f5a19..accaea79351b0a11d5ad4fed7c6b9ea69702d528 100644 --- a/ckanext/odsh/tests/test_selenium.py +++ b/ckanext/odsh/tests/test_selenium.py @@ -1,5 +1,4 @@ # coding: utf-8 -from nosedep import depends from ckanext.odsh.tests.ckan_selenium import SeleniumCkanApp import pdb diff --git a/ckanext/odsh/tests/test_upload.py b/ckanext/odsh/tests/test_upload.py index 662010b4e31bd8f34cd17eed147d9d5e81f73a93..206cb18dfd700c42d3463e9c2928efb4266247ec 100644 --- a/ckanext/odsh/tests/test_upload.py +++ b/ckanext/odsh/tests/test_upload.py @@ -6,7 +6,6 @@ import ckan.tests.helpers as helpers from ckan import model from .test_helpers import odsh_test from routes import url_for -from nose.tools import assert_true, assert_false, assert_equal, assert_in from ckanext.odsh.helpers import odsh_create_checksum webtest_submit = helpers.webtest_submit import pdb diff --git a/ckanext/odsh/tests/test_user.py b/ckanext/odsh/tests/test_user.py index 7382c19c71b84a4516ba35ac0cb802195823d40d..18d14ac6307d1e6dd789ab1c9e7110da7fd5c791 100644 --- a/ckanext/odsh/tests/test_user.py +++ b/ckanext/odsh/tests/test_user.py @@ -6,7 +6,6 @@ import ckan.tests.helpers as helpers from ckan import model from .test_helpers import odsh_test from routes import url_for -from nose.tools import assert_true, assert_false, assert_equal, assert_in class TestUser(helpers.FunctionalTestBase): @@ -87,4 +86,4 @@ class TestUser(helpers.FunctionalTestBase): logout_url = url_for(controller='user', action='logout') logout_response = app.get(logout_url, status=302) final_response = helpers.webtest_maybe_follow(logout_response) - return final_response \ No newline at end of file + return final_response diff --git a/ckanext/odsh/tests/test_validation.py b/ckanext/odsh/tests/test_validation.py index 01a9a779ac20d2ae74034ba4b73ae4cca4d16636..40e8ee32b2110b0f0cf32590a0a9da45db7a2f7e 100644 --- a/ckanext/odsh/tests/test_validation.py +++ b/ckanext/odsh/tests/test_validation.py @@ -1,10 +1,8 @@ from ckanext.odsh.validation import * import ckan.plugins.toolkit as toolkit -import pylons import ckan.model as modelMock import sys import json -from nose.tools import * from mock import MagicMock, Mock, patch diff --git a/ckanext/odsh/tests_tpsh/test_checksum.py b/ckanext/odsh/tests_tpsh/test_checksum.py index 6bff5d4fe469025e396c8b7e291e0d99106aad36..4a8aa30ec970c5772e96cb2f357303ed777b09b7 100644 --- a/ckanext/odsh/tests_tpsh/test_checksum.py +++ b/ckanext/odsh/tests_tpsh/test_checksum.py @@ -1,15 +1,16 @@ from mock import patch, mock_open -import nose.tools as nt from ckanext.odsh.lib.uploader import _raise_validation_error_if_hash_values_differ, calculate_hash import ckantoolkit as ct import ckan.logic as logic import hashlib +import unittest +import pytest import os path = os.path.abspath(__file__) dir_path = os.path.dirname(path) -class testHashException(object): +class testHashException(unittest.TestCase): text = 'Transparenz SH' # hash produced by following command in bash: # echo -n "Transparenz SH" | md5sum @@ -31,7 +32,7 @@ class testHashException(object): resource = {'package_id':'Test_id', 'hash':'incorrect_hash'} with patch("__builtin__.open", mock_open(read_data=self.text)) as mock_file: with open('some/file') as f: - with nt.assert_raises(logic.ValidationError) as e: + with pytest.raises(logic.ValidationError) as e: _raise_validation_error_if_hash_values_differ(f, resource) exception_upload = e.exception.error_dict.get('upload') assert exception_upload[0] == 'Berechneter Hash und mitgelieferter Hash sind unterschiedlich' @@ -40,11 +41,11 @@ class testHashException(object): with patch("__builtin__.open", mock_open(read_data=self.text)) as mock_file: with open('some/file') as f: file_content = f.read() - nt.assert_equal(file_content, self.text) + assert file_content == self.text def test_hash_of_empty_string(self): hash_empty_string = 'd41d8cd98f00b204e9800998ecf8427e' - nt.assert_equal(hash_empty_string, hashlib.md5('').hexdigest()) + assert hash_empty_string == hashlib.md5('').hexdigest() def test_pdf(self): # expected_hash_pdf produced by following command in bash: @@ -52,8 +53,8 @@ class testHashException(object): expected_hash_pdf = '66123edf64fabf1c073fc45478bf4a57' with open(dir_path + '/resources/test.pdf') as f: hash = calculate_hash(f) - nt.assert_equal(hash, expected_hash_pdf) + assert hash == expected_hash_pdf - \ No newline at end of file + diff --git a/ckanext/odsh/tests_tpsh/test_date_range.py b/ckanext/odsh/tests_tpsh/test_date_range.py index e9b7121db7b7285b13ae6690a763af9028c901cd..97251675277158f65637334e1545ec2260d37264 100644 --- a/ckanext/odsh/tests_tpsh/test_date_range.py +++ b/ckanext/odsh/tests_tpsh/test_date_range.py @@ -1,12 +1,11 @@ # -*- coding: utf-8 -*- -import nose.tools as nt - import datetime +import unittest from ckanext.odsh.pretty_daterange.date_range import DateRange -class TestDateRange(object): +class TestDateRange(unittest.TestCase): def test_is_one_year_returns_true(self): dr = DateRange( date_start = datetime.date(2000, 1, 1), @@ -58,11 +57,11 @@ class TestDateRange(object): def test_get_half_year_returns_1_for_first_half_of_year(self): half_year = DateRange.get_half_year(datetime.date(2000, 6, 30)) - nt.assert_equal(half_year, 1) + assert half_year == 1 def test_get_half_year_returns_2_for_second_half_of_year(self): half_year = DateRange.get_half_year(datetime.date(2000, 7, 1)) - nt.assert_equal(half_year, 2) + assert half_year == 2 def test_is_one_quarter_of_year_returns_true_for_first_quarter(self): dr = DateRange( @@ -94,19 +93,19 @@ class TestDateRange(object): def test_get_quarter_returns_1_for_first_quarter(self): quarter = DateRange.get_quarter(datetime.date(2000, 2, 1)) - nt.assert_equal(quarter, 1) + assert quarter == 1 def test_get_quarter_returns_2_for_second_quarter(self): quarter = DateRange.get_quarter(datetime.date(2000, 5, 1)) - nt.assert_equal(quarter, 2) + assert quarter == 2 def test_get_quarter_returns_3_for_third_quarter(self): quarter = DateRange.get_quarter(datetime.date(2000, 8, 1)) - nt.assert_equal(quarter, 3) + assert quarter == 3 def test_get_quarter_returns_4_for_fourth_quarter(self): quarter = DateRange.get_quarter(datetime.date(1981, 11, 21)) - nt.assert_equal(quarter, 4) + assert quarter == 4 def test_is_one_month_returns_true(self): dr = DateRange( @@ -155,4 +154,4 @@ class TestDateRange(object): date_start = datetime.date(2000, 1, 1), date_end = datetime.date(2000, 12, 31) ) - assert dr.is_range_of_multiple_years() == False \ No newline at end of file + assert dr.is_range_of_multiple_years() == False diff --git a/ckanext/odsh/tests_tpsh/test_date_range_formatter.py b/ckanext/odsh/tests_tpsh/test_date_range_formatter.py index 28f16ca33d94a8b31b4646db301ec71ed243dc91..b3e6845dd5e4699395478bd6f7bcf5b28e1268fc 100644 --- a/ckanext/odsh/tests_tpsh/test_date_range_formatter.py +++ b/ckanext/odsh/tests_tpsh/test_date_range_formatter.py @@ -1,16 +1,16 @@ # -*- coding: utf-8 -*- -import nose.tools as nt - import datetime +import unittest +import pytest from ckanext.odsh.pretty_daterange.date_range_formatter import DateRangeFormatter -class TestDateRangeFormatter(object): +class TestDateRangeFormatter(unittest.TestCase): def test_it_raises_value_error_if_date_end_before_date_start(self): date_start = datetime.date(2019,1,1) date_end = datetime.date(2018,1,1) - with nt.assert_raises(ValueError): + with pytest.raises(ValueError): drf = DateRangeFormatter(date_start, date_end) def test_it_stores_date_start_and_date_end(self): @@ -28,7 +28,7 @@ class TestDateRangeFormatter(object): def _assert_output_string_equals(self, date_start, date_end, expected_str): drf = DateRangeFormatter(date_start, date_end) formatted_date_range = drf.get_formatted_str() - nt.assert_equal(formatted_date_range, expected_str) + assert formatted_date_range == expected_str def test_it_returns_single_date_if_start_equals_end(self): self._assert_output_string_equals( @@ -142,4 +142,4 @@ class TestDateRangeFormatter(object): date_start = '', date_end = '', expected_str = '' - ) \ No newline at end of file + ) diff --git a/ckanext/odsh/tests_tpsh/test_helper_pkg_dict.py b/ckanext/odsh/tests_tpsh/test_helper_pkg_dict.py index 33cb9d049c72cb9a5cb6d39d9bb4553570b425d5..504966e83d62d42f8caa05914bdf3fe6cd4d660e 100644 --- a/ckanext/odsh/tests_tpsh/test_helper_pkg_dict.py +++ b/ckanext/odsh/tests_tpsh/test_helper_pkg_dict.py @@ -1,49 +1,49 @@ import datetime -import nose.tools as nt from mock import patch, call +import unittest from ckanext.odsh.helper_pkg_dict import HelperPgkDict import ckanext.odsh.helpers_tpsh as helpers_tpsh import ckanext.odsh.uri_store as uri_store -class TestHelperPkgDict(object): +class TestHelperPkgDict(unittest.TestCase): def test_is_collection_returns_true(self): dataset_dict = { 'type': 'collection', } h = HelperPgkDict(dataset_dict) is_collection = h.is_collection() - nt.assert_true(is_collection) + assert (is_collection) def test_is_collection_returns_false_if_no_type(self): dataset_dict = {} h = HelperPgkDict(dataset_dict) is_collection = h.is_collection() - nt.assert_false(is_collection) + assert not (is_collection) def test_is_collection_returns_false_if_type_dataset(self): dataset_dict = {'type': 'dataset'} h = HelperPgkDict(dataset_dict) is_collection = h.is_collection() - nt.assert_false(is_collection) + assert not (is_collection) def test_shall_be_part_of_collection_returns_true_if_flag_add_to_collection_is_True(self): dataset_dict = {'add_to_collection': True} h = HelperPgkDict(dataset_dict) shall_be_part_of_collection = h.shall_be_part_of_collection() - nt.assert_true(shall_be_part_of_collection) + assert (shall_be_part_of_collection) def test_shall_be_part_of_collection_returns_false_if_flag_add_to_collection_is_False(self): dataset_dict = {'add_to_collection': False} h = HelperPgkDict(dataset_dict) shall_be_part_of_collection = h.shall_be_part_of_collection() - nt.assert_false(shall_be_part_of_collection) + assert not (shall_be_part_of_collection) def test_shall_be_part_of_collection_returns_false_if_flag_add_to_collection_not_in_dict(self): dataset_dict = {} h = HelperPgkDict(dataset_dict) shall_be_part_of_collection = h.shall_be_part_of_collection() - nt.assert_false(shall_be_part_of_collection) + assert not (shall_be_part_of_collection) def test_update_relations_to_collection_members_leads_to_correct_call_of_add_to_collection(self): with patch.object(helpers_tpsh, 'add_pkg_to_collection') as patch_add_package_to_collection: @@ -108,7 +108,7 @@ class TestHelperPkgDict(object): } h = HelperPgkDict(dataset_dict_collection_member) collection = h.get_collection_uri() - nt.assert_equal(collection, 'http://transparenz.schleswig-holstein.de/5ffd27c528f7ab6936318da90d5cdd63') + assert collection == 'http://transparenz.schleswig-holstein.de/5ffd27c528f7ab6936318da90d5cdd63' def test_get_collection_uri_if_not_in_extras(self): dataset_dict_collection_member = { @@ -116,7 +116,7 @@ class TestHelperPkgDict(object): } h = HelperPgkDict(dataset_dict_collection_member) collection = h.get_collection_uri() - nt.assert_equal(collection, None) + assert collection == None def test_get_uris_collection_members(self): collection_members_as_string = '["http://transparenz.schleswig-holstein.de/cd606b042789723a2b6d61cb31c46c39", "http://transparenz.schleswig-holstein.de/3a0d0674120fbf06b5cb8737124e3fd0", "http://transparenz.schleswig-holstein.de/b5cd3f303f594ecde96e1017e953b688", "http://transparenz.schleswig-holstein.de/9f9ae60bb0d8985e10e9ab8aa6a7ca34", "http://transparenz.schleswig-holstein.de/ff612d0f165d46f3091f58e1ef56a2ec"]' @@ -127,13 +127,13 @@ class TestHelperPkgDict(object): } h = HelperPgkDict(dataset_dict) uris = h.get_uris_collection_members() - nt.assert_equal(uris[0], 'http://transparenz.schleswig-holstein.de/cd606b042789723a2b6d61cb31c46c39') - nt.assert_equal(uris[1], 'http://transparenz.schleswig-holstein.de/3a0d0674120fbf06b5cb8737124e3fd0') - nt.assert_equal(uris[-1], 'http://transparenz.schleswig-holstein.de/ff612d0f165d46f3091f58e1ef56a2ec') + assert uris[0] == 'http://transparenz.schleswig-holstein.de/cd606b042789723a2b6d61cb31c46c39' + assert uris[1] == 'http://transparenz.schleswig-holstein.de/3a0d0674120fbf06b5cb8737124e3fd0' + assert uris[-1] == 'http://transparenz.schleswig-holstein.de/ff612d0f165d46f3091f58e1ef56a2ec' -class Test_get_date_start_and_end_from_pkg_dict(object): +class Test_get_date_start_and_end_from_pkg_dict(unittest.TestCase): def setUp(self): self.dict_with_start_and_end_date = { @@ -172,29 +172,29 @@ class Test_get_date_start_and_end_from_pkg_dict(object): def test_it_returns_correct_start_date(self): h = HelperPgkDict(self.dict_with_start_and_end_date) date_start, _ = h._get_date_start_and_end_from_pkg_dict() - nt.assert_equal(date_start, self.date_start_expected) + assert date_start == self.date_start_expected def test_it_returns_correct_end_date(self): h = HelperPgkDict(self.dict_with_start_and_end_date) _, date_end = h._get_date_start_and_end_from_pkg_dict() - nt.assert_equal(date_end, self.date_end_expected) + assert date_end == self.date_end_expected def test_it_return_none_if_date_start_empty(self): h = HelperPgkDict(self.dict_with_empty_start_date) date_start, _ = h._get_date_start_and_end_from_pkg_dict() - nt.assert_equal(date_start, None) + assert date_start == None def test_it_return_none_if_date_end_empty(self): h = HelperPgkDict(self.dict_with_empty_end_date) _, date_end = h._get_date_start_and_end_from_pkg_dict() - nt.assert_equal(date_end, None) + assert date_end == None def test_it_returns_date_start_if_date_end_empty(self): h = HelperPgkDict(self.dict_with_empty_end_date) date_start, _ = h._get_date_start_and_end_from_pkg_dict() - nt.assert_equal(date_start, self.date_start_expected) + assert date_start == self.date_start_expected def test_it_returns_date_end_if_date_start_empty(self): h = HelperPgkDict(self.dict_with_empty_start_date) _, date_end = h._get_date_start_and_end_from_pkg_dict() - nt.assert_equal(date_end, self.date_end_expected) \ No newline at end of file + assert date_end == self.date_end_expected diff --git a/ckanext/odsh/tests_tpsh/test_helpers_tpsh.py b/ckanext/odsh/tests_tpsh/test_helpers_tpsh.py index 1615d88d10a3808c1d9ad613ab740e0e1db8384c..b3ffec4888af9c393e9a4af329b67757607799c3 100644 --- a/ckanext/odsh/tests_tpsh/test_helpers_tpsh.py +++ b/ckanext/odsh/tests_tpsh/test_helpers_tpsh.py @@ -3,11 +3,11 @@ import os from collections import namedtuple, OrderedDict import datetime -import nose.tools as nt from mock import patch from ckan.common import config import ckan.logic.action.create as create from ckanext.odsh.tests_tpsh.resources import org_dicts +import unittest from ckanext.odsh.helpers_tpsh import ( @@ -23,30 +23,25 @@ from ckanext.odsh.helpers_tpsh import ( ) -class TestMatchDctTypeToCkanType(object): +class TestMatchDctTypeToCkanType(unittest.TestCase): def test_it_returns_collection(self): dct_type = 'http://dcat-ap.de/def/datasetTypes/collection' ckan_type = map_dct_type_to_ckan_type(dct_type) expected_ckan_type = 'collection' - nt.assert_equal(ckan_type, expected_ckan_type) + assert ckan_type == expected_ckan_type def test_it_returns_none_for_unknown_type(self): - nt.assert_equal( - map_dct_type_to_ckan_type('some unknown type'), - None - ) + assert map_dct_type_to_ckan_type('some unknown type') == None -class TestMatchCkanTypeToDctType(object): +class TestMatchCkanTypeToDctType(unittest.TestCase): def test_it_returns_url_for_collection(self): ckan_type = 'collection' dct_type = map_ckan_type_to_dct_type(ckan_type) expected_dct_type = 'http://dcat-ap.de/def/datasetTypes/collection' - nt.assert_equal( - dct_type, expected_dct_type - ) + assert dct_type == expected_dct_type FakePackageRelationship = namedtuple( @@ -60,7 +55,7 @@ FakePackageRelationship = namedtuple( ''' ) -class Test_correct_missing_relationship(object): +class Test_correct_missing_relationship(unittest.TestCase): def setUp(self): self.relationships_from_model = [ FakePackageRelationship( @@ -79,7 +74,7 @@ class Test_correct_missing_relationship(object): correct_missing_relationship( pkg_dict, relationships_from_model ) - nt.assert_equal(pkg_dict, original_pkg_dict) + assert pkg_dict == original_pkg_dict def test_it_does_not_modify_pkg_dict_if_relationships_already_in_dict(self): original_pkg_dict = { @@ -101,7 +96,7 @@ class Test_correct_missing_relationship(object): correct_missing_relationship( pkg_dict, self.relationships_from_model ) - nt.assert_equal(pkg_dict, original_pkg_dict) + assert pkg_dict == original_pkg_dict def test_it_does_not_modify_pkg_dict_if_type_collection(self): original_pkg_dict = { @@ -123,7 +118,7 @@ class Test_correct_missing_relationship(object): correct_missing_relationship( pkg_dict, self.relationships_from_model ) - nt.assert_equal(pkg_dict, original_pkg_dict) + assert pkg_dict == original_pkg_dict def test_it_adds_relationships_if_not_already_in_dict(self): pkg_dict = { @@ -153,25 +148,19 @@ class Test_correct_missing_relationship(object): from_extras = lambda d, key: d.get('relationships_as_subject')[0].get('__extras').get(key) # assert - nt.assert_equal(pkg_dict.get('type'), 'dataset') + assert pkg_dict.get('type') == 'dataset' for key in ('id', 'type'): - nt.assert_true(from_relationships(pkg_dict, key) is not None) - nt.assert_equal( - from_relationships(pkg_dict, key), - from_relationships(expected_pkg_dict, key) - ) + assert from_relationships(pkg_dict, key) is not None + assert from_relationships(pkg_dict, key) == from_relationships(expected_pkg_dict, key) for key in ('object_package_id', 'revision_id', 'subject_package_id'): - nt.assert_true( - pkg_dict is not None) - nt.assert_equal( - from_extras(pkg_dict, key), - from_extras(expected_pkg_dict, key) + assert pkg_dict is not None + assert from_extras(pkg_dict, key) == from_extras(expected_pkg_dict, key ) -class Test_get_language_of_package(object): +class Test_get_language_of_package(unittest.TestCase): def setUp(self): config.update({'ckanext.odsh.language_mapping': '/usr/lib/ckan/default/src/ckanext-odsh/language_mapping.json'}) @@ -185,7 +174,7 @@ class Test_get_language_of_package(object): {'key': 'language', 'value': 'http://publications.europa.eu/resource/authority/language/ENG'}, ] } - nt.assert_equal(get_language_of_package(test_package),'Englisch') + assert get_language_of_package(test_package) == 'Englisch' def test_it_returns_None_if_language_id_not_in_dict(self): test_package = { @@ -194,29 +183,29 @@ class Test_get_language_of_package(object): {'key': 'language', 'value': 'tlhIngan Hol'}, ] } - nt.assert_equal(get_language_of_package(test_package), None) + assert get_language_of_package(test_package) == None def test_it_returns_None_if_language_not_in_pkg_dict(self): test_package = {} - nt.assert_equal(get_language_of_package(test_package), None) + assert get_language_of_package(test_package) == None -class Test_get_address_org(object): +class Test_get_address_org(unittest.TestCase): def test_it_returns_address_for_org_with_address(self): organization = org_dicts.organization_with_address address = get_address_org(organization) - nt.assert_equal(address.get('location'), 'Müllerdorf') - nt.assert_equal(address.get('person'), 'Michael Müller') - nt.assert_equal(address.get('mail'), 'mueller@mueller.de') - nt.assert_equal(address.get('street'), 'Müllergasse 10') - nt.assert_equal(address.get('telephone'), '040 123456') - nt.assert_equal(address.get('web'), 'http://mueller.de') + assert address.get('location') == 'Müllerdorf' + assert address.get('person') == 'Michael Müller' + assert address.get('mail') == 'mueller@mueller.de' + assert address.get('street') == 'Müllergasse 10' + assert address.get('telephone') == '040 123456' + assert address.get('web') == 'http://mueller.de' def test_it_returns_empty_dict_if_called_via_organization_new(self): organization = dict() address = get_address_org(organization) assert type(address) is dict - nt.assert_equal(len(address), 0) + assert len(address) == 0 def _add_subject_mapping_file_to_config(): @@ -224,7 +213,7 @@ def _add_subject_mapping_file_to_config(): path_to_subject_mapping_file = path_current_file + '/resources/subject_mapping_for_tests.json' config.update({'ckanext.odsh.subject_mapping': path_to_subject_mapping_file}) -class Test_load_json_to_ordered_dict(object): +class Test_load_json_to_ordered_dict(unittest.TestCase): def setUp(self): json_str = '{"A": 1, "B": 2, "D": 3, "C":4, "E": 0}' self.result = load_json_to_ordered_dict(json_str) @@ -233,17 +222,17 @@ class Test_load_json_to_ordered_dict(object): pass def test_it_returns_ordered_dict(self): - nt.assert_is(type(self.result), OrderedDict) + assert type(self.result) is OrderedDict def test_it_preserves_order_of_keys(self): keys = list(self.result.keys()) - nt.assert_equal(keys, ['A', 'B', 'D', 'C', 'E']) + assert keys == ['A', 'B', 'D', 'C', 'E'] def test_it_preserves_order_of_values(self): values = list(self.result.values()) - nt.assert_equal(values, [1, 2, 3, 4, 0]) + assert values == [1, 2, 3, 4, 0] -class Test_load_subject_mapping(object): +class Test_load_subject_mapping(unittest.TestCase): def setUp(self): _add_subject_mapping_file_to_config() self.SUBJECT_MAPPING = load_subject_mapping() @@ -252,16 +241,16 @@ class Test_load_subject_mapping(object): config.clear() def test_it_returns_an_ordered_dictionary(self): - nt.assert_is(type(self.SUBJECT_MAPPING), OrderedDict) + assert type(self.SUBJECT_MAPPING) is OrderedDict def test_it_preserves_order_of_json_file(self): keys = list(self.SUBJECT_MAPPING.keys()) - nt.assert_equal(keys[0], 'http://transparenz.schleswig-holstein.de/informationsgegenstand#Verwaltungsvorschrift') - nt.assert_equal(keys[1], 'http://transparenz.schleswig-holstein.de/informationsgegenstand#Organisationsplan') - nt.assert_equal(keys[2], 'http://transparenz.schleswig-holstein.de/informationsgegenstand#Geschaeftsverteilungsplan') - nt.assert_equal(keys[3], 'http://transparenz.schleswig-holstein.de/informationsgegenstand#Aktenplan') + assert keys[0] == 'http://transparenz.schleswig-holstein.de/informationsgegenstand#Verwaltungsvorschrift' + assert keys[1] == 'http://transparenz.schleswig-holstein.de/informationsgegenstand#Organisationsplan' + assert keys[2] == 'http://transparenz.schleswig-holstein.de/informationsgegenstand#Geschaeftsverteilungsplan' + assert keys[3] == 'http://transparenz.schleswig-holstein.de/informationsgegenstand#Aktenplan' -class Test_get_subject_for_selection(object): +class Test_get_subject_for_selection(unittest.TestCase): def setUp(self): _add_subject_mapping_file_to_config() self.result = get_subject_for_selection() @@ -273,9 +262,9 @@ class Test_get_subject_for_selection(object): assert type(self.result) is list def test_first_element_is_empty(self): - nt.assert_equal(self.result[0], {'key': 'empty', 'value': ' '}) + assert self.result[0] == {'key': 'empty', 'value': ' '} def test_it_contains_more_than_one_element(self): - nt.assert_greater(len(self.result), 1) + assert len(self.result) > 1 diff --git a/ckanext/odsh/tests_tpsh/test_icap.py b/ckanext/odsh/tests_tpsh/test_icap.py deleted file mode 100644 index f97bbc74249eadeeb2e36ebdf07aae53191d0d82..0000000000000000000000000000000000000000 --- a/ckanext/odsh/tests_tpsh/test_icap.py +++ /dev/null @@ -1,67 +0,0 @@ -import nose.tools as nt -from testfixtures import log_capture - -from ckan.common import config -from ckanext.odsh.lib.odsh_icap_client import ODSHICAPRequest, _read_from_config - -class Test_ODSHICAPRequest(object): - def setUp(self): - config.update({ - 'ckanext.odsh.icap.host': 'some_host', - 'ckanext.odsh.icap.port': '123', - 'ckanext.odsh.icap.clientip': 'some_ip', - }) - - def tearDown(self): - config.clear() - - def test_it_initializes_with_parameters_set_in_config(self): - request = ODSHICAPRequest('some_filename', 'some_filebuffer') - nt.assert_equal(request.HOST, 'some_host') - nt.assert_equal(request.PORT, 123) - nt.assert_equal(request.CLIENTIP, 'some_ip') - - @log_capture() - def test_it_logs_missing_parameter_host_to_error_log(self, capture): - del config['ckanext.odsh.icap.host'] - ODSHICAPRequest('some_filename', 'some_filebuffer') - capture.check(( - 'ckanext.odsh.lib.odsh_icap_client', - 'ERROR', - "'key ckanext.odsh.icap.host is not defined in ckan config file.'" - )) - - @log_capture() - def test_it_logs_missing_parameter_port_to_error_log(self, capture): - del config['ckanext.odsh.icap.port'] - ODSHICAPRequest('some_filename', 'some_filebuffer') - capture.check(( - 'ckanext.odsh.lib.odsh_icap_client', - 'ERROR', - "'key ckanext.odsh.icap.port is not defined in ckan config file.'" - )) - - @log_capture() - def test_it_logs_missing_parameter_clientip_to_error_log(self, capture): - del config['ckanext.odsh.icap.clientip'] - ODSHICAPRequest('some_filename', 'some_filebuffer') - capture.check(( - 'ckanext.odsh.lib.odsh_icap_client', - 'ERROR', - "'key ckanext.odsh.icap.clientip is not defined in ckan config file.'" - )) - - def test_read_from_config_raises_KeyError_if_host_not_defined_in_config(self): - del config['ckanext.odsh.icap.host'] - with nt.assert_raises(KeyError): - _read_from_config('ckanext.odsh.icap.host') - - def test_read_from_config_raises_KeyError_if_port_not_defined_in_config(self): - del config['ckanext.odsh.icap.port'] - with nt.assert_raises(KeyError): - _read_from_config('ckanext.odsh.icap.port') - - def test_read_from_config_raises_KeyError_if_clientip_not_defined_in_config(self): - del config['ckanext.odsh.icap.clientip'] - with nt.assert_raises(KeyError): - _read_from_config('ckanext.odsh.icap.clientip') diff --git a/ckanext/odsh/tests_tpsh/test_matomo.py b/ckanext/odsh/tests_tpsh/test_matomo.py deleted file mode 100644 index 0c20d6853e746ad866e7c30f25db91a2d6e7c5ab..0000000000000000000000000000000000000000 --- a/ckanext/odsh/tests_tpsh/test_matomo.py +++ /dev/null @@ -1,53 +0,0 @@ -import nose.tools as nt -from mock import patch -from ckan.common import config - -from ckanext.odsh.plugin import OdshPlugin -import ckanext.odsh.helpers_tpsh as helpers_tpsh -import ckanext.odsh.matomo as matomo - -class Test_helper_odsh_use_matomo(object): - def setUp(self): - self.plugin = OdshPlugin() - - def test_use_matomo_returns_False_if_not_in_config(self): - use_matomo = self.plugin.get_helpers()['odsh_use_matomo']() - nt.assert_false(use_matomo) - - def test_use_matomo_returns_False_if_set_False_in_config(self): - config.update({'ckanext.odsh.use_matomo': 'False'}) - use_matomo = self.plugin.get_helpers()['odsh_use_matomo']() - nt.assert_false(use_matomo) - config.clear() - - def test_use_matomo_returns_True_if_set_True_in_config(self): - config.update({'ckanext.odsh.use_matomo': 'True'}) - use_matomo = self.plugin.get_helpers()['odsh_use_matomo']() - nt.assert_true(use_matomo) - config.clear() - - -class Test_decorator_do_if_use_matomo(object): - def test_it_does_not_if_use_matomo_set_False_in_config(self): - - @matomo.do_if_use_matomo - def set_to_true(_): - return True - - config.update({'ckanext.odsh.use_matomo': 'False'}) - did_run = False - did_run = set_to_true(did_run) - nt.assert_false(did_run) - config.clear() - - def test_it_does_if_use_matomo_set_True_in_config(self): - - @matomo.do_if_use_matomo - def set_to_true(_): - return True - - config.update({'ckanext.odsh.use_matomo': 'True'}) - did_run = False - did_run = set_to_true(did_run) - nt.assert_true(did_run) - config.clear() diff --git a/ckanext/odsh/tests_tpsh/test_odsh_helpers.py b/ckanext/odsh/tests_tpsh/test_odsh_helpers.py index 9adfc5e6da311f1a44ea941c1cd9204a6be0acfe..0f5a788a5434753afdc702ac95070db107223071 100644 --- a/ckanext/odsh/tests_tpsh/test_odsh_helpers.py +++ b/ckanext/odsh/tests_tpsh/test_odsh_helpers.py @@ -1,6 +1,6 @@ import datetime -import nose.tools as nt from mock import patch +import unittest import ckan.lib.helpers as helpers @@ -9,128 +9,7 @@ from ckanext.odsh.helpers import is_within_last_month import ckanext.odsh.collection.helpers as helpers_collection import ckan.model as model - -class Test_tpsh_get_successor_and_predecessor_dataset(object): - - def setUp(self): - - # construct datasets that shall be in following order: - # name date - # public2 2014-07-01 - # public3 2014-07-01 - # public4 2014-07-02 - # public1 2014-07-03 - - self.names_collection_members = [ - 'public3', 'public2', 'public1', 'public4', - 'private3', 'private2', 'private1'] - self.dates_collection_members = [ - '2014-07-01T00:00:00', #public3 - '2014-07-01T00:00:00', #public2 - '2014-07-03T00:00:00', #public1 - '2014-07-02T00:00:00', #public4 - '2014-07-05T00:00:00', #private3 - '2014-07-06T00:00:00', #private2 - '2014-07-07T00:00:00', #private1 - ] - self.pkg_dicts_collection_members = [ - { - 'name': name, - 'extras': {'issued': date} - } - for (name, date) in zip(self.names_collection_members, self.dates_collection_members) - ] - - def fake_access_checker(access_type, pkg_dict): - pkg_name = pkg_dict.get('name') - if 'public' in pkg_name: - return True - return False - - def fake_get_package_dict(name): - package_list = [pkg_dict for pkg_dict in self.pkg_dicts_collection_members if pkg_dict.get('name')==name] - return package_list[0] - - self.patch_get_datasets_belonging_to_collection_by_dataset = patch.object( - helpers_collection, - 'get_all_datasets_belonging_to_collection_by_dataset', - return_value = self.names_collection_members) - self.patch_get_datasets_belonging_to_collection_by_dataset.start() - - self.patch_check_access = patch.object( - helpers, - 'check_access', - new=fake_access_checker, - ) - self.patch_check_access.start() - - self.patch_get_package_dict = patch.object( - helpers_collection, - 'get_package_dict', - new=fake_get_package_dict, - ) - self.patch_get_package_dict.start() - - def tearDown(self): - self.patch_get_datasets_belonging_to_collection_by_dataset.stop() - self.patch_check_access.stop() - self.patch_get_package_dict.stop() - - def test_patch_get_datasets_belonging_to_collection_by_dataset(self): - return_value = helpers_collection.get_all_datasets_belonging_to_collection_by_dataset() - nt.assert_equal(return_value, self.names_collection_members) - - def test_patch_access_checker_returns_True(self): - pkg_dict = {'name': 'public1'} - has_access = helpers.check_access('package_show', pkg_dict) - nt.assert_true(has_access) - - def test_patch_access_checker_returns_False(self): - pkg_dict = {'name': 'private1'} - has_access = helpers.check_access('package_show', pkg_dict) - nt.assert_false(has_access) - - def test_patch_package_get(self): - pkg_dict = helpers_collection.get_package_dict('public1') - nt.assert_equal(pkg_dict.get('name'), 'public1') - - def test_it_returns_correct_for_public2(self): - pkg_dict = {'name': 'public2'} - successor, predecessor = helpers_collection.get_successor_and_predecessor_dataset(pkg_dict) - nt.assert_equal(successor, 'public3') - nt.assert_equal(predecessor, None) - - def test_it_returns_correct_for_public3(self): - pkg_dict = {'name': 'public3'} - successor, predecessor = helpers_collection.get_successor_and_predecessor_dataset(pkg_dict) - nt.assert_equal(successor, 'public4') - nt.assert_equal(predecessor, 'public2') - - def test_it_returns_correct_for_public4(self): - pkg_dict = {'name': 'public4'} - successor, predecessor = helpers_collection.get_successor_and_predecessor_dataset(pkg_dict) - nt.assert_equal(successor, 'public1') - nt.assert_equal(predecessor, 'public3') - - def test_it_returns_correct_for_public1(self): - pkg_dict = {'name': 'public1'} - successor, predecessor = helpers_collection.get_successor_and_predecessor_dataset(pkg_dict) - nt.assert_equal(successor, None) - nt.assert_equal(predecessor, 'public4') - - def test_it_returns_None_if_no_siblings(self): - with patch.object( - helpers_collection, - 'get_all_datasets_belonging_to_collection_by_dataset', - return_value = list() - ): - pkg_dict = {'name': 'some_name'} - successor, predecessor = helpers_collection.get_successor_and_predecessor_dataset(pkg_dict) - nt.assert_equal(successor, None) - nt.assert_equal(predecessor, None) - - -class Test_is_within_last_month(object): +class Test_is_within_last_month(unittest.TestCase): def test_it_returns_true_for_simple_query(self): date = datetime.date(2019, 4, 15) date_ref = datetime.date(2019, 4, 29) @@ -158,4 +37,4 @@ class Test_is_within_last_month(object): def test_it_return_false_for_date_in_different_months(self): date = datetime.date(2018, 6, 8) date_ref = datetime.date(2018, 7, 10) - assert is_within_last_month(date, date_ref)==False \ No newline at end of file + assert is_within_last_month(date, date_ref)==False diff --git a/ckanext/odsh/tests_tpsh/test_password_validation.py b/ckanext/odsh/tests_tpsh/test_password_validation.py index c999b3974784df07d2da8c3d40ac1d9e11e8026d..fbd187605da5853be744547826269505b82e06e3 100644 --- a/ckanext/odsh/tests_tpsh/test_password_validation.py +++ b/ckanext/odsh/tests_tpsh/test_password_validation.py @@ -1,9 +1,9 @@ # encoding: utf-8 -import nose.tools as nt from ckanext.odsh.logic.action import check_password +import unittest -class Test_PasswordValidation(object): +class Test_PasswordValidation(unittest.TestCase): @staticmethod def assert_password_invalid(password): @@ -32,4 +32,4 @@ class Test_PasswordValidation(object): self.assert_password_invalid('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') def test_to_short(self): - self.assert_password_invalid('Pw123') \ No newline at end of file + self.assert_password_invalid('Pw123') diff --git a/ckanext/odsh/tests_tpsh/test_plugin.py b/ckanext/odsh/tests_tpsh/test_plugin.py index 627518a2a359f3a8a97563bb95edbc89b1f56418..140bd8ae92afc4a21e9235038898f13a3da489b8 100644 --- a/ckanext/odsh/tests_tpsh/test_plugin.py +++ b/ckanext/odsh/tests_tpsh/test_plugin.py @@ -1,8 +1,9 @@ import datetime import ckanext.odsh.plugin as plugin +import unittest -class TestMethodBeforeView(object): +class TestMethodBeforeView(unittest.TestCase): date_time_format = '%Y-%m-%dT%H:%M:%S' def test_before_view_adds_false_for_old_dataset(self): @@ -49,4 +50,4 @@ class TestMethodBeforeView(object): 'some_other_key': 'some_other_value', } ) - assert dict_for_template['some_other_key']=='some_other_value' \ No newline at end of file + assert dict_for_template['some_other_key']=='some_other_value' diff --git a/ckanext/odsh/tests_tpsh/test_profiles.py b/ckanext/odsh/tests_tpsh/test_profiles.py index f26405a354e0a58d23198180a477cae5c7a5cda7..c76c324b5d49ad664124e92f874500119fda7c17 100644 --- a/ckanext/odsh/tests_tpsh/test_profiles.py +++ b/ckanext/odsh/tests_tpsh/test_profiles.py @@ -1,5 +1,5 @@ -import nose.tools as nt import rdflib +import unittest from rdflib import Graph from mock import patch @@ -11,7 +11,7 @@ import ckanext.odsh.helper_pkg_dict as helper_pkg_dict DCT = rdflib.namespace.Namespace("http://purl.org/dc/terms/") -class TestODSHDCATdeProfileParseDatasetWithCollection(object): +class TestODSHDCATdeProfileParseDatasetWithCollection(unittest.TestCase): ''' Tests for ODSHDCATdeProfile.parse_dataset with an rdf file containing a collection @@ -33,17 +33,17 @@ class TestODSHDCATdeProfileParseDatasetWithCollection(object): def test_parse_dataset_adds_type_collection_to_dataset_dict(self): dataset_dict = {} self.profile.parse_dataset(dataset_dict, self.dataset_ref_with_collection) - nt.assert_equal('collection', dataset_dict['type']) + assert 'collection' == dataset_dict['type'] def test_parse_dataset_adds_flag_for_collection_member(self): dataset_dict = {} self.profile.parse_dataset(dataset_dict, self.dataset_ref_with_collection_member) - nt.assert_equal(True, dataset_dict.get('add_to_collection')) + assert True == dataset_dict.get('add_to_collection') def test_parse_type_adds_type_collection_to_dataset_dict(self): dataset_dict = {} self.profile._parse_type(dataset_dict, self.dataset_ref_with_collection) - nt.assert_equal('collection', dataset_dict['type']) + assert 'collection' == dataset_dict['type'] def test_parse_type_does_not_add_collection_to_dataset_dict(self): dataset_dict = {} @@ -58,10 +58,10 @@ class TestODSHDCATdeProfileParseDatasetWithCollection(object): dataset_dict = {} belongs_to_collection = self.profile._belongs_to_collection( dataset_dict, self.dataset_ref_with_member_not_in_collection) - nt.assert_false(belongs_to_collection) + assert not belongs_to_collection -class TestODSHDCATdeProfileParseDatasetWithSubject(object): +class TestODSHDCATdeProfileParseDatasetWithSubject(unittest.TestCase): ''' Tests for ODSHDCATdeProfile.parse_dataset with an rdf file containing datasets with subjects @@ -77,15 +77,15 @@ class TestODSHDCATdeProfileParseDatasetWithSubject(object): def test_parse_subject_returns_subject(self): dataset_dict = {} self.profile._parse_subject(dataset_dict, self.dataset_ref_with_subject) - nt.assert_equal('http://d-nb.info/gnd/4128022-2', dataset_dict['subject']) + assert 'http://d-nb.info/gnd/4128022-2' == dataset_dict['subject'] def test_parse_dataset_returns_subject(self): dataset_dict = {} self.profile.parse_dataset(dataset_dict, self.dataset_ref_with_subject) - nt.assert_equal('http://d-nb.info/gnd/4128022-2', dataset_dict['subject']) + assert 'http://d-nb.info/gnd/4128022-2' == dataset_dict['subject'] -class TestODSHDCATdeProfileGraphFromDataset(object): +class TestODSHDCATdeProfileGraphFromDataset(unittest.TestCase): ''' Tests for ODSHDCATdeProfile.graph_from_dataset ''' @@ -98,7 +98,7 @@ class TestODSHDCATdeProfileGraphFromDataset(object): self.profile.graph_from_dataset(dataset_dict, dataset_ref) graph_serialized = self.profile.g.serialize() print((self.profile.g.serialize(format='pretty-xml'))) - nt.assert_in(expected_node, graph_serialized) + assert expected_node in graph_serialized patch_collection_member = patch.object( @@ -181,4 +181,4 @@ class TestODSHDCATdeProfileGraphFromDataset(object): self.profile._remove_predefined_collection_members() graph_serialized = self.profile.g.serialize() for ref in refs: - nt.assert_not_in(ref, graph_serialized) \ No newline at end of file + assert ref in graph_serialized diff --git a/ckanext/odsh/tests_tpsh/test_search.py b/ckanext/odsh/tests_tpsh/test_search.py index e3b0dd6ecd7bb2df39de5c6cd0cfc6c42c7122c8..a8f216163cd612d72c24319cca7e32ad9e3362e4 100644 --- a/ckanext/odsh/tests_tpsh/test_search.py +++ b/ckanext/odsh/tests_tpsh/test_search.py @@ -1,7 +1,7 @@ -import nose.tools as nt import ckanext.odsh.search as search +import unittest -class Test_before_search(object): +class Test_before_search(unittest.TestCase): def setUp(self): self.search_params_before_test = { 'extras': {}, @@ -23,7 +23,7 @@ class Test_before_search(object): search.before_search(search_params) # assert search_params_expected = self.search_params_with_facet_mincount.copy() - nt.assert_equal(search_params, search_params_expected) + assert search_params == search_params_expected def test_it_adds_fq_if_empty_range(self): # arange @@ -43,7 +43,7 @@ class Test_before_search(object): # act search.before_search(search_params) # assert - nt.assert_equal(search_params, search_params_expected) + assert search_params == search_params_expected def test_it_solely_adds_facet_mincount_to_dict_if_wrong_date_format_in_extras(self): # arange @@ -55,7 +55,7 @@ class Test_before_search(object): # act search.before_search(search_params) # assert - nt.assert_equal(search_params, search_params_expected) + assert search_params == search_params_expected def test_it_adds_fq_if_enclosing_range(self): # arange @@ -79,7 +79,7 @@ class Test_before_search(object): # act search.before_search(search_params) # assert - nt.assert_equal(search_params, search_params_expected) + assert search_params == search_params_expected def test_it_adds_fq_if_start_only(self): # arange @@ -100,7 +100,7 @@ class Test_before_search(object): # act search.before_search(search_params) # assert - nt.assert_equal(search_params, search_params_expected) + assert search_params == search_params_expected def test_it_adds_fq_if_end_only(self): # arange @@ -122,7 +122,7 @@ class Test_before_search(object): # act search.before_search(search_params) # assert - nt.assert_equal(search_params, search_params_expected) + assert search_params == search_params_expected def test_it_returns_search_params(self): # arange @@ -130,4 +130,4 @@ class Test_before_search(object): # act return_value = search.before_search(search_params) # assert - nt.assert_equal(return_value, search_params) + assert search_params == return_value diff --git a/ckanext/odsh/tests_tpsh/test_uri_store.py b/ckanext/odsh/tests_tpsh/test_uri_store.py index 0bdcac3331f8adf53c01d1e899ceea3bcc886880..404ea7a8fa890bb87b72981f6499ebcab6c8a9f2 100644 --- a/ckanext/odsh/tests_tpsh/test_uri_store.py +++ b/ckanext/odsh/tests_tpsh/test_uri_store.py @@ -1,7 +1,7 @@ -import nose.tools as nt from ckanext.odsh.uri_store import add_uri, get_id_from_uri, _set_uri_to_id, _get_uri_to_id +import unittest -class Test_uri_store(object): +class Test_uri_store(unittest.TestCase): def test_add_uri_adds_values_to_dict(self): _set_uri_to_id({'http://some_uri': 'some_id'}) dataset_dict = { @@ -11,28 +11,22 @@ class Test_uri_store(object): ] } add_uri(dataset_dict) - nt.assert_equal( - _get_uri_to_id().get('http://some_uri'), - 'some_id' - ) - nt.assert_equal( - _get_uri_to_id().get('http://some_new_uri'), - 'some_new_id' - ) + assert _get_uri_to_id().get('http://some_uri') == 'some_id' + assert _get_uri_to_id().get('http://some_new_uri') =='some_new_id' def test_get_id_returns_id(self): _set_uri_to_id({'http://some_uri': 'some_id'}) uri = 'http://some_uri' id = get_id_from_uri(uri) id_expected = 'some_id' - nt.assert_equal(id, id_expected) + assert id == id_expected def test_get_id_from_uri_returns_None_if_dict_empty(self): _set_uri_to_id({}) id = get_id_from_uri('some_uri') - nt.assert_equal(id, None) + assert id == None def test_get_id_from_uri_returns_None_if_id_unknown(self): _set_uri_to_id({'uri_to_id': {'http://some_uri': 'some_id'}}) id = get_id_from_uri('some_unknown_id') - nt.assert_equal(id, None) \ No newline at end of file + assert id == None diff --git a/dev-requirements.txt b/dev-requirements.txt index 296c410ff10a01f5be261393623ad1b427c48a89..3d609ba68221e37259acf30531e16eb977585251 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -7,7 +7,6 @@ astroid==1.6.6 atomicwrites==1.3.0 attrs==19.3.0 Babel==2.3.4 -backports.functools-lru-cache==1.5 Beaker==1.8.1 beautifulsoup4==4.5.1 billiard==3.3.0.23 @@ -43,8 +42,6 @@ Flask==0.11.1 Flask-DebugToolbar==0.10.0 FormEncode==1.3.0 funcsigs==1.0.2 -functools32==3.2.3.post2 -futures==3.3.0 GeoAlchemy==0.7.2 GeoAlchemy2==0.4.2 geolinks==0.2.0 @@ -76,7 +73,6 @@ monotonic==1.5 more-itertools==5.0.0 mox3==0.26.0 multiline-log-formatter==0.1.8 -nose==1.3.7 ofs==0.4.2 ordereddict==1.1 OWSLib==0.16.0