2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-01-18 23:42:49 +00:00

fixed tempfile bleed through

This commit is contained in:
2025-12-17 22:10:32 +00:00
parent 09a9b6e18f
commit 9392d4a2d9
3 changed files with 19 additions and 21 deletions

View File

@@ -228,9 +228,9 @@ class FixturePageTests(TestCase):
content = response.content.decode()
ph = r"Seetrichter"
ph_alt = r"1623-284"
phmatch = re.search(ph, content) or re.search(ph_alt, content)
with open('_cave_caves284.html', 'w') as f:
f.write(content)
# phmatch = re.search(ph, content) or re.search(ph_alt, content)
# with open('_cave_caves284.html', 'w') as f:
# f.write(content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "' or '" + ph_alt + "'")
# Although the Cave object exists, it looks like we get a bad slug error when trying to get a QM page.

View File

@@ -1,6 +1,7 @@
import os
import pathlib
import tempfile
from unittest.mock import patch
from django.test import TestCase
@@ -27,10 +28,10 @@ class DrawingsPathlibTests(TestCase):
(sub2 / 'abc.th2').write_text('th2')
(sub2 / 'abc.th').write_text('th')
# point the module at our tempdir
settings.DRAWINGS_DATA = td
drawings.load_drawings_files()
# point the module at our tempdir using a temporary setting on the
# local settings module (the parsers import `settings` directly)
with patch.object(settings, "DRAWINGS_DATA", td):
drawings.load_drawings_files()
# all files should be present
self.assertTrue(DrawingFile.objects.filter(dwgpath='one.pdf').exists())
@@ -44,9 +45,8 @@ class DrawingsPathlibTests(TestCase):
p = pathlib.Path(td)
(p / '.hidden').write_text('hid')
(p / 'file~').write_text('bak')
settings.DRAWINGS_DATA = td
drawings.load_drawings_files()
with patch.object(settings, "DRAWINGS_DATA", td):
drawings.load_drawings_files()
# Should not import hidden or backup files
self.assertFalse(DrawingFile.objects.filter(dwgpath='.hidden').exists())
@@ -56,9 +56,8 @@ class DrawingsPathlibTests(TestCase):
with tempfile.TemporaryDirectory() as td:
p = pathlib.Path(td)
(p / 'noext').write_text('data')
settings.DRAWINGS_DATA = td
drawings.load_drawings_files()
with patch.object(settings, "DRAWINGS_DATA", td):
drawings.load_drawings_files()
self.assertTrue(DrawingFile.objects.filter(dwgpath='noext').exists())
@@ -68,9 +67,8 @@ class DrawingsPathlibTests(TestCase):
g = p / '.git'
g.mkdir()
(g / 'secret.txt').write_text('top secret')
settings.DRAWINGS_DATA = td
drawings.load_drawings_files()
with patch.object(settings, "DRAWINGS_DATA", td):
drawings.load_drawings_files()
self.assertFalse(DrawingFile.objects.filter(dwgpath='.git/secret.txt').exists())
@@ -81,9 +79,8 @@ class DrawingsPathlibTests(TestCase):
p = pathlib.Path(td)
for i in range(count):
(p / f'file{i}.txt').write_text('x')
settings.DRAWINGS_DATA = td
drawings.load_drawings_files()
with patch.object(settings, "DRAWINGS_DATA", td):
drawings.load_drawings_files()
self.assertEqual(DrawingFile.objects.count(), count)

View File

@@ -256,9 +256,10 @@ def _handle_obsolete_wallets(old_wallet, dwgfile, scanfilename, parser_label):
if w_renamed := _find_renamed_x_wallet(old_wallet, scanfilename, parser_label):
return w_renamed
message = f" - Warning {parser_label} XFILES {old_wallet} {(old_wallet==x.group(1))} in {path}"
# 'path' is not in scope here; use the drawing file's path for messages
message = f" - Warning {parser_label} XFILES {old_wallet} {(old_wallet==x.group(1))} in {dwgfile.dwgpath}"
print(message)
DataIssue.objects.update_or_create(parser=parser_label, message=message, url=f"/dwgdataraw/{path}")
DataIssue.objects.update_or_create(parser=parser_label, message=message, url=f"/dwgdataraw/{dwgfile.dwgpath}")
return False
if old_wallet in old_wallets: