From c96f5d810a878250e8359ccb12074f5bd2f32302 Mon Sep 17 00:00:00 2001 From: Thorge Petersen <petersen@rz.uni-kiel.de> Date: Mon, 5 Jun 2023 16:18:59 +0200 Subject: [PATCH] Started fixing validation tests --- ckanext/odsh/tests/test_validation.py | 28 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/ckanext/odsh/tests/test_validation.py b/ckanext/odsh/tests/test_validation.py index 40e8ee32..c46d73af 100644 --- a/ckanext/odsh/tests/test_validation.py +++ b/ckanext/odsh/tests/test_validation.py @@ -3,6 +3,7 @@ import ckan.plugins.toolkit as toolkit import ckan.model as modelMock import sys import json +import pytest from mock import MagicMock, Mock, patch @@ -52,16 +53,16 @@ def test_tag_string_convert(): assert data[('tags', 1, 'name')] == 'tag2' -@raises(Exception) def test_tag_name_validator_invalid(): - tag_name_validator('&', None) + with pytest.raises(Exception): + tag_name_validator('&', None) def test_tag_name_validator_valid(): tag_name_validator('valid', None) -@patch('urllib2.urlopen') +@patch('urllib.request.urlopen') @patch('pylons.config.get', side_effect='foo') @patch('csv.reader', side_effect=[[['uri', 'text', json.dumps({"geometry": 0})]]]) def test_known_spatial_uri(url_mock, get_mock, csv_mock): @@ -77,26 +78,31 @@ def test_known_spatial_uri(url_mock, get_mock, csv_mock): assert data[('extras', 2, 'value')] == '0' -@raises(Exception) -@patch('urllib2.urlopen') +@pytest.mark.parametrize('exception_type', [Exception]) +@patch('urllib.request.urlopen') @patch('pylons.config.get', side_effect='foo') @patch('csv.reader', side_effect=[[['uri', 'text', json.dumps({"geometry": 0})]]]) -def test_known_spatial_uri_without_uri(url_mock, get_mock, csv_mock): +def test_known_spatial_uri_without_uri(url_mock, get_mock, csv_mock, exception_type): # arrange data = {('extras', 0, 'key'): 'spatial_uri', ('extras', 0, 'value'): ''} - # act - known_spatial_uri('spatial_uri', data, {}, None) + + # act and assert + with pytest.raises(exception_type): + known_spatial_uri('spatial_uri', data, {}, None) -def test_known_spatial_uri_without_uri_with_spatial(): +@pytest.mark.parametrize('exception_type', [Exception]) +def test_known_spatial_uri_without_uri_with_spatial(exception_type): # arrange data = {('extras', 0, 'key'): 'spatial', ('extras', 0, 'value'): 'value', ('extras', 1, 'key'): 'spatial_uri', ('extras', 1, 'value'): ''} - # act - known_spatial_uri('spatial_uri', data, {}, None) + + # act and assert + with pytest.raises(exception_type): + known_spatial_uri('spatial_uri', data, {}, None) def test_validate_licenseAttributionByText(): -- GitLab