mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-02-08 12:41:09 +00:00
fixed tempfile bleed through
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user