Commit a67f2ed6 authored by Jean-Baptiste's avatar Jean-Baptiste

update: reload source on new source

parent 8d60dbe4
Pipeline #4782 passed with stage
in 1 minute and 21 seconds
from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User
from django.contrib.auth.models import User
from django.db import models
from django.db.models.base import ModelBase
from django.urls import get_resolver
from django.utils.decorators import classonlymethod
from guardian.shortcuts import get_perms
from djangoldp.permissions import LDPPermissions
User._meta.rdf_type = "foaf:user"
......
import django
import sys
import django
from django.conf import settings
settings.configure(DEBUG=False,
ALLOWED_HOSTS = ["*"],
ALLOWED_HOSTS=["*"],
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
}
},
LDP_RDF_CONTEXT = {
LDP_RDF_CONTEXT={
"@context": {
"@vocab": "http://happy-dev.fr/owl/#",
"foaf": "http://xmlns.com/foaf/0.1/",
......@@ -35,7 +36,8 @@ settings.configure(DEBUG=False,
"control": "acl:Control"
}
},
AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend', 'guardian.backends.ObjectPermissionBackend'),
AUTHENTICATION_BACKENDS=(
'django.contrib.auth.backends.ModelBackend', 'guardian.backends.ObjectPermissionBackend'),
ROOT_URLCONF='djangoldp.urls',
DJANGOLDP_PACKAGES=['djangoldp.tests'],
INSTALLED_APPS=('django.contrib.auth',
......@@ -46,10 +48,9 @@ settings.configure(DEBUG=False,
'djangoldp',
'djangoldp.tests',
),
SITE_URL = 'http://happy-dev.fr',
SITE_URL='http://happy-dev.fr',
)
django.setup()
from django.test.runner import DiscoverRunner
......@@ -64,9 +65,9 @@ failures = test_runner.run_tests([
'djangoldp.tests.tests_auto_author',
'djangoldp.tests.tests_get',
'djangoldp.tests.tests_delete',
'djangoldp.tests.tests_sources',
# 'djangoldp.tests.tests_temp'
])
if failures:
sys.exit(failures)
from rest_framework.test import APIRequestFactory, APIClient, APITestCase
from djangoldp.models import LDPSource
class TestSource(APITestCase):
def setUp(self):
self.factory = APIRequestFactory()
self.client = APIClient()
def tearDown(self):
pass
def test_get_resource(self):
source = LDPSource.objects.create(federation="source_name", container="http://bar.foo/")
response = self.client.get('/sources/{}/'.format(source.federation), content_type='application/ld+json')
self.assertEqual(response.status_code, 200)
import sys
from importlib import reload
from django.apps import apps
from django.conf import settings
from django.conf.urls import url, include
from django.contrib.auth import get_user_model
from django.core.exceptions import FieldDoesNotExist
from django.core.urlresolvers import get_resolver
from django.db.models.signals import post_save, post_delete
from django.db.utils import OperationalError, ProgrammingError
from django.dispatch import receiver
from django.shortcuts import get_object_or_404
from django.urls import clear_url_caches
from django.utils.decorators import classonlymethod
from guardian.shortcuts import get_objects_for_user
from pyld import jsonld
from rest_framework import status
from rest_framework.authentication import SessionAuthentication
from rest_framework.parsers import JSONParser
from rest_framework.renderers import JSONRenderer
from rest_framework.viewsets import ModelViewSet
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from djangoldp.models import LDPSource, Model
from djangoldp.permissions import LDPPermissions
......@@ -133,7 +137,8 @@ class LDPViewSet(LDPViewSetGenerator):
meta_args['exclude'] = self.exclude or ()
meta_class = type('Meta', (), meta_args)
from djangoldp.serializers import LDPSerializer
return type(LDPSerializer)(self.model._meta.object_name.lower() + name_prefix + 'Serializer', (LDPSerializer,), {'Meta': meta_class})
return type(LDPSerializer)(self.model._meta.object_name.lower() + name_prefix + 'Serializer', (LDPSerializer,),
{'Meta': meta_class})
def create(self, request, *args, **kwargs):
serializer = self.get_write_serializer(data=request.data)
......@@ -255,7 +260,7 @@ class LDPNestedViewSet(LDPViewSet):
nested_related_name = related_field.remote_field.name
return cls.urls(
lookup_field= Model.get_meta(related_field.related_model, 'lookup_field', 'pk'),
lookup_field=Model.get_meta(related_field.related_model, 'lookup_field', 'pk'),
model=related_field.related_model,
exclude=(nested_related_name,) if related_field.one_to_many else (),
parent_model=cls.get_model(**kwargs),
......@@ -283,3 +288,14 @@ class LDPSourceViewSet(LDPViewSet):
def get_queryset(self, *args, **kwargs):
return super().get_queryset(*args, **kwargs).filter(federation=self.federation)
@receiver([post_save, post_delete], sender=LDPSource)
def reload_sources_module(sender, instance, **kwargs):
urlconf = settings.ROOT_URLCONF
clear_url_caches()
if 'djangoldp.urls' in sys.modules:
reload(sys.modules['djangoldp.urls'])
if urlconf in sys.modules:
reload(sys.modules[urlconf])
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