Commit 1356f45e authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[test][core] Add base class for remote relate tests

This will make use of Django LiveServerTestCase and will
allow to properly test the WebAPI class as currently the
Django REST framework client is used.
parent 052b8e72
......@@ -38,9 +38,11 @@
Base class for asset testing
"""
import os
import nose.tools
import click
import shutil
from click.testing import CliRunner
from beat.core.test.utils import cleanup
......@@ -48,7 +50,20 @@ from beat.cmdline.scripts import main_cli
from .. import common
from . import platform, prefix, tmp_prefix, user, token
from . import platform, disconnected, prefix, tmp_prefix, user, token
if not disconnected:
from django.contrib.staticfiles.testing import LiveServerTestCase
else:
class LiveServerTestCase:
"""Dummy shell class"""
live_server_url = None
@classmethod
def setUpClass(cls):
pass
class AssetLocalTest:
......@@ -169,3 +184,65 @@ class AssetLocalTest:
exit_code, outputs = self.call("rm", obj, prefix=tmp_prefix)
nose.tools.eq_(exit_code, 1, outputs)
nose.tools.assert_false(storage.exists())
class OnlineTestCase(LiveServerTestCase):
"""Test case using django live server for test of remote functions"""
asset_type = None
@classmethod
def setUpClass(cls):
super().setUpClass()
nose.tools.assert_is_not_none(cls.asset_type)
def setUp(self):
"""Cache a copy of the database to avoid the need to call make install
on each tests.
"""
if not disconnected:
from django.conf import settings
database_path = settings.DATABASES["default"]["TEST"]["NAME"]
db_backup = os.path.join(prefix, "django_test_database.sqlite3")
if not os.path.exists(db_backup):
shutil.copyfile(database_path, db_backup)
else:
shutil.copyfile(db_backup, database_path)
def tearDown(self):
cleanup()
@classmethod
def call(cls, *args, **kwargs):
"""A central mechanism to call the main routine with the right parameters"""
use_prefix = kwargs.get("prefix", prefix)
use_platform = kwargs.get("platform", cls.live_server_url)
asset_type = kwargs.get("asset_type", cls.asset_type)
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(
main_cli.main,
[
"--test-mode",
"--prefix",
use_prefix,
"--token",
token,
"--user",
user,
"--platform",
use_platform,
asset_type,
]
+ list(args),
catch_exceptions=False,
)
if result.exit_code != 0:
click.echo(result.output)
return result.exit_code, result.output
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