diff --git a/djangoldp/tests/runner.py b/djangoldp/tests/runner.py index 9ef164ecd6dceb6079edbb58e5f52e2836cfb619..dec534f81e727df345fe38eb9faabc9ed474b5b7 100644 --- a/djangoldp/tests/runner.py +++ b/djangoldp/tests/runner.py @@ -12,20 +12,20 @@ from django.test.runner import DiscoverRunner test_runner = DiscoverRunner(verbosity=1) failures = test_runner.run_tests([ - 'djangoldp.tests.tests_ldp_model', - 'djangoldp.tests.tests_save', - 'djangoldp.tests.tests_user_permissions', - 'djangoldp.tests.tests_guardian', - 'djangoldp.tests.tests_anonymous_permissions', - 'djangoldp.tests.tests_update', - 'djangoldp.tests.tests_auto_author', - 'djangoldp.tests.tests_get', - 'djangoldp.tests.tests_delete', - 'djangoldp.tests.tests_sources', - 'djangoldp.tests.tests_pagination', - 'djangoldp.tests.tests_inbox', - 'djangoldp.tests.tests_backlinks_service', - # 'djangoldp.tests.tests_temp' + # 'djangoldp.tests.tests_ldp_model', + # 'djangoldp.tests.tests_save', + # 'djangoldp.tests.tests_user_permissions', + # 'djangoldp.tests.tests_guardian', + # 'djangoldp.tests.tests_anonymous_permissions', + # 'djangoldp.tests.tests_update', + # 'djangoldp.tests.tests_auto_author', + # 'djangoldp.tests.tests_get', + # 'djangoldp.tests.tests_delete', + # 'djangoldp.tests.tests_sources', + # 'djangoldp.tests.tests_pagination', + # 'djangoldp.tests.tests_inbox', + # 'djangoldp.tests.tests_backlinks_service', + 'djangoldp.tests.tests_temp' ]) if failures: diff --git a/djangoldp/tests/tests_save.py b/djangoldp/tests/tests_save.py index a785233b4a729cf748ec289aa3d7563304a39a0a..48fe32f3d91be959db82c26cb8223cdd05d65e21 100644 --- a/djangoldp/tests/tests_save.py +++ b/djangoldp/tests/tests_save.py @@ -318,7 +318,6 @@ class Save(TestCase): self.assertEqual(response.data['circle']['@id'], "http://testserver/circles/{}/".format(circle.pk)) - def test_nested_container_federated(self): resource = Resource.objects.create() body = { diff --git a/djangoldp/tests/tests_temp.py b/djangoldp/tests/tests_temp.py index a7e6d763bfd3cc08962a5ad393691e3f3a8174e5..d9c93559b8a234e415c1250445358bf429014a36 100644 --- a/djangoldp/tests/tests_temp.py +++ b/djangoldp/tests/tests_temp.py @@ -2,7 +2,7 @@ import json from guardian.shortcuts import assign_perm -from .models import PermissionlessDummy, Dummy +from .models import PermissionlessDummy, Dummy, Resource, UserProfile from django.contrib.auth import get_user_model from django.test import TestCase from rest_framework.test import APIRequestFactory, APIClient @@ -33,15 +33,75 @@ class TestTemp(TestCase): def tearDown(self): pass + # def test_nested_container_federated_609(self): + # resource = Resource.objects.create() + # body = { + # 'http://happy-dev.fr/owl/#@id': "http://testserver/resources/{}".format(resource.pk), + # 'http://happy-dev.fr/owl/#joboffers': [ + # { + # 'http://happy-dev.fr/owl/#@id': "https://external.com/job-offers/1" + # }, + # { + # 'http://happy-dev.fr/owl/#@id': "https://external.com/job-offers/2" + # } + # ] + # } + # + # response = self.client.put('/resources/{}/'.format(resource.pk), + # data=json.dumps(body), + # content_type='application/ld+json') + # self.assertEqual(response.status_code, 200) + # self.assertEqual(len(response.data['joboffers']['ldp:contains']), 2) + # + # body2 = { + # 'http://happy-dev.fr/owl/#@id': "http://testserver/resources/{}".format(resource.pk), + # 'http://happy-dev.fr/owl/#joboffers': [ + # { + # 'http://happy-dev.fr/owl/#@id': "https://external.com/job-offers/1" + # }, + # { + # 'http://happy-dev.fr/owl/#@id': "https://external.com/job-offers/3" + # }, + # { + # 'http://happy-dev.fr/owl/#@id': "https://external.com/job-offers/4" + # } + # ] + # } + # response = self.client.put('/resources/{}/'.format(resource.pk), + # data=json.dumps(body2), + # content_type='application/ld+json') + # + # self.assertEqual(response.status_code, 200) + # self.assertEqual(len(response.data['joboffers']['ldp:contains']), 3) + # + # response = self.client.put('/resources/{}/job-offers'.format(resource.pk), + # data=json.dumps(body2), + # content_type='application/ld+json') - # test with anonymous user - def test_invalidate_cache_permissions(self): - self.setUpLoggedInUser() - self.setUpGuardianDummyWithPerms() - response = self.client.get('/permissionless-dummys/{}/'.format(self.dummy.slug)) - self.assertEqual(response.status_code, 403) - assign_perm('view' + '_' + PermissionlessDummy._meta.model_name, self.user, self.dummy) - LDPPermissions.invalidate_cache() - response = self.client.get('/permissionless-dummys/{}/'.format(self.dummy.slug)) + def test_create_sub_object_in_existing_object_with_existing_reverse_1to1_relation(self): + user = get_user_model().objects.create(username="alex", password="test") + profile = UserProfile.objects.create(user=user, description="user description") + body = { + '@id': '/users/{}/'.format(user.pk), + "first_name": "Alexandre", + "last_name": "Bourlier", + "username": "alex", + 'userprofile': { + '@id': "http://happy-dev.fr/userprofiles/{}/".format(profile.pk), + 'description': "user update" + }, + '@context': { + "@vocab": "http://happy-dev.fr/owl/#", + } + } + + response = self.client.put('/users/{}/'.format(user.pk), data=json.dumps(body), + content_type='application/ld+json') self.assertEqual(response.status_code, 200) + self.assertIn('userprofile', response.data) + + response = self.client.get('/userprofiles/{}/'.format(profile.pk), + content_type='application/ld+json') + self.assertEqual(response.data['description'], "user update") +