Beispiel #1
0
    def test_dehydrate_resources(self):
        obj = BaseResource(resolwe=self.resolwe_mock, id=1)

        self.assertEqual(obj._dehydrate_resources(obj), 1)
        self.assertEqual(obj._dehydrate_resources([obj]), [1])
        self.assertEqual(obj._dehydrate_resources({'key': obj}), {'key': 1})
        self.assertEqual(obj._dehydrate_resources({'key': [obj]}), {'key': [1]})
Beispiel #2
0
    def test_dehydrate_resources(self):
        obj = BaseResource(resolwe=self.resolwe_mock, id=1)
        obj2 = DescriptorSchema(resolwe=self.resolwe_mock, slug='foo', id=2)

        self.assertEqual(obj._dehydrate_resources(obj), {'id': 1})
        self.assertEqual(obj._dehydrate_resources([obj]), [{'id': 1}])
        self.assertEqual(obj._dehydrate_resources({'key': obj}),
                         {'key': {
                             'id': 1
                         }})
        self.assertEqual(obj._dehydrate_resources({'key': [obj]}),
                         {'key': [{
                             'id': 1
                         }]})

        self.assertEqual(obj._dehydrate_resources(obj2), {'id': 2})
        self.assertEqual(obj._dehydrate_resources([obj2]), [{'id': 2}])
        self.assertEqual(obj._dehydrate_resources({'key': obj2}),
                         {'key': {
                             'id': 2
                         }})
        self.assertEqual(obj._dehydrate_resources({'key': [obj2]}),
                         {'key': [{
                             'id': 2
                         }]})

        # Imitate creation (obj.id=None) - resource has to be given by slug
        obj = BaseResource(resolwe=self.resolwe_mock, id=None)
        self.assertEqual(obj._dehydrate_resources(obj2), {'slug': 'foo'})
Beispiel #3
0
    def test_dehydrate_resources(self):
        obj = BaseResource(resolwe=self.resolwe_mock, id=1)
        obj2 = DescriptorSchema(resolwe=self.resolwe_mock, slug="foo", id=2)

        self.assertEqual(obj._dehydrate_resources(obj), {"id": 1})
        self.assertEqual(obj._dehydrate_resources([obj]), [{"id": 1}])
        self.assertEqual(obj._dehydrate_resources({"key": obj}),
                         {"key": {
                             "id": 1
                         }})
        self.assertEqual(obj._dehydrate_resources({"key": [obj]}),
                         {"key": [{
                             "id": 1
                         }]})

        self.assertEqual(obj._dehydrate_resources(obj2), {"id": 2})
        self.assertEqual(obj._dehydrate_resources([obj2]), [{"id": 2}])
        self.assertEqual(obj._dehydrate_resources({"key": obj2}),
                         {"key": {
                             "id": 2
                         }})
        self.assertEqual(obj._dehydrate_resources({"key": [obj2]}),
                         {"key": [{
                             "id": 2
                         }]})

        # Imitate creation (obj.id=None) - resource has to be given by slug
        obj = BaseResource(resolwe=self.resolwe_mock, id=None)
        self.assertEqual(obj._dehydrate_resources(obj2), {"slug": "foo"})
    def test_dehydrate_resources(self):
        obj = BaseResource(resolwe=self.resolwe_mock, id=1)
        obj2 = DescriptorSchema(resolwe=self.resolwe_mock, slug='foo')

        self.assertEqual(obj._dehydrate_resources(obj), 1)
        self.assertEqual(obj._dehydrate_resources([obj]), [1])
        self.assertEqual(obj._dehydrate_resources({'key': obj}), {'key': 1})
        self.assertEqual(obj._dehydrate_resources({'key': [obj]}), {'key': [1]})

        self.assertEqual(obj._dehydrate_resources(obj2), 'foo')
        self.assertEqual(obj._dehydrate_resources([obj2]), ['foo'])
        self.assertEqual(obj._dehydrate_resources({'key': obj2}), {'key': 'foo'})
        self.assertEqual(obj._dehydrate_resources({'key': [obj2]}), {'key': ['foo']})
    def test_dehydrate_resources(self):
        obj = BaseResource(resolwe=self.resolwe_mock, id=1)
        obj2 = DescriptorSchema(resolwe=self.resolwe_mock, slug='foo')

        self.assertEqual(obj._dehydrate_resources(obj), 1)
        self.assertEqual(obj._dehydrate_resources([obj]), [1])
        self.assertEqual(obj._dehydrate_resources({'key': obj}), {'key': 1})
        self.assertEqual(obj._dehydrate_resources({'key': [obj]}),
                         {'key': [1]})

        self.assertEqual(obj._dehydrate_resources(obj2), 'foo')
        self.assertEqual(obj._dehydrate_resources([obj2]), ['foo'])
        self.assertEqual(obj._dehydrate_resources({'key': obj2}),
                         {'key': 'foo'})
        self.assertEqual(obj._dehydrate_resources({'key': [obj2]}),
                         {'key': ['foo']})