Skip to content

Commit

Permalink
fix(tests): tmp dir;
Browse files Browse the repository at this point in the history
- TMPDIR fixes.
  • Loading branch information
JVickery-TBS committed Dec 9, 2024
1 parent ee5f621 commit d1eef74
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions ckanext/xloader/tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def get_large_data_response(download_url, headers):
resp.headers = headers
return resp

def _get_temp_files():
return [os.path.join('/tmp', f) for f in os.listdir('/tmp') if os.path.isfile(os.path.join('/tmp', f))]
def _get_temp_files(dir='/tmp'):
return [os.path.join(dir, f) for f in os.listdir(dir) if os.path.isfile(os.path.join(dir, f))]


@pytest.fixture
Expand Down Expand Up @@ -90,6 +90,14 @@ def data(create_with_upload, apikey):
@pytest.mark.ckan_config("ckan.jobs.timeout", 15)
class TestXLoaderJobs(helpers.FunctionalRQTestBase):

@classmethod
def setup_method(self, method):
"""Method is called at class level before EACH test methods of the class are called.
Setup any state specific to the execution of the given class methods.
"""
for f in _get_temp_files():
os.remove(f)

def test_xloader_data_into_datastore(self, cli, data):
self.enqueue(jobs.xloader_data_into_datastore, [data])
with mock.patch("ckanext.xloader.jobs.get_response", get_response):
Expand Down Expand Up @@ -138,8 +146,6 @@ def test_data_max_excerpt_lines_config(self, cli, data):
assert resource["datastore_contains_all_records_of_source_file"] is False

def test_data_with_rq_job_timeout(self, cli, data):
for f in _get_temp_files():
os.remove(f)
assert len(_get_temp_files()) == 0
self.enqueue(jobs.xloader_data_into_datastore, [data], rq_kwargs=dict(timeout=15))
with mock.patch("ckanext.xloader.jobs.get_response", get_large_data_response):
Expand Down

0 comments on commit d1eef74

Please sign in to comment.