Пример #1
0
 def read(self, request):
     profile = request.user.userprofile
     if 'provider' in profile.get_current_roles():
         try:
             response = get_provider_resources(request.user)
         except Exception, e:
             return build_response(request, 400, e.message)
Пример #2
0
    def read(self, request):

        pagination = {
            'start': request.GET.get('start', None),
            'limit': request.GET.get('limit', None)
        }
        if pagination['start'] == None or pagination['limit'] == None:
            pagination = None

        profile = request.user.userprofile
        filter_ = request.GET.get('open', None)

        if filter_ and filter_ != 'true' and filter_ != 'false':
            return build_response(request, 400, 'Invalid open param')

        open_res = None
        if filter_ is not None:
            open_res = False

            if filter_ == 'true':
                open_res = True

        if 'provider' in profile.get_current_roles():
            try:
                response = get_provider_resources(request.user, filter_=open_res, pagination=pagination)
            except Exception, e:
                return build_response(request, 400, e.message)
Пример #3
0
    def read(self, request):

        profile = request.user.userprofile
        filter_ = request.GET.get('open', None)

        if filter_ and filter_ != 'true' and filter_ != 'false':
            return build_response(request, 400, 'Invalid open param')

        if 'provider' in profile.get_current_roles():
            try:
                response = get_provider_resources(request.user, filter_=filter_)
            except Exception, e:
                return build_response(request, 400, e.message)
Пример #4
0
    def test_resource_retrieving(self, expected_result, filter_=None):

        # Call the method
        error = False
        try:
            result = resources_management.get_provider_resources(self.user, filter_)
        except:
            error = True

        # Assert that no error occurs
        self.assertFalse(error)

        # Check calls
        resources_management.Resource.objects.filter.assert_called_once_with(provider=self.org)
        # Check result
        self.assertEquals(result, expected_result)
Пример #5
0
    def test_resource_retrieving(self, expected_result, filter_=None, pagination=None, err_type=None, err_msg=None):

        # Call the method
        error = None
        try:
            result = resources_management.get_provider_resources(self.user, filter_, pagination)
        except Exception as e:
            error = e

        if not err_type:
            # Assert that no error occurs
            self.assertEquals(error, None)
            # Check result
            self.assertEquals(result, expected_result)
        else:
            self.assertTrue(isinstance(error, err_type))
            self.assertEquals(unicode(e), err_msg)
Пример #6
0
    def test_resource_retrieving(self,
                                 expected_result,
                                 filter_=None,
                                 pagination=None,
                                 err_type=None,
                                 err_msg=None):

        # Call the method
        error = None
        try:
            result = resources_management.get_provider_resources(
                self.user, filter_, pagination)
        except Exception as e:
            error = e

        if not err_type:
            # Assert that no error occurs
            self.assertEquals(error, None)
            # Check result
            self.assertEquals(result, expected_result)
        else:
            self.assertTrue(isinstance(error, err_type))
            self.assertEquals(unicode(e), err_msg)