Skip to content

Commit b00b0c3

Browse files
committed
Moved some production-path checks to the checks module, and fixed up tests which changed some settings without restoring them.
- Legacy-Id: 10808
2 parents 5ab5b8a + e348212 commit b00b0c3

7 files changed

Lines changed: 52 additions & 8 deletions

File tree

ietf/checks.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,34 @@ def check_doc_email_aliases_exists(app_configs, **kwargs):
6767

6868
return errors
6969

70+
@checks.register('directories')
71+
def check_id_submission_directories(app_configs, **kwargs):
72+
errors = []
73+
for s in ("IDSUBMIT_STAGING_PATH", "IDSUBMIT_REPOSITORY_PATH", "INTERNET_DRAFT_ARCHIVE_DIR"):
74+
p = getattr(settings, s)
75+
if not os.path.exists(p):
76+
errors.append(checks.Critical(
77+
"A directory used by the ID submission tool does not exist at the path given\n"
78+
"in the settings file. The setting is:\n"
79+
" %s = %s" % (s, p),
80+
hint = ("Please either update the local settings to point at the correct directory,"
81+
"or if the setting is correct, create the directory."),
82+
id = "datatracker.E0006",
83+
))
84+
return errors
85+
86+
@checks.register('files')
87+
def check_id_submission_files(app_configs, **kwargs):
88+
errors = []
89+
for s in ("IDSUBMIT_IDNITS_BINARY", ):
90+
p = getattr(settings, s)
91+
if not os.path.exists(p):
92+
errors.append(checks.Critical(
93+
"A file used by the ID submission tool does not exist at the path given\n"
94+
"in the settings file. The setting is:\n"
95+
" %s = %s" % (s, p),
96+
hint = ("Please either update the local settings to point at the correct file,"
97+
"or if the setting is correct, make sure the file is in place and has the right permissions."),
98+
id = "datatracker.E0007",
99+
))
100+
return errors

ietf/doc/tests_draft.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ def test_resurrect(self):
498498

499499
class ExpireIDsTests(TestCase):
500500
def setUp(self):
501+
self.saved_id_dir = settings.INTERNET_DRAFT_PATH
502+
self.saved_archive_dir = settings.INTERNET_DRAFT_ARCHIVE_DIR
501503
self.id_dir = os.path.abspath("tmp-id-dir")
502504
self.archive_dir = os.path.abspath("tmp-id-archive")
503505
if not os.path.exists(self.id_dir):
@@ -514,6 +516,8 @@ def setUp(self):
514516
def tearDown(self):
515517
shutil.rmtree(self.id_dir)
516518
shutil.rmtree(self.archive_dir)
519+
settings.INTERNET_DRAFT_PATH = self.saved_id_dir
520+
settings.INTERNET_DRAFT_ARCHIVE_DIR = self.saved_archive_dir
517521

518522
def write_draft_file(self, name, size):
519523
f = open(os.path.join(self.id_dir, name), 'w')

ietf/secr/drafts/tests_views.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818

1919
class MainTestCase(TestCase):
2020
def setUp(self):
21+
self.saved_internet_draft_path = settings.INTERNET_DRAFT_PATH
2122
self.repository_dir = os.path.abspath("tmp-submit-repository-dir")
2223
os.mkdir(self.repository_dir)
2324
settings.INTERNET_DRAFT_PATH = self.repository_dir
2425

26+
self.saved_internet_draft_archive_dir = settings.INTERNET_DRAFT_ARCHIVE_DIR
2527
self.archive_dir = os.path.abspath("tmp-submit-archive-dir")
2628
os.mkdir(self.archive_dir)
2729
settings.INTERNET_DRAFT_ARCHIVE_DIR = self.archive_dir
@@ -34,6 +36,8 @@ def tearDown(self):
3436
shutil.rmtree(self.repository_dir)
3537
shutil.rmtree(self.archive_dir)
3638
shutil.rmtree(self.manual_dir)
39+
settings.INTERNET_DRAFT_PATH = self.saved_internet_draft_path
40+
settings.INTERNET_DRAFT_ARCHIVE_DIR = self.saved_internet_draft_archive_dir
3741

3842
def test_abstract(self):
3943
draft = make_test_data()

ietf/secr/drafts/views.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ def archive_draft_files(filename):
4141
Takes a string representing the old draft filename, without extensions.
4242
Moves any matching files to archive directory.
4343
'''
44-
if not os.path.isdir(settings.INTERNET_DRAFT_ARCHIVE_DIR):
45-
raise IOError('Internet-Draft archive directory does not exist (%s)' % settings.INTERNET_DRAFT_ARCHIVE_DIR)
4644
files = glob.glob(os.path.join(settings.INTERNET_DRAFT_PATH,filename) + '.*')
4745
for file in files:
4846
shutil.move(file,settings.INTERNET_DRAFT_ARCHIVE_DIR)

ietf/submit/forms.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,6 @@ def clean(self):
118118
if self.shutdown and not has_role(self.request.user, "Secretariat"):
119119
raise forms.ValidationError('The submission tool is currently shut down')
120120

121-
# sanity check that paths exist (for development servers)
122-
for s in ("IDSUBMIT_STAGING_PATH", "IDSUBMIT_IDNITS_BINARY",
123-
"IDSUBMIT_REPOSITORY_PATH", "INTERNET_DRAFT_ARCHIVE_DIR"):
124-
if not os.path.exists(getattr(settings, s)):
125-
raise forms.ValidationError('%s defined in settings.py does not exist' % s)
126-
127121
for ext in ['txt', 'pdf', 'xml', 'ps']:
128122
f = self.cleaned_data.get(ext, None)
129123
if not f:

ietf/submit/tests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@
2424

2525
class SubmitTests(TestCase):
2626
def setUp(self):
27+
self.saved_idsubmit_staging_path = settings.IDSUBMIT_STAGING_PATH
2728
self.staging_dir = os.path.abspath("tmp-submit-staging-dir")
2829
os.mkdir(self.staging_dir)
2930
settings.IDSUBMIT_STAGING_PATH = self.staging_dir
3031

32+
self.saved_internet_draft_path = settings.INTERNET_DRAFT_PATH
33+
self.saved_idsubmit_repository_path = settings.IDSUBMIT_REPOSITORY_PATH
3134
self.repository_dir = os.path.abspath("tmp-submit-repository-dir")
3235
os.mkdir(self.repository_dir)
3336
settings.INTERNET_DRAFT_PATH = settings.IDSUBMIT_REPOSITORY_PATH = self.repository_dir
3437

38+
self.saved_archive_dir = settings.INTERNET_DRAFT_ARCHIVE_DIR
3539
self.archive_dir = os.path.abspath("tmp-submit-archive-dir")
3640
os.mkdir(self.archive_dir)
3741
settings.INTERNET_DRAFT_ARCHIVE_DIR = self.archive_dir
@@ -40,6 +44,11 @@ def tearDown(self):
4044
shutil.rmtree(self.staging_dir)
4145
shutil.rmtree(self.repository_dir)
4246
shutil.rmtree(self.archive_dir)
47+
settings.IDSUBMIT_STAGING_PATH = self.saved_idsubmit_staging_path
48+
settings.INTERNET_DRAFT_PATH = self.saved_internet_draft_path
49+
settings.IDSUBMIT_REPOSITORY_PATH = self.saved_idsubmit_repository_path
50+
settings.INTERNET_DRAFT_ARCHIVE_DIR = self.saved_archive_dir
51+
4352

4453
def submission_file(self, name, rev, group, format, templatename):
4554
# construct appropriate text draft

ietf/sync/tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ def test_notify_page(self):
209209

210210
class RFCSyncTests(TestCase):
211211
def setUp(self):
212+
self.save_id_dir = settings.INTERNET_DRAFT_PATH
213+
self.save_archive_dir = settings.INTERNET_DRAFT_ARCHIVE_DIR
212214
self.id_dir = os.path.abspath("tmp-id-dir")
213215
self.archive_dir = os.path.abspath("tmp-id-archive")
214216
if not os.path.exists(self.id_dir):
@@ -221,6 +223,8 @@ def setUp(self):
221223
def tearDown(self):
222224
shutil.rmtree(self.id_dir)
223225
shutil.rmtree(self.archive_dir)
226+
settings.INTERNET_DRAFT_PATH = self.save_id_dir
227+
settings.INTERNET_DRAFT_ARCHIVE_DIR = self.save_archive_dir
224228

225229
def write_draft_file(self, name, size):
226230
with open(os.path.join(self.id_dir, name), 'w') as f:

0 commit comments

Comments
 (0)