Esempio n. 1
0
    def test_make_response_with_errors(self):
        """
        """
        session = GASession(garuda_uuid='xxx-xxx-xxx-xxx')
        request = GARequest(action=GARequest.ACTION_READ)
        context = GAContext(session=session, request=request)

        error1 = GAError(type=GAError.TYPE_INVALID,
                         title='title1',
                         description='description2',
                         suggestion='nope',
                         property_name='prop1')
        error2 = GAError(type=GAError.TYPE_CONFLICT,
                         title='title2',
                         description='description3',
                         suggestion='nope',
                         property_name='prop2')
        error3 = GAError(type=GAError.TYPE_NOTFOUND,
                         title='title3',
                         description='description4',
                         suggestion='nope',
                         property_name='prop3')
        context.add_errors([error1, error2, error3])

        response = context.make_response()

        self.assertEquals(response.__class__, GAResponseFailure)
        self.assertEquals(response.content, [error1, error2, error3])
Esempio n. 2
0
    def test_make_response_for_assign(self):
        """
        """
        session = GASession(garuda_uuid='xxx-xxx-xxx-xxx')
        request = GARequest(action=GARequest.ACTION_ASSIGN)
        context = GAContext(session=session, request=request)

        enterprise1 = tstdk.GAEnterprise(name='enterprise1')
        context.object = enterprise1

        response = context.make_response()

        self.assertEquals(response.__class__, GAResponseSuccess)
        self.assertEquals(response.content, enterprise1)
Esempio n. 3
0
    def test_make_response_for_assign(self):
        """
        """
        session = GASession(garuda_uuid='xxx-xxx-xxx-xxx')
        request = GARequest(action=GARequest.ACTION_ASSIGN)
        context = GAContext(session=session, request=request)

        enterprise1 = tstdk.GAEnterprise(name='enterprise1')
        context.object = enterprise1

        response = context.make_response()

        self.assertEquals(response.__class__, GAResponseSuccess)
        self.assertEquals(response.content, enterprise1)
Esempio n. 4
0
    def test_make_response_for_read_all(self):
        """
        """
        session = GASession(garuda_uuid='xxx-xxx-xxx-xxx')
        request = GARequest(action=GARequest.ACTION_READALL)
        context = GAContext(session=session, request=request)

        enterprise1 = tstdk.GAEnterprise(name='enterprise1')
        enterprise2 = tstdk.GAEnterprise(name='enterprise2')
        context.objects = [enterprise1, enterprise2]

        response = context.make_response()

        self.assertEquals(response.__class__, GAResponseSuccess)
        self.assertEquals(response.content, [enterprise1, enterprise2])
Esempio n. 5
0
    def test_make_response_for_read_all(self):
        """
        """
        session = GASession(garuda_uuid='xxx-xxx-xxx-xxx')
        request = GARequest(action=GARequest.ACTION_READALL)
        context = GAContext(session=session, request=request)

        enterprise1 = tstdk.GAEnterprise(name='enterprise1')
        enterprise2 = tstdk.GAEnterprise(name='enterprise2')
        context.objects = [enterprise1, enterprise2]

        response = context.make_response()

        self.assertEquals(response.__class__, GAResponseSuccess)
        self.assertEquals(response.content, [enterprise1, enterprise2])
Esempio n. 6
0
    def execute_model_request(self, request):
        """
        """
        session_uuid = self.sessions_controller.extract_session_identifier(
            request=request)
        session = None

        logger.debug("finding session: %s" % session_uuid)
        if session_uuid:
            session = self.sessions_controller.get_session(
                session_uuid=session_uuid)

        if not session:
            session = self.sessions_controller.create_session(request=request)

            if session:
                return GAResponseSuccess(content=[session.root_object])

        context = GAContext(session=session, request=request)

        if not session:
            error = GAError(
                type=GAError.TYPE_UNAUTHORIZED,
                title='Unauthorized access',
                description='Could not grant access. Please log in.')

            context.add_error(error)

            return GAResponseFailure(content=context.errors)

        # reset the session ttl
        self.sessions_controller.reset_session_ttl(session)

        logger.debug('Execute action %s on session UUID=%s' %
                     (request.action, session_uuid))

        operations_controller = GAOperationsController(
            context=context,
            logic_controller=self.logic_controller,
            storage_controller=self.storage_controller)
        operations_controller.run()

        response = context.make_response()

        if len(context.events) > 0:  # pragma: no cover
            self.push_controller.push_events(events=context.events)

        return response
Esempio n. 7
0
    def test_make_response_with_errors(self):
        """
        """
        session = GASession(garuda_uuid='xxx-xxx-xxx-xxx')
        request = GARequest(action=GARequest.ACTION_READ)
        context = GAContext(session=session, request=request)

        error1 = GAError(type=GAError.TYPE_INVALID, title='title1', description='description2', suggestion='nope', property_name='prop1')
        error2 = GAError(type=GAError.TYPE_CONFLICT, title='title2', description='description3', suggestion='nope', property_name='prop2')
        error3 = GAError(type=GAError.TYPE_NOTFOUND, title='title3', description='description4', suggestion='nope', property_name='prop3')
        context.add_errors([error1, error2, error3])

        response = context.make_response()

        self.assertEquals(response.__class__, GAResponseFailure)
        self.assertEquals(response.content, [error1, error2, error3])
Esempio n. 8
0
    def execute_model_request(self, request):
        """
        """
        session_uuid = self.sessions_controller.extract_session_identifier(request=request)
        session = None

        logger.debug("finding session: %s" % session_uuid)
        if session_uuid:
            session = self.sessions_controller.get_session(session_uuid=session_uuid)

        if not session:
            session = self.sessions_controller.create_session(request=request)

            if session:
                return GAResponseSuccess(content=[session.root_object])

        context = GAContext(session=session, request=request)

        if not session:
            error = GAError(type=GAError.TYPE_UNAUTHORIZED,
                            title='Unauthorized access',
                            description='Could not grant access. Please log in.')

            context.add_error(error)

            return GAResponseFailure(content=context.errors)

        # reset the session ttl
        self.sessions_controller.reset_session_ttl(session)

        logger.debug('Execute action %s on session UUID=%s' % (request.action, session_uuid))

        operations_controller = GAOperationsController(context=context, logic_controller=self.logic_controller, storage_controller=self.storage_controller)
        operations_controller.run()

        response = context.make_response()

        if len(context.events) > 0:  # pragma: no cover
            self.push_controller.push_events(events=context.events)

        return response