Beispiel #1
0
 def test_delete_by_name_missing_source(self):
     self.m.StubOutWithMock(ArtifactSource, "get_by_name")
     
     name = "mhawthorne"
     ArtifactSource.get_by_name(name)
     
     self.m.ReplayAll()
     self.assertRaises(NotFoundException, ArtifactSourceAccessor.delete_by_name, name)
     self.m.VerifyAll()
Beispiel #2
0
    def test_delete_by_name_missing_source(self):
        self.m.StubOutWithMock(ArtifactSource, "get_by_name")

        name = "mhawthorne"
        ArtifactSource.get_by_name(name)

        self.m.ReplayAll()
        self.assertRaises(NotFoundException,
                          ArtifactSourceAccessor.delete_by_name, name)
        self.m.VerifyAll()
Beispiel #3
0
 def test_delete_by_name_deletes_source_with_referencing_feed(self):
     # self.m.StubOutWithMock(antonym_model, 'ArtifactSource')
     self.m.StubOutWithMock(ArtifactSource, "get_by_name")
     self.m.StubOutWithMock(FeedAccessor, "get_by_source_name")
     
     name = "mhawthorne"
     source = MockEntity(key_name=name)
     ArtifactSource.get_by_name(name).AndReturn(source)
     FeedAccessor.get_by_source_name(name, return_none=True).AndReturn(MockEntity(key=name, url="http://real.ly"))
     
     self.m.ReplayAll()
     self.assertRaises(ConflictingDataException, ArtifactSourceAccessor.delete_by_name, name)
     self.m.VerifyAll()
Beispiel #4
0
    def test_delete_by_name_deletes_source_with_referencing_feed(self):
        # self.m.StubOutWithMock(antonym_model, 'ArtifactSource')
        self.m.StubOutWithMock(ArtifactSource, "get_by_name")
        self.m.StubOutWithMock(FeedAccessor, "get_by_source_name")

        name = "mhawthorne"
        source = MockEntity(key_name=name)
        ArtifactSource.get_by_name(name).AndReturn(source)
        FeedAccessor.get_by_source_name(name, return_none=True).AndReturn(
            MockEntity(key=name, url="http://real.ly"))

        self.m.ReplayAll()
        self.assertRaises(ConflictingDataException,
                          ArtifactSourceAccessor.delete_by_name, name)
        self.m.VerifyAll()
Beispiel #5
0
    def delete_by_name(cls, source_name):
        source = ArtifactSource.get_by_name(source_name)
        logging.debug("delete_by_name source: %s" % source)
        if not source:
            raise NotFoundException('ArtifactSource %s' % source_name)

        # checks for feeds linked to source
        feed = FeedAccessor.get_by_source_name(source_name, return_none=True)
        if feed:
            raise ConflictingDataException(
                "ArtifactSource '%s' is referenced by Feed '%s'" %
                (source_name, feed.url))

        # finds and deletes artifacts for source
        info_keys = ArtifactInfo.find_by_source(source, keys_only=True)
        content_keys = ArtifactContent.find_by_source(source)

        # zips keys to delete info/content pairs back-to-back
        for artifact_keys in zip(info_keys, content_keys):
            db.delete(artifact_keys)

        # deletes extras if info/content sizes don't match
        # (this would be a data bug somewhere)
        content_len = content_keys.count()
        info_len = info_keys.count()
        if content_len < info_len:
            db.delete(content_keys[info_len:])
        elif info_len > content_len:
            db.delete(info_keys[content_len:])

        # deletes source
        db.delete(source)
Beispiel #6
0
    def delete_by_name(cls, source_name):
        source = ArtifactSource.get_by_name(source_name)
        logging.debug("delete_by_name source: %s" % source)
        if not source:
            raise NotFoundException("ArtifactSource %s" % source_name)

        # checks for feeds linked to source
        feed = FeedAccessor.get_by_source_name(source_name, return_none=True)
        if feed:
            raise ConflictingDataException("ArtifactSource '%s' is referenced by Feed '%s'" % (source_name, feed.url))

        # finds and deletes artifacts for source
        info_keys = ArtifactInfo.find_by_source(source, keys_only=True)
        content_keys = ArtifactContent.find_by_source(source)

        # zips keys to delete info/content pairs back-to-back
        for artifact_keys in zip(info_keys, content_keys):
            db.delete(artifact_keys)

        # deletes extras if info/content sizes don't match
        # (this would be a data bug somewhere)
        content_len = content_keys.count()
        info_len = info_keys.count()
        if content_len < info_len:
            db.delete(content_keys[info_len:])
        elif info_len > content_len:
            db.delete(info_keys[content_len:])

        # deletes source
        db.delete(source)
Beispiel #7
0
 def test_delete_by_name_deletes_source_with_no_referencing_feed(self):
     self.m.StubOutWithMock(ArtifactSource, "get_by_name")
     self.m.StubOutWithMock(FeedAccessor, "get_by_source_name")
     self.m.StubOutWithMock(ArtifactInfo, "find_by_source")
     self.m.StubOutWithMock(ArtifactContent, "find_by_source")
     self.m.StubOutWithMock(db, "delete")
     self.m.StubOutWithMock(memcache, "delete")
     
     name = "mhawthorne"
     source = MockEntity(key_name=name)
     ArtifactSource.get_by_name(name).AndReturn(source)
     FeedAccessor.get_by_source_name(name, return_none=True)
     ArtifactInfo.find_by_source(source, keys_only=True).AndReturn(MockQuery(range(0,0)))
     ArtifactContent.find_by_source(source).AndReturn(MockQuery(range(0,0)))
     db.delete(source)
     memcache.delete(IsA(str)).AndReturn(1)
     
     self.m.ReplayAll()
     ArtifactSourceAccessor.delete_by_name(name)
     self.m.VerifyAll()
Beispiel #8
0
    def test_delete_by_name_deletes_source_with_no_referencing_feed(self):
        self.m.StubOutWithMock(ArtifactSource, "get_by_name")
        self.m.StubOutWithMock(FeedAccessor, "get_by_source_name")
        self.m.StubOutWithMock(ArtifactInfo, "find_by_source")
        self.m.StubOutWithMock(ArtifactContent, "find_by_source")
        self.m.StubOutWithMock(db, "delete")
        self.m.StubOutWithMock(memcache, "delete")

        name = "mhawthorne"
        source = MockEntity(key_name=name)
        ArtifactSource.get_by_name(name).AndReturn(source)
        FeedAccessor.get_by_source_name(name, return_none=True)
        ArtifactInfo.find_by_source(source, keys_only=True).AndReturn(
            MockQuery(range(0, 0)))
        ArtifactContent.find_by_source(source).AndReturn(MockQuery(range(0,
                                                                         0)))
        db.delete(source)
        memcache.delete(IsA(str)).AndReturn(1)

        self.m.ReplayAll()
        ArtifactSourceAccessor.delete_by_name(name)
        self.m.VerifyAll()
Beispiel #9
0
 def get_by_name(cls, source_name, **kw):
     return ArtifactSource.get_by_name(source_name, **kw)
Beispiel #10
0
 def get_by_name(cls, source_name, **kw):
     return ArtifactSource.get_by_name(source_name, **kw)