Skip to content
Snippets Groups Projects
Commit 5faa7663 authored by Jean-Baptiste's avatar Jean-Baptiste
Browse files

Merge branch 'udpate/rename-thread-conversation' into 'master'

update: udpate tests 'thread' -> 'conversation'

See merge request startinblox/djangoldp-packages/djangoldp!58
parents c878c736 1e758b6c
No related branches found
Tags v0.5.74
1 merge request!58update: udpate tests 'thread' -> 'conversation'
Pipeline #915 passed with stage
in 1 minute and 25 seconds
from django.conf import settings
from django.conf.urls import url, include
from djangoldp.tests.models import Skill, JobOffer, Message, Thread, Dummy
from djangoldp.tests.models import Skill, JobOffer, Message, Conversation, Dummy
from djangoldp.views import LDPViewSet
urlpatterns = [
url(r'^messages/', LDPViewSet.urls(model=Message, permission_classes=[], fields=["@id", "text", "thread"], nested_fields=['thread'])),
url(r'^threads/', LDPViewSet.urls(model=Thread, nested_fields=["message_set"], permission_classes=())),
url(r'^messages/', LDPViewSet.urls(model=Message, permission_classes=[], fields=["@id", "text", "conversation"], nested_fields=['conversation'])),
url(r'^conversations/', LDPViewSet.urls(model=Conversation, nested_fields=["message_set"], permission_classes=())),
url(r'^users/', LDPViewSet.urls(model=settings.AUTH_USER_MODEL, permission_classes=[])),
url(r'^dummys/', LDPViewSet.urls(model=Dummy, permission_classes=[], lookup_field='slug',)),
]
......
......@@ -26,14 +26,14 @@ class JobOffer(Model):
lookup_field = 'slug'
class Thread(models.Model):
class Conversation(models.Model):
description = models.CharField(max_length=255, blank=True, null=True)
author_user = models.ForeignKey(settings.AUTH_USER_MODEL)
class Message(models.Model):
text = models.CharField(max_length=255, blank=True, null=True)
thread = models.ForeignKey(Thread, on_delete=models.DO_NOTHING)
conversation = models.ForeignKey(Conversation, on_delete=models.DO_NOTHING)
author_user = models.ForeignKey(settings.AUTH_USER_MODEL)
......
......@@ -2,7 +2,7 @@ from django.contrib.auth.models import User
from django.test import TestCase
from djangoldp.serializers import LDPSerializer
from djangoldp.tests.models import Skill, JobOffer, Thread, Message
from djangoldp.tests.models import Skill, JobOffer, Conversation, Message
class Update(TestCase):
......@@ -147,9 +147,9 @@ class Update(TestCase):
def test_update_list_with_reverse_relation(self):
user1 = User.objects.create()
thread = Thread.objects.create(description="Thread 1", author_user=user1)
message1 = Message.objects.create(text="Message 1", thread=thread, author_user=user1)
message2 = Message.objects.create(text="Message 2", thread=thread, author_user=user1)
conversation = Conversation.objects.create(description="Conversation 1", author_user=user1)
message1 = Message.objects.create(text="Message 1", conversation=conversation, author_user=user1)
message2 = Message.objects.create(text="Message 2", conversation=conversation, author_user=user1)
json = {"@graph": [
{
......@@ -161,8 +161,8 @@ class Update(TestCase):
"text": "Message 2 UP"
},
{
'@id': "https://happy-dev.fr/threads/{}/".format(thread.pk),
'description': "Thread 1 UP",
'@id': "https://happy-dev.fr/conversations/{}/".format(conversation.pk),
'description': "Conversation 1 UP",
"message_set": [
{"@id": "https://happy-dev.fr/messages/{}/".format(message1.pk)},
{"@id": "https://happy-dev.fr/messages/{}/".format(message2.pk)},
......@@ -171,26 +171,26 @@ class Update(TestCase):
]
}
meta_args = {'model': Thread, 'depth': 2, 'fields': ("@id", "description", "message_set")}
meta_args = {'model': Conversation, 'depth': 2, 'fields': ("@id", "description", "message_set")}
meta_class = type('Meta', (), meta_args)
serializer_class = type(LDPSerializer)('ThreadSerializer', (LDPSerializer,), {'Meta': meta_class})
serializer = serializer_class(data=json, instance=thread)
serializer_class = type(LDPSerializer)('ConversationSerializer', (LDPSerializer,), {'Meta': meta_class})
serializer = serializer_class(data=json, instance=conversation)
serializer.is_valid()
result = serializer.save()
messages = result.message_set.all().order_by('text')
self.assertEquals(result.description, "Thread 1 UP")
self.assertEquals(result.description, "Conversation 1 UP")
self.assertIs(result.message_set.count(), 2)
self.assertEquals(messages[0].text, "Message 1 UP")
self.assertEquals(messages[1].text, "Message 2 UP")
def test_add_new_element_with_foreign_key_id(self):
user1 = User.objects.create()
thread = Thread.objects.create(description="Thread 1", author_user=user1)
message1 = Message.objects.create(text="Message 1", thread=thread, author_user=user1)
message2 = Message.objects.create(text="Message 2", thread=thread, author_user=user1)
conversation = Conversation.objects.create(description="Conversation 1", author_user=user1)
message1 = Message.objects.create(text="Message 1", conversation=conversation, author_user=user1)
message2 = Message.objects.create(text="Message 2", conversation=conversation, author_user=user1)
json = {"@graph": [
{
......@@ -215,17 +215,17 @@ class Update(TestCase):
}
},
{
'@id': "https://happy-dev.fr/threads/{}/".format(thread.pk),
'@id': "https://happy-dev.fr/conversations/{}/".format(conversation.pk),
"author_user": {
'@id': "https://happy-dev.fr/users/{}/".format(user1.pk)
},
'description': "Thread 1 UP",
'description': "Conversation 1 UP",
'message_set': {
"@id": "https://happy-dev.fr/threads/{}/message_set/".format(thread.pk)
"@id": "https://happy-dev.fr/conversations/{}/message_set/".format(conversation.pk)
}
},
{
'@id': "https://happy-dev.fr/threads/{}/message_set/".format(thread.pk),
'@id': "https://happy-dev.fr/conversations/{}/message_set/".format(conversation.pk),
"ldp:contains": [
{"@id": "https://happy-dev.fr/messages/{}/".format(message1.pk)},
{"@id": "https://happy-dev.fr/messages/{}/".format(message2.pk)},
......@@ -235,17 +235,17 @@ class Update(TestCase):
]
}
meta_args = {'model': Thread, 'depth': 2, 'fields': ("@id", "description", "message_set")}
meta_args = {'model': Conversation, 'depth': 2, 'fields': ("@id", "description", "message_set")}
meta_class = type('Meta', (), meta_args)
serializer_class = type(LDPSerializer)('ThreadSerializer', (LDPSerializer,), {'Meta': meta_class})
serializer = serializer_class(data=json, instance=thread)
serializer_class = type(LDPSerializer)('ConversationSerializer', (LDPSerializer,), {'Meta': meta_class})
serializer = serializer_class(data=json, instance=conversation)
serializer.is_valid()
result = serializer.save()
messages = result.message_set.all().order_by('text')
self.assertEquals(result.description, "Thread 1 UP")
self.assertEquals(result.description, "Conversation 1 UP")
self.assertIs(result.message_set.count(), 3)
self.assertEquals(messages[0].text, "Message 1 UP")
self.assertEquals(messages[1].text, "Message 2 UP")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment