Skip to content

Commit

Permalink
#111 moving the annoying test to geospaas test folder///stop all the …
Browse files Browse the repository at this point in the history
…patchers with stopall
  • Loading branch information
aanersc authored and akorosov committed Jul 10, 2020
1 parent 8acfb21 commit 151fcc1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
23 changes: 6 additions & 17 deletions geospaas/nansat_ingestor/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions geospaas/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 151fcc1

Please sign in to comment.