Skip to content

Commit 3507466

Browse files
chore: Prevent test suite artifact creation in work directory (ietf-tools#6438)
* chore: Prevent test suite artifact creation in work directory Also remove a few other stale test assets while I'm here. * Try and fix CI * Change IDSUBMIT_REPOSITORY_PATH * Make the dir * test: clean up media/nomcom directories * test: de-dup settings_temp_path_overrides * chore: remove debug * refactor: avoid premature import of test_utils * refactor: drop useless lambda wrapper --------- Co-authored-by: Jennifer Richards <jennifer@staff.ietf.org>
1 parent c6389ba commit 3507466

18 files changed

Lines changed: 33 additions & 10932 deletions

dev/tests/settings_local.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
}
1818

1919
IDSUBMIT_IDNITS_BINARY = "/usr/local/bin/idnits"
20-
IDSUBMIT_REPOSITORY_PATH = "test/id/"
21-
IDSUBMIT_STAGING_PATH = "test/staging/"
20+
IDSUBMIT_REPOSITORY_PATH = "/assets/ietfdata/doc/draft/repository"
21+
IDSUBMIT_STAGING_PATH = "/assets/www6s/staging/"
2222

2323
AGENDA_PATH = '/assets/www6s/proceedings/'
2424
MEETINGHOST_LOGO_PATH = AGENDA_PATH

docker/configs/settings_local.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ietf.settings_postgresqldb import DATABASES # pyflakes:ignore
99

1010
IDSUBMIT_IDNITS_BINARY = "/usr/local/bin/idnits"
11-
IDSUBMIT_STAGING_PATH = "test/staging/"
11+
IDSUBMIT_STAGING_PATH = "/assets/www6s/staging/"
1212

1313
AGENDA_PATH = '/assets/www6s/proceedings/'
1414
MEETINGHOST_LOGO_PATH = AGENDA_PATH
@@ -53,7 +53,7 @@
5353
FTP_DIR = '/assets/ftp'
5454

5555
NOMCOM_PUBLIC_KEYS_DIR = 'data/nomcom_keys/public_keys/'
56-
SLIDE_STAGING_PATH = 'test/staging/'
56+
SLIDE_STAGING_PATH = '/assets/www6s/staging/'
5757

5858
DE_GFM_BINARY = '/usr/local/bin/de-gfm'
5959

docker/scripts/app-create-dirs.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
#!/bin/bash
22

33
for sub in \
4-
test/id \
5-
test/staging \
6-
test/archive \
7-
test/rfc \
8-
test/media \
9-
test/wiki/ietf \
10-
data/nomcom_keys/public_keys \
114
/assets/archive/id \
125
/assets/collection \
136
/assets/collection/draft-archive \
@@ -27,6 +20,7 @@ for sub in \
2720
/assets/ietfdata/derived \
2821
/assets/ietfdata/derived/bibxml \
2922
/assets/ietfdata/derived/bibxml/bibxml-ids \
23+
/assets/ietfdata/doc/draft/repository \
3024
/assets/www6s \
3125
/assets/www6s/staging \
3226
/assets/www6s/wg-descriptions \

ietf/meeting/tests_js.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import time
66
import datetime
77
import shutil
8-
import os
8+
import tempfile
99
import re
1010

1111
from django.utils import timezone
@@ -939,13 +939,8 @@ def tearDown(self):
939939
def tempdir(self, label):
940940
# Borrowed from test_utils.TestCase
941941
slug = slugify(self.__class__.__name__.replace('.','-'))
942-
dirname = "tmp-{label}-{slug}-dir".format(**locals())
943-
if 'VIRTUAL_ENV' in os.environ:
944-
dirname = os.path.join(os.environ['VIRTUAL_ENV'], dirname)
945-
path = os.path.abspath(dirname)
946-
if not os.path.exists(path):
947-
os.mkdir(path)
948-
return path
942+
suffix = "-{label}-{slug}-dir".format(**locals())
943+
return tempfile.mkdtemp(suffix=suffix)
949944

