Exemplo n.º 1
0
 def get_service_instance(self, class_name, instance_id):
     class_obj = self.class_dao.find(class_name)
     if class_obj:
         instance = self.instance_dao.find(instance_id)
         if instance:
             if instance['class_name'] == class_name:
                 return instance
             else:
                 raise UnsupportedParameterValueException(
                     '{0}-{1}'.format(class_name, instance_id),
                     'instances-of-class')
         else:
             raise NotFoundException(instance_id)
     else:
         raise NotFoundException(class_name)
Exemplo n.º 2
0
 def discover_service_instances(self, class_name, params):
     if 'class_name' in params:
         raise BadParameterException('class_name')
     class_obj = self.class_dao.find(class_name)
     if not class_obj:
         raise NotFoundException(class_name)
     params['class_name'] = class_name
     return self.instance_dao.find_instances(params)
Exemplo n.º 3
0
 def wrapper(*args, **kwargs):
     obj = f(*args, **kwargs)
     if not obj:
         resource = ''
         if len(args) > 1:
             resource = args[1]
         raise NotFoundException(resource)
     return obj
Exemplo n.º 4
0
 def delete(self, class_name, instance_id):
     class_obj = self.class_dao.find(class_name)
     if class_obj:
         instance = self.instance_dao.find(instance_id)
         if instance:
             if instance['class_name'] == class_name:
                 if self.instance_dao.delete(instance_id):
                     return
                 else:
                     raise GenericServiceError(
                         'The instance delete process failed.')
             else:
                 raise UnsupportedParameterValueException(
                     '{0}-{1}'.format(class_name, instance_id),
                     'instances-of-class')
         else:
             raise NotFoundException(instance_id)
     raise NotFoundException(class_name)
Exemplo n.º 5
0
 def create_binding(self, binding):
     if not self.class_dao.find(binding['class_name']):
         raise NotFoundException(binding['class_name'])
     try:
         self.check_binding_rules_in_class(binding)
         return self.binding_dao.create(binding)
     except DuplicateKeyError:
         raise UnsupportedParameterValueException(
             '{0}-{1}'.format(binding['class_name'], binding['origin']),
             'non-duplicated-origin')
Exemplo n.º 6
0
 def create(self, obj):
     if not self.class_dao.find(obj['class_name']):
         raise NotFoundException(obj['class_name'])
     try:
         return self.instance_dao.create(obj)
     except DuplicateKeyError:
         raise UnsupportedParameterValueException(
             '{0}-{1}-{2}'.format(obj['class_name'], obj['uri'],
                                  obj['version']),
             'non-duplicated-instance')
Exemplo n.º 7
0
    def delete(self, class_name):
        class_obj = self.class_dao.find(class_name)
        if class_obj:
            try:
                self.instance_dao.delete_by_class_name(class_name)
            except OperationFailure:
                raise GenericServiceError('The class delete process failed.')
            if self.class_dao.delete(class_name):
                return
            else:
                raise GenericServiceError('The class delete process failed.')

        raise NotFoundException(class_name)
Exemplo n.º 8
0
 def update_binding(self, binding):
     if not self.class_dao.find(binding['class_name']):
         raise NotFoundException(binding['class_name'])
     # if not binding is found, not found is already launched in serializers
     try:
         self.check_binding_rules_in_class(binding)
         if self.binding_dao.update_binding(binding):
             return binding
         else:
             raise GenericServiceError('The binding update process failed.')
     except DuplicateKeyError:
         raise UnsupportedParameterValueException(
             '{0}-{1}'.format(binding['class_name'], binding['origin']),
             'non-duplicated-origin')
    def test_init_basic_authentication_no_user_created_should_create_user(self):

        Singleton._instances.pop(BasicMongoAuthentication, None)
        with nested(
             patch('users.authentication.UserAdminService'),
             patch('users.authentication.logger')) as(mock_user_admin, mock_logger):
            user_admin_instance = MagicMock(name='user_admin_instance')
            mock_user_admin.return_value = user_admin_instance
            user_admin_instance.get_user.side_effect = NotFoundException('not found')
            BasicMongoAuthentication()
            self.assertEquals(0, mock_logger.error.call_count, 'error log generated and it shouldn')
            user_admin_instance.get_user.assert_called_once_with('admin')
            user_expected = DictMatcher({'_id': 'admin', 'password': '******', 'is_admin': True}, [])
            user_admin_instance.create.assert_called_once_with(user_expected)
Exemplo n.º 10
0
def handle_default_404(request):
    """
    Generic function basede view for deal with default 404 error
    launched by django (mainly url path not found)
    """

    # Exception Mapper.
    exc_info = ExceptionMapper().get_exception_info(
        NotFoundException(request.path))
    exc_data = {
        'exceptionId': exc_info['code'],
        'exceptionText': exc_info['details']
    }
    return HttpResponse(content=dumps(exc_data),
                        mimetype='application/json',
                        status=exc_info['status_code'])
Exemplo n.º 11
0
    def get_binding_instance(self, params):
        try:
            class_name = params.pop('class_name')
        except KeyError:
            raise MissingMandatoryParameterException('class_name')

        class_ = self.class_dao.find(class_name)
        if not class_:
            raise NotFoundException(class_name)

        origin = params.get('origin', 'default')
        binding = self.binding_dao.find_by_class_and_origin(class_name, origin)
        if binding is None:  # when rules are null in database
            rules = ()
        else:
            rules = binding['binding_rules']

        # perform the binding_instance operation
        if rules:
            binding_instances = self.get_binding_instances_by_rules(
                rules, params)
            if binding_instances is None:
                raise NotMatchingRuleException(class_name, origin)
            else:
                # Although we only return one binding_instance, in future this can deal
                # with several bindings and return the first binding alive
                if len(binding_instances) == 0:
                    raise NotBindingInstanceException(class_name, origin)
                binding_instance = self.instance_dao.find(binding_instances[0])
                if binding_instance:
                    return binding_instance
                else:
                    raise DeletedInstanceException(binding_instances[0])
        else:
            # No rules defined for the search
            raise NotBindingDefinedException(class_name, origin)