Example #1
0
    def test_read_write_hyperlinked_collection_property(self):
        request = Request(make_dummy_request())
        request._user = User(is_superuser=True)

        context = {'request': request}
        serializer = ProjectSerializer(self.project, context=context)

        field = serializer.get_fields()['notes']
        property_serializer = HydraPropertySerializer(field,
                                                      'notes',
                                                      'projectns:',
                                                      self.project,
                                                      context=context)

        supported_operations = property_serializer.data\
            .get('property')\
            .get('hydra:supportedOperation')

        self.assertEqual(len(supported_operations), 2)

        create_operation, = filter(lambda op: op.get('hydra:method') == 'POST',
                                   supported_operations)

        self.assertDictEqual(
            dict(create_operation), {
                '@id': '_:project_note_create',
                '@type': 'hydra:CreateResourceOperation',
                'label': 'Create a note for this project.',
                'description': None,
                'hydra:method': 'POST',
                'hydra:expects': 'projectns:Note',
                'hydra:returns': 'projectns:Note',
                'hydra:possibleStatus': []
            })
Example #2
0
    def test_read_write_hyperlinked_collection_property(self):
        request = Request(make_dummy_request())
        request._user = User(username='******', is_superuser=True)

        context = {'request': request}
        serializer = ProjectSerializer(self.project, context=context)

        field = serializer.get_fields()['notes']
        property_serializer = HydraPropertySerializer(
            field, 'notes',
            'projectns:',
            self.project,
            context=context
        )

        supported_operations = property_serializer.data\
            .get('property')\
            .get('hydra:supportedOperation')

        self.assertEqual(len(supported_operations), 2)

        create_operation, = filter(lambda op: op.get('hydra:method') == 'POST',
                                   supported_operations)

        self.assertDictEqual(dict(create_operation), {
            '@id': '_:project_note_create',
            '@type': 'hydra:CreateResourceOperation',
            'label': 'Create a note for this project.',
            'description': None,
            'hydra:method': 'POST',
            'hydra:expects': 'projectns:Note',
            'hydra:returns': 'projectns:Note',
            'hydra:possibleStatus': []
        })
Example #3
0
    def test_read_write_hyperlinked_collection_property(self):
        request = Request(make_dummy_request())
        request._user = User(is_superuser=True)

        context = {"request": request}
        serializer = ProjectSerializer(self.project, context=context)

        field = serializer.get_fields()["notes"]
        property_serializer = HydraPropertySerializer(field, "notes", "projectns:", self.project, context=context)

        supported_operations = property_serializer.data.get("property").get("hydra:supportedOperation")

        self.assertEqual(len(supported_operations), 2)

        create_operation, = [op for op in supported_operations if op.get("hydra:method") == "POST"]

        self.assertDictEqual(
            dict(create_operation),
            {
                "@id": "_:project_note_create",
                "@type": "hydra:CreateResourceOperation",
                "label": "Create a note for this project.",
                "description": None,
                "hydra:method": "POST",
                "hydra:expects": "projectns:Note",
                "hydra:returns": "projectns:Note",
                "hydra:possibleStatus": [],
            },
        )