diff --git a/geospaas/nansat_ingestor/tests.py b/geospaas/nansat_ingestor/tests.py index d3765dca..15e5b526 100644 --- a/geospaas/nansat_ingestor/tests.py +++ b/geospaas/nansat_ingestor/tests.py @@ -108,13 +108,13 @@ def setUp(self): self.mock_Nansat.return_value.get_metadata.side_effect = self.mock_get_metadata self.mock_Nansat.return_value.get_border_wkt.return_value = 'POLYGON((24.88 68.08,22.46 68.71,19.96 69.31,17.39 69.87,24.88 68.08))' self.mock_Nansat.return_value.bands.side_effect = self.mock_bands - # in order to prevent "mock leak" in the tests - self.addCleanup(patcher.stopall) - self.patcher2 = patch('geospaas.utils.utils.os.path.isfile') - self.mock_isfile = self.patcher2.start() - self.mock_isfile.return_value = True + self.patcher2 = patch('geospaas.nansat_ingestor.managers.validate_uri') + self.mock_validate_uri = self.patcher2.start() + self.mock_validate_uri.return_value = None + # in order to prevent "mock leak" in the tests + self.addCleanup(patch.stopall) def mock_get_metadata(self, *args): """ Mock behaviour of Nansat.get_metadata method """ @@ -168,11 +168,6 @@ def test_getorcreate_localfile_filtering_base_on_parameter(self): self.assertEqual(str(testingDataset.first().parameters.first()), self.predefined_band_metadata_dict[2]['standard_name']) - def test_fail_invalid_uri(self): - uri = '/this/is/some/file/but/not/an/uri' - with self.assertRaises(ValueError): - Dataset.objects.get_or_create(uri) - def test_dont_add_longitude_latitude(self): """ shall not add latitude and longitude into DatasetParameter table """ uri = 'file://localhost/some/folder/filename.ext' @@ -300,13 +295,7 @@ def setUp(self): ] self.mock_Crawl.return_value = PropertyMock( datasets=[test_LeafDataset]) - - def tearDown(self): - self.patch_LeafDataset.stop() - self.patch_validate_uri.stop() - self.patch_Crawl.stop() - self.patch_Dataset.stop() - self.patch_DatasetURI.stop() + self.addCleanup(patch.stopall) def test_ds_created(self): '''shall assert that NansatDataset.objects.get_or_create diff --git a/geospaas/tests.py b/geospaas/tests.py index dd079b32..07978fc5 100644 --- a/geospaas/tests.py +++ b/geospaas/tests.py @@ -42,3 +42,8 @@ def test_module_path(self, mock_mkdir): root = '/home/vagrant/site_media/media' mpath = utils.module_path(module, root) self.assertEqual(mpath, os.path.join(root, 'geospaas/catalog')) + + def test_fail_invalid_uri(self): + uri = '/this/is/some/file/but/not/an/uri' + with self.assertRaises(ValueError): + utils.validate_uri(uri)