Allow running field binary tests with a non memory SQLite database
By setting the filestore path as a global variable, we can modify it for the test without changing the database path where the SQLite databases are stored. Closes #13792 (grafted from b431c4c5ddcf6556dcfd502bad748e18d596040a) --HG-- branch : 7.0
This commit is contained in:
@@ -8,6 +8,8 @@ from trytond.tools import resolve
|
||||
|
||||
__all__ = ['filestore']
|
||||
|
||||
PATH = os.path.normpath(config.get('database', 'path'))
|
||||
|
||||
|
||||
class FileStore(object):
|
||||
|
||||
@@ -51,10 +53,9 @@ class FileStore(object):
|
||||
return [self.set(d, prefix) for d in data]
|
||||
|
||||
def _filename(self, id, prefix):
|
||||
path = os.path.normpath(config.get('database', 'path'))
|
||||
filename = os.path.join(path, prefix, id[0:2], id[2:4], id)
|
||||
filename = os.path.join(PATH, prefix, id[0:2], id[2:4], id)
|
||||
filename = os.path.normpath(filename)
|
||||
if not filename.startswith(path):
|
||||
if not filename.startswith(PATH):
|
||||
raise ValueError('Bad prefix')
|
||||
return filename
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import unittest
|
||||
|
||||
from sql import Literal
|
||||
|
||||
from trytond.config import config
|
||||
from trytond import filestore
|
||||
from trytond.model import fields
|
||||
from trytond.model.exceptions import (
|
||||
RequiredValidationError, SQLConstraintError)
|
||||
@@ -25,10 +25,11 @@ class FieldBinaryTestCase(unittest.TestCase):
|
||||
activate_module('tests')
|
||||
|
||||
def setUp(self):
|
||||
path = config.get('database', 'path')
|
||||
super().setUp()
|
||||
path = filestore.PATH
|
||||
dtemp = tempfile.mkdtemp()
|
||||
config.set('database', 'path', dtemp)
|
||||
self.addCleanup(config.set, 'database', 'path', path)
|
||||
filestore.PATH = dtemp
|
||||
self.addCleanup(setattr, filestore, 'PATH', path)
|
||||
self.addCleanup(shutil.rmtree, dtemp)
|
||||
|
||||
@with_transaction()
|
||||
|
||||
Reference in New Issue
Block a user