950945
def displayed_interims(self, groups=None):
951946
sessions = add_event_info_to_session_qs(

ietf/person/factories.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import faker.config
99
import os
1010
import random
11-
import shutil
11+
from PIL import Image
1212

1313
from unidecode import unidecode
1414
from unicodedata import normalize
@@ -103,10 +103,9 @@ def default_photo(obj, create, extracted, **kwargs): # pylint: disable=no-self-a
103103
media_name = "%s/%s.jpg" % (settings.PHOTOS_DIRNAME, photo_name)
104104
obj.photo = media_name
105105
obj.photo_thumb = media_name
106-
photosrc = os.path.join(settings.TEST_DATA_DIR, "profile-default.jpg")
107106
photodst = os.path.join(settings.PHOTOS_DIR, photo_name + '.jpg')
108-
if not os.path.exists(photodst):
109-
shutil.copy(photosrc, photodst)
107+
img = Image.new('RGB', (200, 200))
108+
img.save(photodst)
110109
def delete_file(file):
111110
os.unlink(file)
112111
atexit.register(delete_file, photodst)

ietf/settings_test.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
# ./manage.py test --settings=settings_test doc.ChangeStateTestCase
1010
#
1111

12-
import os
12+
import atexit
13+
import os
14+
import shutil
15+
import tempfile
1316
from ietf.settings import * # pyflakes:ignore
14-
from ietf.settings import TEST_CODE_COVERAGE_CHECKER, BASE_DIR, PHOTOS_DIRNAME
17+
from ietf.settings import TEST_CODE_COVERAGE_CHECKER
1518
import debug # pyflakes:ignore
1619
debug.debug = True
1720

@@ -48,11 +51,20 @@ def __getitem__(self, item):
4851
if TEST_CODE_COVERAGE_CHECKER and not TEST_CODE_COVERAGE_CHECKER._started: # pyflakes:ignore
4952
TEST_CODE_COVERAGE_CHECKER.start() # pyflakes:ignore
5053

51-
NOMCOM_PUBLIC_KEYS_DIR=os.path.abspath("tmp-nomcom-public-keys-dir")
5254

53-
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'test/media/') # pyflakes:ignore
54-
MEDIA_URL = '/test/media/'
55-
PHOTOS_DIR = MEDIA_ROOT + PHOTOS_DIRNAME # pyflakes:ignore
55+
def tempdir_with_cleanup(**kwargs):
56+
"""Utility to create a temporary dir and arrange cleanup"""
57+
_dir = tempfile.mkdtemp(**kwargs)
58+
atexit.register(shutil.rmtree, _dir)
59+
return _dir
60+
61+
62+
NOMCOM_PUBLIC_KEYS_DIR = tempdir_with_cleanup(suffix="-nomcom-public-keys-dir")
63+
64+
MEDIA_ROOT = tempdir_with_cleanup(suffix="-media")
65+
PHOTOS_DIRNAME = "photo"
66+
PHOTOS_DIR = os.path.join(MEDIA_ROOT, PHOTOS_DIRNAME)
67+
os.mkdir(PHOTOS_DIR)
5668

5769
# Undo any developer-dependent middleware when running the tests
5870
MIDDLEWARE = [ c for c in MIDDLEWARE if not c in DEV_MIDDLEWARE ] # pyflakes:ignore

ietf/utils/test_utils.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3535

3636

37-
import os
37+
import tempfile
3838
import re
3939
import email
4040
import html5lib
@@ -239,13 +239,8 @@ def normalize(x):
239239

240240
def tempdir(self, label):
241241
slug = slugify(self.__class__.__name__.replace('.','-'))
242-
dirname = "tmp-{label}-{slug}-dir".format(**locals())
243-
if 'VIRTUAL_ENV' in os.environ:
244-
dirname = os.path.join(os.environ['VIRTUAL_ENV'], dirname)
245-
path = os.path.abspath(dirname)
246-
if not os.path.exists(path):
247-
os.mkdir(path)
248-
return path
242+
suffix = "-{label}-{slug}-dir".format(**locals())
243+
return tempfile.mkdtemp(suffix=suffix)
249244

250245
def assertNoFormPostErrors(self, response, error_css_selector=".is-invalid"):
251246
"""Try to fish out form errors, if none found at least check the
@@ -306,7 +301,7 @@ def setUp(self):
306301

307302
# Replace settings paths with temporary directories.
308303
self._ietf_temp_dirs = {} # trashed during tearDown, DO NOT put paths you care about in this
309-
for setting in self.settings_temp_path_overrides:
304+
for setting in set(self.settings_temp_path_overrides):
310305
self._ietf_temp_dirs[setting] = self.tempdir(slugify(setting))
311306
self._ietf_saved_context = django.test.utils.override_settings(**self._ietf_temp_dirs)
312307
self._ietf_saved_context.enable()

media/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

media/photo/nopictureavailable.jpg

-1.58 KB
Binary file not shown.

media/photo/profile-default.jpg

-1.36 KB
Binary file not shown.

0 commit comments

Comments
 (0)