예제 #1
0
    def test_get_obj(self):
        """
        Method should raise NotImplementedError in the ApiBase class.
        """
        request = testing.DummyRequest()

        # create a direct instance of ApiBase
        api = ApiBase(request)
        with self.assertRaises(NotImplementedError):
            api.get_obj(1)
예제 #2
0
    def test_dehydrate(self):
        """
        Dehydrate doesn't really do anything in the ApiBase class,
        it just returns the original object as-is.
        """
        request = testing.DummyRequest()
        api = ApiBase(request)

        test_obj = Mock()
        bundle = Bundle(obj=test_obj, request=request)
        dehydrated = api.dehydrate(bundle)

        # they should be the same objects
        self.assertEqual(bundle, dehydrated)
예제 #3
0
    def test_build_bundle(self):
        """
        Should construct a bundle object.
        """
        # some test data
        request = testing.DummyRequest()
        data = {'id': 1, 'name': 'admin'}

        # calling build_bundle with an object
        obj = Mock()
        api = ApiBase(request)
        bundle = api.build_bundle(obj=obj, data=data)
        self.assertEqual(bundle.resource, api)
        self.assertEqual(bundle.request, request)
        self.assertEqual(bundle.data, data)
        self.assertEqual(bundle.obj, obj)   # should use obj

        # calling build_bundle without an object
        bundle = api.build_bundle(data=data)
        self.assertEqual(bundle.resource, api)
        self.assertEqual(bundle.request, request)
        self.assertEqual(bundle.data, data)