Commit 8632e5eb authored by Mickaël Desfrênes's avatar Mickaël Desfrênes
Browse files

fix annotation tests

parent 707e1a78
Loading
Loading
Loading
Loading
+11 −13
Original line number Diff line number Diff line
@@ -3,9 +3,7 @@ from resources import models
from rpc import methods as rpc_methods
from resources.management.commands.loadfixtures import load_fixtures
from django.contrib.auth.models import User

from annotations.models import Annotation
from annotations.rpc import methods as annotations_methods
from rpc.methods import ServiceException

test_json = {"pouet": "tagada"}
@@ -63,32 +61,32 @@ class AnnotationTestCase(TestCase):

    def test_add_annotation(self):
        with self.assertRaises(ServiceException):
            annotations_methods.create_annotation(self.test_user, 42, test_json)
            rpc_methods.create_annotation(self.test_user, 42, test_json)

        res = models.Resource.objects.create(
            title="test res", ptr_project=self.test_project
        )
        serialized_annotation = annotations_methods.create_annotation(
        serialized_annotation = rpc_methods.create_annotation(
            self.test_user, res.pk, test_json
        )
        self.assertEqual(serialized_annotation.get("data"), test_json)

    def test_delete_annotation(self):
        with self.assertRaises(ServiceException):
            annotations_methods.delete_annotation(self.test_user, 42)
            rpc_methods.delete_annotation(self.test_user, 42)
        res = models.Resource.objects.create(
            title="test res", ptr_project=self.test_project
        )
        serialized_annotation = annotations_methods.create_annotation(
        serialized_annotation = rpc_methods.create_annotation(
            self.test_user, res.pk, test_json
        )
        # not owner
        with self.assertRaises(ServiceException):
            annotations_methods.delete_annotation(
            rpc_methods.delete_annotation(
                self.admin_user, serialized_annotation.get("id")
            )
        self.assertTrue(
            annotations_methods.delete_annotation(
            rpc_methods.delete_annotation(
                self.test_user, serialized_annotation.get("id")
            )
        )
@@ -97,19 +95,19 @@ class AnnotationTestCase(TestCase):
        res = models.Resource.objects.create(
            title="test res", ptr_project=self.test_project
        )
        annotations_methods.create_annotation(self.test_user, res.pk, test_json)
        annotations_methods.create_annotation(self.test_user, res.pk, test_json)
        list = annotations_methods.list_annotations(self.test_user, res.pk)
        rpc_methods.create_annotation(self.test_user, res.pk, test_json)
        rpc_methods.create_annotation(self.test_user, res.pk, test_json)
        list = rpc_methods.list_annotations(self.test_user, res.pk)
        self.assertEqual(len(list), 2)

    def test_update_annotation(self):
        res = models.Resource.objects.create(
            title="test res", ptr_project=self.test_project
        )
        serialized_annotation = annotations_methods.create_annotation(
        serialized_annotation = rpc_methods.create_annotation(
            self.test_user, res.pk, test_json
        )
        annotations_methods.update_annotation(
        rpc_methods.update_annotation(
            self.test_user, serialized_annotation.get("id"), {"something": "else"}
        )
        fetched_annotation = Annotation.objects.get(pk=serialized_annotation.get("id"))