Skip to content

Commit

Permalink
Remove redundant temp folder and unused imports
Browse files Browse the repository at this point in the history
In many of the tests classes we are creating two
temporary directories: one with the name "temp_<random_string>"
and inside it we generate a new directory for each test with the name
"Test<Class_Name>_<random_string>".

I think we don't need the "temp_<random_string>" directory.
The only benefit I can think of is that it could contain multiple
temp folders from failing tests from a particular test run.
But even then, this is not a big bonus because the name
"temp_<random_string>" is not really descriptive from which test
run this directory was created.

PS: Thanks to Jussi Kukkonen who noticed we are using two temp
folders per class in our tests.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
  • Loading branch information
MVrachev committed Oct 19, 2020
1 parent 510aa32 commit 4f8a15b
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 210 deletions.
17 changes: 5 additions & 12 deletions tests/test_arbitrary_package_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
from __future__ import unicode_literals

import os
import tempfile
import shutil
import json
import logging
Expand All @@ -64,11 +63,6 @@ class TestArbitraryPackageAttack(unittest_toolbox.Modified_TestCase):

@classmethod
def setUpClass(cls):
# Create a temporary directory to store the repository, metadata, and target
# files. 'temporary_directory' must be deleted in TearDownModule() so that
# temporary files are always removed, even when exceptions occur.
cls.temporary_directory = tempfile.mkdtemp(dir=os.getcwd())

# Launch a SimpleHTTPServer (serves files in the current directory).
# Test cases will request metadata and target files that have been
# pre-generated in 'tuf/tests/repository_data', which will be served by the
Expand All @@ -85,10 +79,6 @@ def tearDownClass(cls):
# Kills the server subprocess and closes the temp file used for logging.
cls.server_process_handler.clean()

# Remove the temporary repository directory, which should contain all the
# metadata, targets, and key files generated of all the test cases.
shutil.rmtree(cls.temporary_directory)




Expand All @@ -98,12 +88,15 @@ def setUp(self):

self.repository_name = 'test_repository1'

# Create a temporary directory to store the repository, metadata,
# and target files.
temporary_repository_root = \
self.make_temp_directory(directory=os.getcwd())

# Copy the original repository files provided in the test folder so that
# any modifications made to repository files are restricted to the copies.
# The 'repository_data' directory is expected to exist in 'tuf/tests/'.
original_repository_files = os.path.join(os.getcwd(), 'repository_data')
temporary_repository_root = \
self.make_temp_directory(directory=self.temporary_directory)

# The original repository, keystore, and client directories will be copied
# for each test case.
Expand Down
16 changes: 4 additions & 12 deletions tests/test_endless_data_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
from __future__ import unicode_literals

import os
import tempfile
import shutil
import json
import logging
Expand All @@ -66,11 +65,6 @@ class TestEndlessDataAttack(unittest_toolbox.Modified_TestCase):

@classmethod
def setUpClass(cls):
# Create a temporary directory to store the repository, metadata, and target
# files. 'temporary_directory' must be deleted in TearDownModule() so that
# temporary files are always removed, even when exceptions occur.
cls.temporary_directory = tempfile.mkdtemp(dir=os.getcwd())

# Launch a SimpleHTTPServer (serves files in the current directory).
# Test cases will request metadata and target files that have been
# pre-generated in 'tuf/tests/repository_data', which will be served by the
Expand All @@ -87,10 +81,6 @@ def tearDownClass(cls):
# Kills the server subprocess and closes the temp file used for logging.
cls.server_process_handler.clean()

# Remove the temporary repository directory, which should contain all the
# metadata, targets, and key files generated of all the test cases.
shutil.rmtree(cls.temporary_directory)




Expand All @@ -99,13 +89,15 @@ def setUp(self):
unittest_toolbox.Modified_TestCase.setUp(self)

