Beispiel #1
0
 def test_create(self):
     accessor_save_kw = self.__keywords()
     source_name = accessor_save_kw['source']
     content_type = accessor_save_kw['content_type']
     body = accessor_save_kw['body']
     
     self.moxer.StubOutWithMock(ArtifactInfo, "all", use_mock_anything=True)
     self.moxer.StubOutWithMock(ArtifactSource, "get_or_create", use_mock_anything=True)
     self.moxer.StubOutWithMock(Counters, "source_counter", use_mock_anything=True)
     self.moxer.StubOutWithMock(ArtifactInfo, "create", use_mock_anything=True)
     self.moxer.StubOutWithMock(ArtifactContent, "create", use_mock_anything=True)
     
     source = MockEntity(key_name=source_name)
     ArtifactInfo.all(keys_only=True).AndReturn(MockQuery(None, keys_only=True))
     ArtifactSource.get_or_create(source_name).AndReturn(source)
     
     counter = self.moxer.CreateMockAnything()
     Counters.source_counter(source_name).AndReturn(counter)
     counter.increment()
     
     # TODO: I wish I could ignore keywords
     md5 = ArtifactAccessor._content_md5(source_name, content_type, body)
     info_save_kw = dict(source=source, source_name=source_name, content_type=content_type, content_md5=md5)
     info_key = MockKey(name=self.test_id)
     ArtifactInfo.create(**info_save_kw).AndReturn(info_key)
     
     content_save_kw = dict(source=source, source_name=source_name, info=info_key, body=body)
     ArtifactContent.create(info_key.name(), **content_save_kw).AndReturn(MockKey(name=self.test_id))
     
     self.moxer.ReplayAll()
     info, content, source = ArtifactAccessor.create(**accessor_save_kw)
     print 'info:%s, content:%s, source:%s' % (info, content, source)
     self.moxer.VerifyAll()
Beispiel #2
0
    def test_create(self):
        accessor_save_kw = self.__keywords()
        source_name = accessor_save_kw['source']
        content_type = accessor_save_kw['content_type']
        body = accessor_save_kw['body']

        self.moxer.StubOutWithMock(ArtifactInfo, "all", use_mock_anything=True)
        self.moxer.StubOutWithMock(ArtifactSource,
                                   "get_or_create",
                                   use_mock_anything=True)
        self.moxer.StubOutWithMock(Counters,
                                   "source_counter",
                                   use_mock_anything=True)
        self.moxer.StubOutWithMock(ArtifactInfo,
                                   "create",
                                   use_mock_anything=True)
        self.moxer.StubOutWithMock(ArtifactContent,
                                   "create",
                                   use_mock_anything=True)

        source = MockEntity(key_name=source_name)
        ArtifactInfo.all(keys_only=True).AndReturn(
            MockQuery(None, keys_only=True))
        ArtifactSource.get_or_create(source_name).AndReturn(source)

        counter = self.moxer.CreateMockAnything()
        Counters.source_counter(source_name).AndReturn(counter)
        counter.increment()

        # TODO: I wish I could ignore keywords
        md5 = ArtifactAccessor._content_md5(source_name, content_type, body)
        info_save_kw = dict(source=source,
                            source_name=source_name,
                            content_type=content_type,
                            content_md5=md5)
        info_key = MockKey(name=self.test_id)
        ArtifactInfo.create(**info_save_kw).AndReturn(info_key)

        content_save_kw = dict(source=source,
                               source_name=source_name,
                               info=info_key,
                               body=body)
        ArtifactContent.create(info_key.name(), **content_save_kw).AndReturn(
            MockKey(name=self.test_id))

        self.moxer.ReplayAll()
        info, content, source = ArtifactAccessor.create(**accessor_save_kw)
        print 'info:%s, content:%s, source:%s' % (info, content, source)
        self.moxer.VerifyAll()
Beispiel #3
0
    def _create(cls, source_name, body, content_md5, **kw):
        # saves source, if unique
        source_key = ArtifactSource.get_or_create(source_name)

        # saves ArtifactInfo
        a_info_key = ArtifactInfo.create(content_md5=content_md5, source=source_key, source_name=source_name, **kw)

        # saves ArtifactContent
        guid = a_info_key.name()
        a_content_key = ArtifactContent.create(
            guid, body=body, source=source_key, source_name=source_name, info=a_info_key
        )

        # bump source counter
        # it's important to do this AFTER the artifacts are saved
        Counters.source_counter(source_name).increment()

        return a_info_key, a_content_key, source_key
Beispiel #4
0
    def _create(cls, source_name, body, content_md5, **kw):
        # saves source, if unique
        source_key = ArtifactSource.get_or_create(source_name)

        # saves ArtifactInfo
        a_info_key = ArtifactInfo.create(content_md5=content_md5,
                                         source=source_key,
                                         source_name=source_name,
                                         **kw)

        # saves ArtifactContent
        guid = a_info_key.name()
        a_content_key = ArtifactContent.create(guid,
                                               body=body,
                                               source=source_key,
                                               source_name=source_name,
                                               info=a_info_key)

        # bump source counter
        # it's important to do this AFTER the artifacts are saved
        Counters.source_counter(source_name).increment()

        return a_info_key, a_content_key, source_key