Ejemplo n.º 1
0
 def retrieve_agent_profile(self, agent, profile_id):
     """Retrieve agent profile with the specified parameters
     :param agent: Agent object of the desired agent profile
     :type agent: :class:`tincan.agent.Agent`
     :param profile_id: UUID of the desired agent profile
     :type profile_id: str | unicode
     :return: LRS Response object with an agent profile doc as content
     :rtype: :class:`tincan.lrs_response.LRSResponse`
     """
     if not isinstance(agent, Agent):
         agent = Agent(agent)
     request = HTTPRequest(method="GET",
                           resource="agents/profile",
                           ignore404=True)
     request.query_params = {
         "profileId": profile_id,
         "agent": agent.to_json(self.version)
     }
     lrs_response = self._send_request(request)
     if lrs_response.success:
         doc = AgentProfileDocument(id=profile_id,
                                    content=lrs_response.data,
                                    agent=agent)
         headers = lrs_response.response.getheaders()
         if "lastModified" in headers and headers[
                 "lastModified"] is not None:
             doc.timestamp = headers["lastModified"]
         if "contentType" in headers and headers["contentType"] is not None:
             doc.content_type = headers["contentType"]
         if "etag" in headers and headers["etag"] is not None:
             doc.etag = headers["etag"]
         lrs_response.content = doc
     return lrs_response
Ejemplo n.º 2
0
    def retrieve_agent_profile(self, agent, profile_id):
        """Retrieve agent profile with the specified parameters

        :param agent: Agent object of the desired agent profile
        :type agent: :class:`tincan.agent.Agent`
        :param profile_id: UUID of the desired agent profile
        :type profile_id: str | unicode
        :return: LRS Response object with an agent profile doc as content
        :rtype: :class:`tincan.lrs_response.LRSResponse`
        """
        if not isinstance(agent, Agent):
            agent = Agent(agent)

        request = HTTPRequest(
            method="GET",
            resource="agents/profile",
            ignore404=True
        )
        request.query_params = {
            "profileId": profile_id,
            "agent": agent.to_json(self.version)
        }

        lrs_response = self._send_request(request)

        if lrs_response.success:
            doc = AgentProfileDocument(
                id=profile_id,
                content=lrs_response.data,
                agent=agent
            )
            headers = lrs_response.response.getheaders()
            if "lastModified" in headers and headers["lastModified"] is not None:
                doc.timestamp = headers["lastModified"]
            if "contentType" in headers and headers["contentType"] is not None:
                doc.content_type = headers["contentType"]
            if "etag" in headers and headers["etag"] is not None:
                doc.etag = headers["etag"]

            lrs_response.content = doc

        return lrs_response
Ejemplo n.º 3
0
    def test_save_agent_profile(self):
        doc = AgentProfileDocument(agent=self.agent,
                                   id="test",
                                   content="Test value")
        saveResp = self.lrs.save_agent_profile(doc)
        self.assertIsInstance(saveResp, LRSResponse)
        self.assertTrue(saveResp.success)

        response = self.lrs.retrieve_agent_profile(agent=self.agent,
                                                   profile_id="test")
        self.assertIsInstance(response, LRSResponse)
        self.assertTrue(response.success)
        self._vars_verifier(response.content, doc)
Ejemplo n.º 4
0
    def test_delete_agent_profile(self):
        doc = AgentProfileDocument(agent=self.agent, id="test")
        response = self.lrs.delete_agent_profile(doc)

        self.assertIsInstance(response, LRSResponse)
        self.assertTrue(response.success)