self.repository_name = 'test_repository1'
# Create a temporary directory to store the repository, metadata,
# and target files.
temporary_repository_root = \
self.make_temp_directory(directory=os.getcwd())

# Copy the original repository files provided in the test folder so that
# any modifications made to repository files are restricted to the copies.
# The 'repository_data' directory is expected to exist in 'tuf/tests/'.
original_repository_files = os.path.join(os.getcwd(), 'repository_data')
temporary_repository_root = \
self.make_temp_directory(directory=self.temporary_directory)

# The original repository, keystore, and client directories will be copied
# for each test case.
Expand Down
16 changes: 4 additions & 12 deletions tests/test_extraneous_dependencies_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
from __future__ import unicode_literals

import os
import tempfile
import shutil
import json
import logging
Expand All @@ -70,11 +69,6 @@ class TestExtraneousDependenciesAttack(unittest_toolbox.Modified_TestCase):

@classmethod
def setUpClass(cls):
# Create a temporary directory to store the repository, metadata, and target
# files. 'temporary_directory' must be deleted in TearDownModule() so that
# temporary files are always removed, even when exceptions occur.
cls.temporary_directory = tempfile.mkdtemp(dir=os.getcwd())

# Launch a SimpleHTTPServer (serves files in the current directory).
# Test cases will request metadata and target files that have been
# pre-generated in 'tuf/tests/repository_data', which will be served by the
Expand All @@ -91,10 +85,6 @@ def tearDownClass(cls):
# Kills the server subprocess and closes the temp file used for logging.
cls.server_process_handler.clean()

# Remove the temporary repository directory, which should contain all the
# metadata, targets, and key files generated of all the test cases.
shutil.rmtree(cls.temporary_directory)




Expand All @@ -103,13 +93,15 @@ def setUp(self):
unittest_toolbox.Modified_TestCase.setUp(self)

self.repository_name = 'test_repository1'
# Create a temporary directory to store the repository, metadata,
# and target files.
temporary_repository_root = \
self.make_temp_directory(directory=os.getcwd())

# Copy the original repository files provided in the test folder so that
# any modifications made to repository files are restricted to the copies.
# The 'repository_data' directory is expected to exist in 'tuf/tests/'.
original_repository_files = os.path.join(os.getcwd(), 'repository_data')
temporary_repository_root = \
self.make_temp_directory(directory=self.temporary_directory)

# The original repository, keystore, and client directories will be copied
# for each test case.
Expand Down
16 changes: 4 additions & 12 deletions tests/test_indefinite_freeze_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

import os
import time
import tempfile
import shutil
import json
import logging
Expand Down Expand Up @@ -78,11 +77,6 @@ class TestIndefiniteFreezeAttack(unittest_toolbox.Modified_TestCase):

@classmethod
def setUpClass(cls):
# Create a temporary directory to store the repository, metadata, and target
# files. 'temporary_directory' must be deleted in TearDownModule() so that
# temporary files are always removed, even when exceptions occur.
cls.temporary_directory = tempfile.mkdtemp(dir=os.getcwd())

# Launch a SimpleHTTPServer (serves files in the current directory).
# Test cases will request metadata and target files that have been
# pre-generated in 'tuf/tests/repository_data', which will be served by the
Expand All @@ -99,24 +93,22 @@ def tearDownClass(cls):
# Kills the server subprocess and closes the temp file used for logging.
cls.server_process_handler.clean()

# Remove the temporary repository directory, which should contain all the
# metadata, targets, and key files generated of all the test cases.
shutil.rmtree(cls.temporary_directory)




def setUp(self):
# We are inheriting from custom class.
unittest_toolbox.Modified_TestCase.setUp(self)
self.repository_name = 'test_repository1'
# Create a temporary directory to store the repository, metadata,
# and target files.
temporary_repository_root = \
self.make_temp_directory(directory=os.getcwd())

