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

update: add failing tests

parent ce1b7789
......@@ -65,6 +65,7 @@ class Resource(Model):
owner_perms = ['inherit']
serializer_fields = ["@id", "joboffers"]
nested_fields = ["joboffers"]
depth = 1
class UserProfile(Model):
......
......@@ -61,17 +61,17 @@ 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_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_temp'
# 'djangoldp.tests.tests_ldp_model',
# 'djangoldp.tests.tests_save',
# 'djangoldp.tests.tests_user_permissions',
# '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_temp'
])
if failures:
......
import json
from django.contrib.auth.models import User
from django.test import TestCase
from rest_framework.test import APIRequestFactory, APIClient
from djangoldp.tests.models import Resource, JobOffer
class TestTemp(TestCase):
......@@ -12,3 +16,61 @@ class TestTemp(TestCase):
def tearDown(self):
pass
# def test_m2m_existing_link(self):
# resource = Resource.objects.create()
# job = JobOffer.objects.create(title="first title", slug="job")
# resource.joboffers.add(job)
# resource.save()
# body = {
# 'http://happy-dev.fr/owl/#joboffers': {
# '@id': '/job-offers/{}'.format(job.slug),
# 'http://happy-dev.fr/owl/#title': "new job",
# }
# }
#
# 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(response.data['joboffers']['ldp:contains'][0]['@id'],
# "http://testserver/job-offers/aaa/")
# self.assertEqual(response.data['joboffers']['ldp:contains'][0]['title'], "new job")
def test_m2m_new_link(self):
resource = Resource.objects.create()
job = JobOffer.objects.create(title="first title", slug="job")
body = {
'http://happy-dev.fr/owl/#joboffers': {
'@id': 'http://testserver/job-offers/{}/'.format(job.slug),
}
}
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(response.data['joboffers']['ldp:contains'][0]['@id'],
"http://testserver/job-offers/{}/".format(job.slug))
self.assertEqual(response.data['joboffers']['ldp:contains'][0]['title'], "job")
def test_m2m_new_link_bis(self):
resource = Resource.objects.create()
job = JobOffer.objects.create(title="first title", slug="job")
body = {
'http://happy-dev.fr/owl/#joboffers':
{
'@id': "http://testserver/resources/{}/joboffers/".format(resource.pk),
"ldp:contains": [
{'@id': 'http://testserver/job-offers/{}/'.format(job.slug)},
]
}
}
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(response.data['joboffers']['ldp:contains'][0]['@id'],
"http://testserver/job-offers/{}/".format(job.slug))
self.assertEqual(response.data['joboffers']['ldp:contains'][0]['title'], "job")
......@@ -4,7 +4,7 @@ from rest_framework.test import APIRequestFactory, APIClient
from rest_framework.utils import json
from djangoldp.serializers import LDPSerializer
from djangoldp.tests.models import Post, UserProfile
from djangoldp.tests.models import Post, UserProfile, Resource
from djangoldp.tests.models import Skill, JobOffer, Conversation, Message
......@@ -395,3 +395,21 @@ class Update(TestCase):
content_type='application/ld+json')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['peer_user'], None)
def test_m2m_new_link_embedded(self):
resource = Resource.objects.create()
body = {
'http://happy-dev.fr/owl/#joboffers': {
'http://happy-dev.fr/owl/#slug': 'aaa',
'http://happy-dev.fr/owl/#title': "new job",
}
}
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(response.data['joboffers']['ldp:contains'][0]['@id'],
"http://testserver/job-offers/aaa/")
self.assertEqual(response.data['joboffers']['ldp:contains'][0]['title'], "new job")
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