Exemple #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()
Exemple #2
0
 def test_create_duplicate(self):
     self.moxer.StubOutWithMock(ArtifactInfo, "all", use_mock_anything=True)
     
     ArtifactInfo.all(keys_only=True).AndReturn(MockQuery(range(1), keys_only=True))
     
     self.moxer.ReplayAll()
     try:
         ArtifactAccessor.create(**self.__keywords())
         self.fail("exception expected")
     except DuplicateDataException, ex:
         pass
Exemple #3
0
    def test_create_duplicate(self):
        self.moxer.StubOutWithMock(ArtifactInfo, "all", use_mock_anything=True)

        ArtifactInfo.all(keys_only=True).AndReturn(
            MockQuery(range(1), keys_only=True))

        self.moxer.ReplayAll()
        try:
            ArtifactAccessor.create(**self.__keywords())
            self.fail("exception expected")
        except DuplicateDataException, ex:
            pass
Exemple #4
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()
Exemple #5
0
 def get(self, **kw):
     helper = RequestHelper(self)
     start = int(self.request.get("start", 0))
     count = int(self.request.get("count", 10))
     
     q = ArtifactInfo.all().order("-modified")
     json_results = []
     if q.count():
         for a_info in q.fetch(count, start):
             a_content = ArtifactAccessor.get_content_by_guid(a_info.guid)
             json_results.append(ArtifactsHelper.artifact_to_hash(a_info, a_content))
     helper.write_json(json_results)