# Copy the original repository files provided in the test folder so that
# any modifications made to repository files are restricted to the copies.
# The 'repository_data' directory is expected to exist in 'tuf/tests/'.
original_repository_files = os.path.join(os.getcwd(), 'repository_data')
temporary_repository_root = \
self.make_temp_directory(directory=self.temporary_directory)

# The original repository, keystore, and client directories will be copied
# for each test case.
Expand Down
16 changes: 4 additions & 12 deletions tests/test_key_revocation_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

import os
import shutil
import tempfile
import logging
import unittest
import sys
Expand All @@ -65,11 +64,6 @@ class TestKeyRevocation(unittest_toolbox.Modified_TestCase):

@classmethod
def setUpClass(cls):
# Create a temporary directory to store the repository, metadata, and target
# files. 'temporary_directory' must be deleted in TearDownModule() so that
# temporary files are always removed, even when exceptions occur.
cls.temporary_directory = tempfile.mkdtemp(dir=os.getcwd())

# Launch a SimpleHTTPServer (serves files in the current directory). Test
# cases will request metadata and target files that have been pre-generated
# in 'tuf/tests/repository_data', which will be served by the
Expand All @@ -86,10 +80,6 @@ def tearDownClass(cls):
# Kills the server subprocess and closes the temp file used for logging.
cls.server_process_handler.clean()

# Remove the temporary repository directory, which should contain all the
# metadata, targets, and key files generated for the test cases.
shutil.rmtree(cls.temporary_directory)




Expand All @@ -98,13 +88,15 @@ def setUp(self):
unittest_toolbox.Modified_TestCase.setUp(self)

self.repository_name = 'test_repository1'
# Create a temporary directory to store the repository, metadata,
# and target files.
temporary_repository_root = \
self.make_temp_directory(directory=os.getcwd())

# Copy the original repository files provided in the test folder so that
# any modifications made to repository files are restricted to the copies.
# The 'repository_data' directory is expected to exist in 'tuf.tests/'.
original_repository_files = os.path.join(os.getcwd(), 'repository_data')
temporary_repository_root = \
self.make_temp_directory(directory=self.temporary_directory)

# The original repository, keystore, and client directories will be copied
# for each test case.
Expand Down
16 changes: 4 additions & 12 deletions tests/test_mix_and_match_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from __future__ import unicode_literals

import os
import tempfile
import shutil
import logging
import unittest
Expand Down Expand Up @@ -69,11 +68,6 @@ class TestMixAndMatchAttack(unittest_toolbox.Modified_TestCase):

@classmethod
def setUpClass(cls):
# Create a temporary directory to store the repository, metadata, and
# target files. 'temporary_directory' must be deleted in TearDownModule()
# so that temporary files are always removed, even when exceptions occur.
cls.temporary_directory = tempfile.mkdtemp(dir=os.getcwd())

# Launch a SimpleHTTPServer (serves files in the current directory).
# Test cases will request metadata and target files that have been
# pre-generated in 'tuf/tests/repository_data', which will be served by the
Expand All @@ -90,10 +84,6 @@ def tearDownClass(cls):
# Kills the server subprocess and closes the temp file used for logging.
cls.server_process_handler.clean()

# Remove the temporary repository directory, which should contain all the
# metadata, targets, and key files generated of all the test cases.
shutil.rmtree(cls.temporary_directory)




Expand All @@ -102,13 +92,15 @@ def setUp(self):
unittest_toolbox.Modified_TestCase.setUp(self)

self.repository_name = 'test_repository1'
# Create a temporary directory to store the repository, metadata,
# and target files.
temporary_repository_root = \
self.make_temp_directory(directory=os.getcwd())

# Copy the original repository files provided in the test folder so that
# any modifications made to repository files are restricted to the copies.
# The 'repository_data' directory is expected to exist in 'tuf/tests/'.
original_repository_files = os.path.join(os.getcwd(), 'repository_data')
temporary_repository_root = \
self.make_temp_directory(directory=self.temporary_directory)

