Ejemplo n.º 1
0
    def save_statement(self, statement):
        """Save statement to LRS and update statement id if necessary

        :param statement: Statement object to be saved
        :type statement: :class:`tincan.statement.Statement`
        :return: LRS Response object with the saved statement as content
        :rtype: :class:`tincan.lrs_response.LRSResponse`
        """
        if not isinstance(statement, Statement):
            statement = Statement(statement)

        request = HTTPRequest(method="POST", resource="statements")
        if statement.id is not None:
            request.method = "PUT"
            request.query_params["statementId"] = statement.id

        request.headers["Content-Type"] = "application/json"
        request.content = statement.to_json(self.version)

        lrs_response = self._send_request(request)

        if lrs_response.success:
            if statement.id is None:
                statement.id = json.loads(lrs_response.data)[0]
            lrs_response.content = statement

        return lrs_response
Ejemplo n.º 2
0
    def save_statement(self, statement):
        """Save statement to LRS and update statement id if necessary

        :param statement: Statement object to be saved
        :type statement: :class:`tincan.statement.Statement`
        :return: LRS Response object with the saved statement as content
        :rtype: :class:`tincan.lrs_response.LRSResponse`
        """
        if not isinstance(statement, Statement):
            statement = Statement(statement)

        request = HTTPRequest(
            method="POST",
            resource="statements"
        )
        if statement.id is not None:
            request.method = "PUT"
            request.query_params["statementId"] = statement.id

        request.headers["Content-Type"] = "application/json"
        request.content = statement.to_json(self.version)

        lrs_response = self._send_request(request)

        if lrs_response.success:
            if statement.id is None:
                statement.id = json.loads(lrs_response.data)[0]
            lrs_response.content = statement

        return lrs_response
 def test_with_non_dict_event(self):
     RouterConfigurationFactory.create(
         backend_name=RouterConfiguration.XAPI_BACKEND,
         enabled=True,
         route_url='http://test3.com',
         configurations=ROUTER_CONFIG_FIXTURE[3])
     router = EventsRouter(processors=[],
                           backend_name=RouterConfiguration.XAPI_BACKEND)
     transformed_event = Statement()
     with self.assertRaises(ValueError):
         router.send(transformed_event)
Ejemplo n.º 4
0
 def retrieve_voided_statement(self, statement_id):
     """Retrieve a voided statement from the server from its id
     :param statement_id: The UUID of the desired voided statement
     :type statement_id: str | unicode
     :return: LRS Response object with the retrieved voided statement as content
     :rtype: :class:`tincan.lrs_response.LRSResponse`
     """
     request = HTTPRequest(method="GET", resource="statements")
     request.query_params["voidedStatementId"] = statement_id
     lrs_response = self._send_request(request)
     if lrs_response.success:
         lrs_response.content = Statement.from_json(lrs_response.data)
     return lrs_response
Ejemplo n.º 5
0
    def retrieve_voided_statement(self, statement_id):
        """Retrieve a voided statement from the server from its id

        :param statement_id: The UUID of the desired voided statement
        :type statement_id: str | unicode
        :return: LRS Response object with the retrieved voided statement as content
        :rtype: :class:`tincan.lrs_response.LRSResponse`
        """
        request = HTTPRequest(
            method="GET",
            resource="statements"
        )
        request.query_params["voidedStatementId"] = statement_id

        lrs_response = self._send_request(request)

        if lrs_response.success:
            lrs_response.content = Statement.from_json(lrs_response.data)

        return lrs_response