Commit 9715fac0 authored by Florent Chehab's avatar Florent Chehab

Fixed backend batch import, should fix testing too

parent 69453f94
Pipeline #34750 passed with stages
in 2 minutes and 47 seconds
......@@ -3,24 +3,22 @@ from dotmap import DotMap
from reversion_compare.admin import CompareVersionAdmin
from shared import get_api_config
import importlib
api_config = get_api_config()
CLASSIC_MODELS_str = ""
VERSIONNED_MODELS_str = ""
CLASSIC_MODELS = []
VERSIONNED_MODELS = []
for model in api_config:
if "model" in model and model['model']:
model = DotMap(model)
if (not model.requires_testing) and (not model.ignore_in_admin):
exec("from backend.models.{} import {}".format(model.import_location, model.model))
module = importlib.import_module("backend.models.{}".format (model.import_location))
if model.versionned:
VERSIONNED_MODELS_str += model.model + ','
VERSIONNED_MODELS.append(getattr(module, model.model))
else:
CLASSIC_MODELS_str += model.model + ','
exec("CLASSIC_MODELS = [{}]".format(CLASSIC_MODELS_str))
exec("VERSIONNED_MODELS = [{}]".format(VERSIONNED_MODELS_str))
CLASSIC_MODELS.append(getattr(module, model.model))
for model in CLASSIC_MODELS:
......
......@@ -2,6 +2,7 @@ from django.conf import settings
from dotmap import DotMap
from shared import get_api_config
import importlib
api_config = get_api_config()
......@@ -11,16 +12,16 @@ for model in api_config:
model = DotMap(model)
if not model.requires_testing:
if model.viewset != 'UserDataViewSet':
exec("from backend.models.{} import {}".format(model.import_location, model.viewset))
exec("ALL_VIEWSETS['{}'] = {}".format(model.viewset, model.viewset))
module = importlib.import_module("backend.models.{}".format (model.import_location))
ALL_VIEWSETS[model.viewset] = getattr(module, model.viewset)
if settings.TESTING:
for model in api_config:
model = DotMap(model)
if model.requires_testing:
if model.viewset != 'UserDataViewSet':
exec("from backend.models.{} import {}".format(model.import_location, model.viewset))
exec("ALL_VIEWSETS['{}'] = {}".format(model.viewset, model.viewset))
module = importlib.import_module("backend.models.{}".format (model.import_location))
ALL_VIEWSETS[model.viewset] = getattr(module, model.viewset)
class Request(object):
......
......@@ -10,6 +10,8 @@ from shared import get_api_config
from . import views
from dotmap import DotMap
import importlib
urlpatterns = [
url(r'^api-docs/', include_docs_urls(title='Outgoing API')),
]
......@@ -24,11 +26,20 @@ api_config = get_api_config()
for model in api_config:
model = DotMap(model)
if not model.requires_testing:
exec("from backend.models.{} import {}".format(model.import_location, model.viewset))
exec("ALL_VIEWSETS.append({})".format(model.viewset))
module = importlib.import_module("backend.models.{}".format(model.import_location))
Viewset = getattr(module, model.viewset)
ALL_VIEWSETS.append(Viewset)
if model.model is not None and not model.ignore_in_admin:
exec("from backend.models.{} import {}".format(model.import_location, model.model))
exec("ALL_MODELS.append({})".format(model.model))
ALL_MODELS.append(getattr(module, model.model))
# print(viewset)
str_url = model.api_end_point
if 'api_attr' in model:
str_url += '/{}'.format(model.api_attr)
if 'api_name' in model:
router.register(str_url, Viewset, model.api_name)
else:
router.register(str_url, Viewset)
if settings.TESTING:
......@@ -36,33 +47,19 @@ if settings.TESTING:
for model in api_config:
model = DotMap(model)
if model.requires_testing:
exec("from backend.models.{} import {}".format(model.import_location, model.viewset))
exec("ALL_VIEWSET.append({})".format(model.viewset))
module = importlib.import_module("backend.models.{}".format(model.import_location))
Viewset = getattr(module, model.viewset)
ALL_VIEWSETS.append(Viewset)
if model.model is not None:
exec("from backend.models.{} import {}".format(model.import_location, model.model))
exec("ALL_MODELS.append({})".format(model.model))
ALL_MODELS.append(getattr(module, model.model))
str_url = model.api_end_point
if 'api_attr' in model:
str_url += '/{}'.format(model.api_attr)
if 'api_name' in model:
cmd = "r'{}', {}, '{}'".format(str_url, model.viewset, model.api_name)
router.register(str_url, Viewset, model.api_name)
else:
cmd = "r'{}', {}".format(str_url, model.viewset)
exec("router.register({})".format(cmd))
for model in api_config:
model = DotMap(model)
if not model.requires_testing:
str_url = model.api_end_point
if 'api_attr' in model:
str_url += '/{}'.format(model.api_attr)
if 'api_name' in model:
cmd = "r'{}', {}, '{}'".format(str_url, model.viewset, model.api_name)
else:
cmd = "r'{}', {}".format(str_url, model.viewset)
exec("router.register({})".format(cmd))
router.register(str_url, Viewset, model.viewset)
urlpatterns += [url(r'^api/', include(router.urls))]
......
......@@ -6,8 +6,8 @@ djangorestframework==3.8.2 # Django REST Framework
coreapi==2.3.3 # Automatic API doc generation
django-reversion==2.0.13
django-reversion-compare==0.8.4
pytest-django==3.4.2
pytest-cov==2.5.1
pytest-django==3.4.7
pytest-cov==2.6.1
pytest-xdist==1.23.0
flake8
django-debug-toolbar==1.9.1
......
from .get_api_config import get_api_config # noqa: F401
from .obj_moderation_permission import DEFAULT_OBJ_MODERATION_LV, OBJ_MODERATION_PERMISSIONS
\ No newline at end of file
from .obj_moderation_permission import DEFAULT_OBJ_MODERATION_LV, OBJ_MODERATION_PERMISSIONS # noqa: F401
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