示例#1
0
  def testRun(self, mockUrlOpenMethod):
    exportLinks = [
      'docs.google.com/123',
      'docs.google.com/456',
      'docs.google.com/789'
    ]
    mockRevisions = [
      Revision(exportLink=exportLinks[0]).to_dict(),
      Revision(exportLink=exportLinks[1]).to_dict(),
      Revision(exportLink=exportLinks[2]).to_dict()
    ]
    exportedText = {
      exportLinks[0]: StringIO('Hello'),
      exportLinks[1]: StringIO('Hello world.'),
      exportLinks[2]: StringIO('Hello.'),
    }
    mockUrlOpenMethod.side_effect = lambda url: exportedText[url]

    # TODO(michaelcupino): Fix tests
    pipeline = RevisionsAnalysisPipeline(mockRevisions, None)
    pipeline.start_test()
    result = pipeline.outputs.default.value

    revision1 = Revision()
    revision1.wordsAdded = 1
    revision1.wordsDeleted = 0
    revision1.wordCount = 1
    revision1.exportLink = 'docs.google.com/123'
    revision2 = Revision()
    revision2.wordsAdded = 1
    revision2.wordsDeleted = 0
    revision2.wordCount = 2
    revision2.exportLink = 'docs.google.com/456'
    revision3 = Revision()
    revision3.wordsAdded = 0
    revision3.wordsDeleted = 1
    revision3.wordCount = 1
    revision3.exportLink = 'docs.google.com/789'
    self.assertEqual([revision1.to_dict(), revision2.to_dict(),
        revision3.to_dict()], result)
示例#2
0
    def run(self, toEmail, documentId, credentialsAsJson):
        credentials = OAuth2Credentials.from_json(credentialsAsJson)
        http = credentials.authorize(httplib2.Http())

        request = config.getService().revisions().list(fileId=documentId)
        response = request.execute(http=http)

        revisions = []
        for item in response.get('items'):
            revision = Revision()
            revision.documentId = documentId
            revision.revisionNumber = item.get('id')
            revision.author = item.get('lastModifyingUserName')
            revision.exportLink = item.get('exportLinks').get('text/plain')
            revision.dateTime = item.get('modifiedDate')
            revisions.append(revision.to_dict())
        return revisions
  def run(self, toEmail, documentId, credentialsAsJson):
    credentials = OAuth2Credentials.from_json(credentialsAsJson)
    http = credentials.authorize(httplib2.Http())

    request = config.getService().revisions().list(fileId=documentId)
    response = request.execute(http=http)

    revisions = []
    for item in response.get('items'):
      revision = Revision()
      revision.documentId = documentId
      revision.revisionNumber = item.get('id')
      revision.author = item.get('lastModifyingUserName')
      revision.exportLink = item.get('exportLinks').get('text/plain')
      revision.dateTime = item.get('modifiedDate')
      revisions.append(revision.to_dict())
    return revisions