# The original repository, keystore, and client directories will be copied
# for each test case.
Expand Down
13 changes: 4 additions & 9 deletions tests/test_multiple_repositories_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from __future__ import unicode_literals

import os
import tempfile
import logging
import shutil
import unittest
Expand Down Expand Up @@ -61,15 +60,13 @@ def setUp(self):
# We are inheriting from custom class.
unittest_toolbox.Modified_TestCase.setUp(self)

self.temporary_directory = tempfile.mkdtemp(dir=os.getcwd())

# Copy the original repository files provided in the test folder so that
# any modifications made to repository files are restricted to the copies.
# The 'repository_data' directory is expected to exist in 'tuf/tests/'.
original_repository_files = os.path.join(os.getcwd(), 'repository_data')

self.temporary_repository_root = self.make_temp_directory(directory=
self.temporary_directory)
self.temporary_repository_root = self.make_temp_directory(
directory=os.getcwd())

# The original repository, keystore, and client directories will be copied
# for each test case.
Expand Down Expand Up @@ -171,8 +168,6 @@ def tearDown(self):
tuf.roledb.clear_roledb(clear_all=True)
tuf.keydb.clear_keydb(clear_all=True)

shutil.rmtree(self.temporary_directory)


def test_update(self):
self.assertEqual('test_repository1', str(self.repository_updater))
Expand Down Expand Up @@ -271,8 +266,8 @@ def test_repository_tool(self):
valid_targetinfo = multi_repo_updater.get_valid_targetinfo('file3.txt')

for my_updater, my_targetinfo in six.iteritems(valid_targetinfo):
my_updater.download_target(my_targetinfo, self.temporary_directory)
self.assertTrue(os.path.exists(os.path.join(self.temporary_directory, 'file3.txt')))
my_updater.download_target(my_targetinfo, self.temporary_repository_root)
self.assertTrue(os.path.exists(os.path.join(self.temporary_repository_root, 'file3.txt')))



Expand Down
16 changes: 4 additions & 12 deletions tests/test_replay_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from __future__ import unicode_literals

import os
import tempfile
import datetime
import shutil
import logging
Expand Down Expand Up @@ -69,11 +68,6 @@ class TestReplayAttack(unittest_toolbox.Modified_TestCase):

@classmethod
def setUpClass(cls):
# Create a temporary directory to store the repository, metadata, and target
# files. 'temporary_directory' must be deleted in TearDownModule() so that
# temporary files are always removed, even when exceptions occur.
cls.temporary_directory = tempfile.mkdtemp(dir=os.getcwd())

# Launch a SimpleHTTPServer (serves files in the current directory).
# Test cases will request metadata and target files that have been
# pre-generated in 'tuf/tests/repository_data', which will be served by the
Expand All @@ -90,10 +84,6 @@ def tearDownClass(cls):
# Kills the server subprocess and closes the temp file used for logging.
cls.server_process_handler.clean()

# Remove the temporary repository directory, which should contain all the
# metadata, targets, and key files generated of all the test cases.
shutil.rmtree(cls.temporary_directory)




Expand All @@ -102,13 +92,15 @@ def setUp(self):
unittest_toolbox.Modified_TestCase.setUp(self)

self.repository_name = 'test_repository1'
# Create a temporary directory to store the repository, metadata,
# and target files.
temporary_repository_root = \
self.make_temp_directory(directory=os.getcwd())

# Copy the original repository files provided in the test folder so that
# any modifications made to repository files are restricted to the copies.
# The 'repository_data' directory is expected to exist in 'tuf/tests/'.
original_repository_files = os.path.join(os.getcwd(), 'repository_data')
temporary_repository_root = \
self.make_temp_directory(directory=self.temporary_directory)

# The original repository, keystore, and client directories will be copied
# for each test case.
Expand Down
Loading

0 comments on commit 4f8a15b

Please sign in to comment.