88"""
99import os
1010import sys
11+ import six
1112import random
1213import string
1314import textwrap
@@ -32,7 +33,11 @@ def get_random_string(length=6):
3233 """
3334 Generate a random string of letters and numbers
3435 """
35- return unicode ('' .join (random .choice (string .letters + string .digits ) for i in xrange (length )))
36+ return six .u ('' .join (
37+ random .choice (string .ascii_letters + string .digits )
38+ for i in range (length )
39+ ))
40+
3641
3742PANGRAMS = {
3843 'en' : 'The quick brown fox jumps over the lazy dog.' ,
@@ -80,7 +85,7 @@ def get_editable_document(self, version):
8085 "2.5" : "351008-lbex-docid-3383445" ,
8186 "2.6" : "15144-mitchrpt" ,
8287 "2.7" : "351151-lbex-docid-130036" ,
83- "3.3" : "50986-lbhi_sec07940_755445 " ,
88+ "3.3" : "351029-lbex-docid-149714 " ,
8489 }
8590 return version2slug [str (version )]
8691
@@ -283,14 +288,14 @@ def test_get_put(self):
283288 source = get_random_string ()
284289 description = get_random_string ()
285290 data = {get_random_string (): get_random_string ()}
286- if obj .resources .related_article == u 'http://documents.latimes.com' :
287- related_article = u 'http://documentcloud.org'
291+ if obj .resources .related_article == 'http://documents.latimes.com' :
292+ related_article = 'http://documentcloud.org'
288293 else :
289- related_article = u 'http://documents.latimes.com'
290- if obj .resources .published_url == u 'http://documents.latimes.com' :
291- published_url = u 'http://documentcloud.org'
294+ related_article = 'http://documents.latimes.com'
295+ if obj .resources .published_url == 'http://documents.latimes.com' :
296+ published_url = 'http://documentcloud.org'
292297 else :
293- published_url = u 'http://documents.latimes.com'
298+ published_url = 'http://documents.latimes.com'
294299 # Set the random strings our local object's attributes
295300 obj .title = title
296301 obj .source = source
@@ -438,7 +443,10 @@ def test_virtual_file_upload_and_delete(self):
438443 """
439444 path = os .path .join (os .path .dirname (__file__ ), "español.pdf" )
440445 real_file = open (path , 'rb' )
441- virtual_file = io .StringIO (real_file .read ())
446+ if six .PY3 :
447+ virtual_file = io .BytesIO (real_file .read ())
448+ else :
449+ virtual_file = io .StringIO (real_file .read ())
442450 obj = self .private_client .documents .upload (virtual_file , title = 'Espanola!' )
443451 self .assertEqual (type (obj ), Document )
444452 # Delete it
@@ -535,7 +543,7 @@ def test_get_document(self):
535543 Verify that a project can pull a particular document by id
536544 """
537545 obj = self .private_client .projects .get ('934' )
538- doc = obj .get_document (u '25798-pr-01092011-loughner' )
546+ doc = obj .get_document ('25798-pr-01092011-loughner' )
539547 self .assertEqual (type (doc ), Document )
540548
541549 def test_put (self ):
@@ -545,8 +553,8 @@ def test_put(self):
545553 # Pull the object we'll deface
546554 obj = self .private_client .projects .get (self .editable_project )
547555 # Create random strings we will save to the editable attributes
548- title = u 'The Klee Report (%s)' % get_random_string ()
549- description = textwrap .dedent (u """
556+ title = 'The Klee Report (%s)' % get_random_string ()
557+ description = textwrap .dedent ("""
550558 An independent probe into Sam Zell\' s purchase of Tribune Company by
551559 investigator Kenneth Klee. Released at the end of July 2010. (%s)
552560 """ )
@@ -565,8 +573,8 @@ def test_put(self):
565573 self .assertEqual (len (obj .document_list ), 0 )
566574 # Now add all the documents back in
567575 proj_ids = [
568- u '12667-the-klee-report-volume-2' ,
569- u '12666-the-klee-report-volume-1'
576+ '12667-the-klee-report-volume-2' ,
577+ '12666-the-klee-report-volume-1'
570578 ]
571579 for id in proj_ids :
572580 doc = self .private_client .documents .get (id )
@@ -660,7 +668,7 @@ def test_duplicate_object(self):
660668 Make sure DuplicateObjectError works.
661669 """
662670 obj = self .private_client .projects .get ("703" )
663- doc = self .private_client .documents .get (u '12666-the-klee-report-volume-1' )
671+ doc = self .private_client .documents .get ('12666-the-klee-report-volume-1' )
664672 self .assertRaises (DuplicateObjectError , obj .document_list .append , doc )
665673
666674
0 commit comments