コード例 #1
0
ファイル: accessors_test.py プロジェクト: mhawthorne/antonym
 def _test_delete(self):
     self.moxer.StubOutWithMock(ArtifactInfo, "get_by_guid", use_mock_anything=True)
     self.moxer.StubOutWithMock(ArtifactContent, "get_by_guid", use_mock_anything=True)
     
     guid = 'blah'
     ArtifactInfo.get_by_guid(guid).AndReturn(MockEntity(MockKey(name=guid)))
     ArtifactContent.get_by_guid(guid).AndReturn(MockEntity(MockKey(name=guid)))
     
     self.moxer.ReplayAll()
     ArtifactAccessor.delete(guid)
     self.moxer.VerifyAll()
コード例 #2
0
ファイル: accessors_test.py プロジェクト: mhawthorne/antonym
 def test_delete_nonexistent(self):
     self.moxer.StubOutWithMock(ArtifactInfo, "get_by_guid", use_mock_anything=True)
     self.moxer.StubOutWithMock(ArtifactContent, "get_by_guid", use_mock_anything=True)
     
     guid = 'blah'
     ArtifactInfo.get_by_guid(guid)
     ArtifactContent.get_by_guid(guid)
     
     self.moxer.ReplayAll()
     try:
         ArtifactAccessor.delete(guid)
         self.fail("exception expected")
     except NotFoundException, ex:
         pass
コード例 #3
0
ファイル: artifacts.py プロジェクト: mhawthorne/antonym
    def get(self, **kw):
        helper = RequestHelper(self)
        q = self.request.get("q", None)
        output = self.request.get("o", None)
        max_results = int(self.request.get("max", -1))
        
        if not q:
            helper.error(400, "q not provided.")
            return

        q_results = ArtifactContent.all().search(q)

        json_results = None
        if output == "short":
            json_results = {}
            json_results["count"] = q_results.count()
        elif output == "id":
            json_results = {}
            count = q_results.count()
            if max_results > 0 and max_results < q_results.count():
                count = max_results
                
            json_results["count"] = count
            ids = []
            json_results["ids"] = ids
            results = q_results.fetch(1000) if max_results == -1 else q_results.fetch(max_results)
            for c in results:
                ids.append(c.guid)
        else:
            json_results = []
            if q_results.count():
                for content in q_results.fetch(10):
                    info = ArtifactInfo.get_by_guid(content.guid)
                    json_results.append(ArtifactsHelper.artifact_to_hash(info, content))
        helper.write_json(json_results)
コード例 #4
0
    def _test_delete(self):
        self.moxer.StubOutWithMock(ArtifactInfo,
                                   "get_by_guid",
                                   use_mock_anything=True)
        self.moxer.StubOutWithMock(ArtifactContent,
                                   "get_by_guid",
                                   use_mock_anything=True)

        guid = 'blah'
        ArtifactInfo.get_by_guid(guid).AndReturn(MockEntity(
            MockKey(name=guid)))
        ArtifactContent.get_by_guid(guid).AndReturn(
            MockEntity(MockKey(name=guid)))

        self.moxer.ReplayAll()
        ArtifactAccessor.delete(guid)
        self.moxer.VerifyAll()
コード例 #5
0
    def test_delete_nonexistent(self):
        self.moxer.StubOutWithMock(ArtifactInfo,
                                   "get_by_guid",
                                   use_mock_anything=True)
        self.moxer.StubOutWithMock(ArtifactContent,
                                   "get_by_guid",
                                   use_mock_anything=True)

        guid = 'blah'
        ArtifactInfo.get_by_guid(guid)
        ArtifactContent.get_by_guid(guid)

        self.moxer.ReplayAll()
        try:
            ArtifactAccessor.delete(guid)
            self.fail("exception expected")
        except NotFoundException, ex:
            pass
コード例 #6
0
ファイル: artifacts.py プロジェクト: mhawthorne/antonym
 def get(cls, rhandler, guid, **kw):
     helper = RequestHelper(rhandler)
     
     artifact_info = ArtifactInfo.get_by_guid(guid)
     artifact_content = ArtifactContent.get_by_guid(guid)
     if artifact_info and artifact_content:
         artifact_hash = ArtifactsHelper.artifact_to_hash(artifact_info, artifact_content)
         helper.write_json(artifact_hash)
     else:
         helper.error(404)
コード例 #7
0
ファイル: artifacts.py プロジェクト: mhawthorne/antonym
 def put(cls, rhandler, guid, **kw):
     helper = RequestHelper(rhandler)
     
     artifact = ArtifactInfo.get_by_guid(guid)
     if not artifact:
         helper.error(404)
         return
         
     # removes existing properties
     props = ArtifactInfo.properties().keys()
     for prop in props:
         delattr(artifact, prop)
     
     # save artifact
     ArtifactInfo.save(artifact)
コード例 #8
0
ファイル: accessors.py プロジェクト: mhawthorne/antonym
    def delete(cls, guid):
        logger = LoggerFactory.logger(cls.__name__)

        a_info = ArtifactInfo.get_by_guid(guid)
        a_content_key = ArtifactContent.get_by_guid(guid)
        if not (a_info or a_content_key):
            # neither record found
            raise NotFoundException("artifact %s" % guid)
        elif not (a_info and a_content_key):
            # one record found; one missing
            logger.warn("artifact %s; missing data; info=%s; content=%s" %
                        (guid, a_info.key().name(), a_content_key))

        # I delete what I can
        keys = []
        if a_info: keys.append(a_info)
        if a_content_key: keys.append(a_content_key)

        db.delete(keys)

        # decrease source counter
        Counters.source_counter(a_info.source.name).decrement()
コード例 #9
0
ファイル: accessors.py プロジェクト: mhawthorne/antonym
    def delete(cls, guid):
        logger = LoggerFactory.logger(cls.__name__)

        a_info = ArtifactInfo.get_by_guid(guid)
        a_content_key = ArtifactContent.get_by_guid(guid)
        if not (a_info or a_content_key):
            # neither record found
            raise NotFoundException("artifact %s" % guid)
        elif not (a_info and a_content_key):
            # one record found; one missing
            logger.warn("artifact %s; missing data; info=%s; content=%s" % (guid, a_info.key().name(), a_content_key))

        # I delete what I can
        keys = []
        if a_info:
            keys.append(a_info)
        if a_content_key:
            keys.append(a_content_key)

        db.delete(keys)

        # decrease source counter
        Counters.source_counter(a_info.source.name).decrement()