Commit 3abb6dae authored by Samuel GAIST's avatar Samuel GAIST

[test][init] Fix cleanup of beat.core generated data

Only the cleanup of beat.cmdline was executed. beat.core
generated data were left as is.
parent b17beb55
......@@ -40,79 +40,85 @@ import os
import sys
import tempfile
import shutil
import subprocess
import subprocess # nosec
import pkg_resources
import contextlib
import six.moves.urllib as urllib
import urllib
from beat.core.test import tmp_prefix, teardown_package
from beat.core.test import tmp_prefix # noqa forward import
from beat.core.test import teardown_package as bc_teardown_package
platform = os.environ.get('BEAT_CMDLINE_TEST_PLATFORM', '')
platform = os.environ.get("BEAT_CMDLINE_TEST_PLATFORM", "")
disconnected = True
if platform:
# the special name 'django' makes as believe it is connected
if platform.startswith('django://'):
# sets up django infrastructure, preloads test data
os.environ.setdefault('DJANGO_SETTINGS_MODULE', platform[9:])
import django
django.setup()
# the special name 'django' makes as believe it is connected
if platform.startswith("django://"):
# sets up django infrastructure, preloads test data
os.environ.setdefault("DJANGO_SETTINGS_MODULE", platform[9:])
import django
# presets django database for tests
from django.core.management import call_command
call_command('install', 'test', interactive=False, verbose=1)
django.setup()
disconnected = False
# presets django database for tests
from django.core.management import call_command
else: #test it, actually
# some patching to prevent common problems
if not platform.endswith('/'): platform += '/'
if not platform.startswith('http'): platform = 'http://' + platform
try:
code = urllib.request.urlopen(platform).getcode()
disconnected = code != 200
except (IOError, urllib.URLError):
disconnected = True
call_command("install", "test", interactive=False, verbose=1)
disconnected = False
else: # test it, actually
# some patching to prevent common problems
if not platform.endswith("/"):
platform += "/"
if not platform.startswith("http"):
platform = "http://" + platform
try:
code = urllib.request.urlopen(platform).getcode() # nosec
disconnected = code != 200
except (IOError, urllib.URLError):
disconnected = True
else:
platform = 'User did not set $BEAT_CMDLINE_TEST_PLATFORM'
platform = "User did not set $BEAT_CMDLINE_TEST_PLATFORM"
user = 'user'
token = '4'
user = "user" # nosec
token = "3" # nosec
if sys.platform == 'darwin':
prefix_folder = tempfile.mkdtemp(prefix=__name__,
suffix='.prefix',
dir='/tmp')
if sys.platform == "darwin":
prefix_folder = tempfile.mkdtemp(
prefix=__name__, suffix=".prefix", dir="/tmp" # nosec
)
else:
prefix_folder = tempfile.mkdtemp(prefix=__name__,
suffix='.prefix')
prefix_folder = tempfile.mkdtemp(prefix=__name__, suffix=".prefix") # nosec
prefix = os.path.join(prefix_folder, 'prefix')
prefix = os.path.join(prefix_folder, "prefix")
def setup_package():
prefixes = [
pkg_resources.resource_filename('beat.backend.python.test', 'prefix'),
pkg_resources.resource_filename('beat.core.test', 'prefix')
pkg_resources.resource_filename("beat.backend.python.test", "prefix"),
pkg_resources.resource_filename("beat.core.test", "prefix"),
]
for path in prefixes:
subprocess.check_call(['rsync', '-arz', path, prefix_folder])
subprocess.check_call(["rsync", "-arz", path, prefix_folder]) # nosec
def teardown_package():
shutil.rmtree(prefix_folder)
bc_teardown_package()
@contextlib.contextmanager
def temp_cwd():
tempdir = tempfile.mkdtemp(prefix=__name__, suffix='.cwd')
tempdir = tempfile.mkdtemp(prefix=__name__, suffix=".cwd")
curdir = os.getcwd()
os.chdir(tempdir)
try: yield tempdir
try:
yield tempdir
finally:
os.chdir(curdir)
shutil.rmtree(tempdir)
os.chdir(curdir)
shutil.rmtree(tempdir)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment