1
1
import sys , os
2
2
PROJECT_HOME = os .path .abspath (os .path .join (os .path .dirname (__file__ ), '../../' ))
3
3
sys .path .append (PROJECT_HOME )
4
- from flask . ext . testing import TestCase
4
+ from flask_testing import TestCase
5
5
from flask import url_for
6
6
import unittest
7
7
import httpretty
8
8
import json
9
- import app
9
+ from solr import app
10
10
from werkzeug .security import gen_salt
11
11
from werkzeug .datastructures import MultiDict
12
- from StringIO import StringIO
12
+ from io import BytesIO
13
13
from solr .tests .mocks import MockSolrResponse
14
- from views import SolrInterface
15
14
from solr import views
15
+ from solr .views import SolrInterface
16
16
from models import Limits , Base
17
17
import mock
18
- from StringIO import StringIO
19
18
20
19
class TestSolrInterface (TestCase ):
21
20
@@ -248,11 +247,11 @@ def request_callback(request, uri, headers):
248
247
r = c .get (url_for ('search' ), query_string = {'q' : 'star' })
249
248
250
249
# Two cookies (session and sroute)
251
- self .assertEqual (len (r .data .split (';' )), len (self .app .config .get ("SOLR_SERVICE_FORWARDED_COOKIES" )))
250
+ self .assertEqual (len (r .data .decode ( 'utf-8' ). split (';' )), len (self .app .config .get ("SOLR_SERVICE_FORWARDED_COOKIES" )))
252
251
253
252
# This forwarded cookie should match the one we gave originally
254
253
n_found_cookies_with_good_value = 0
255
- for cookie in r .data .split (';' ):
254
+ for cookie in r .data .decode ( 'utf-8' ). split (';' ):
256
255
key , value = cookie .split ('=' )
257
256
if key in self .app .config .get ("SOLR_SERVICE_FORWARDED_COOKIES" ):
258
257
self .assertEqual (value .strip (), cookie_value )
@@ -417,7 +416,7 @@ def test_docs_subquery(self):
417
416
data = {
418
417
'q' : '*:*' ,
419
418
'fq' : 'docs(hHGU1Ef-TpacAhicI3J8kQ)' ,
420
- 'big' : (StringIO ('foo\n bar' ), 'bigname' , 'big-query/csv' )
419
+ 'big' : (BytesIO ('foo\n bar' . encode ( 'utf-8' ) ), 'bigname' , 'big-query/csv' )
421
420
},
422
421
headers = {'Authorization' : 'Bearer foo' })
423
422
# it made a request to retrieve library
@@ -568,7 +567,7 @@ def request_callback(request, uri, headers):
568
567
'q' : '*:*' ,
569
568
'fl' : 'bibcode' ,
570
569
'fq' : '{!bitset}' ,
571
- 'file_field' : (StringIO (bibcodes ), 'file' , 'big-query/csv' )
570
+ 'file_field' : (BytesIO (bibcodes . encode ( 'utf-8' ) ), 'file' , 'big-query/csv' )
572
571
}
573
572
)
574
573
@@ -581,13 +580,13 @@ def request_callback(request, uri, headers):
581
580
data = {
582
581
'q' : '*:*' ,
583
582
'fl' : 'bibcode' ,
584
- 'file_field' : (StringIO (bibcodes ), 'filename' , 'big-query/csv' ),
583
+ 'file_field' : (BytesIO (bibcodes . encode ( 'utf-8' ) ), 'filename' , 'big-query/csv' ),
585
584
}
586
585
)
587
586
588
587
self .assertEqual (resp .status_code , 200 )
589
- self .assertTrue ('bitset' not in resp .data )
590
- self .assertTrue ("Content-Disposition: form-data; name=\" file_field\" ; filename=\" file_field\" \r \ n Content-Type: big-query/csv" in resp .data )
588
+ self .assertTrue ('bitset' not in resp .data . decode ( 'utf-8' ) )
589
+ self .assertTrue ("Content-Disposition: form-data; name=\" file_field\" ; filename=\" file_field\" \\ r \\ nContent-Type: big-query/csv" in resp .data . decode ( 'utf-8' ) )
591
590
592
591
593
592
# Missing 'fq' parameter is filled in - but only when data (request.post(data=...)
@@ -599,8 +598,8 @@ def request_callback(request, uri, headers):
599
598
)
600
599
601
600
self .assertEqual (resp .status_code , 200 )
602
- self .assertTrue ('fq=%7B%21bitset%7D' in resp .data )
603
- self .assertTrue ("Content-Disposition: form-data; name=\" old-bad-behaviour\" ; filename=\" old-bad-behaviour\" \r \ n Content-Type: big-query/csv" in resp .data )
601
+ self .assertTrue ('fq=%7B%21bitset%7D' in resp .data . decode ( 'utf-8' ) )
602
+ self .assertTrue ("Content-Disposition: form-data; name=\" old-bad-behaviour\" ; filename=\" old-bad-behaviour\" \\ r \\ nContent-Type: big-query/csv" in resp .data . decode ( 'utf-8' ) )
604
603
605
604
606
605
@@ -612,20 +611,20 @@ def request_callback(request, uri, headers):
612
611
'q' : '*:*' ,
613
612
'fl' : 'bibcode' ,
614
613
'fq' : '{!bitset compression = true}' ,
615
- 'file_field' : (StringIO (bibcodes ), 'filename' , 'big-query/csv' ),
614
+ 'file_field' : (BytesIO (bibcodes . encode ( 'utf-8' ) ), 'filename' , 'big-query/csv' ),
616
615
}
617
616
)
618
617
619
618
self .assertEqual (resp .status_code , 200 )
620
- self .assertTrue ('fq=%7B%21bitset+compression+%3D+true%7D' in resp .data )
619
+ self .assertTrue ('fq=%7B%21bitset+compression+%3D+true%7D' in resp .data . decode ( 'utf-8' ) )
621
620
622
621
# We now allow more content streams to be sent
623
622
data = MultiDict ([
624
623
('q' , '*:*' ),
625
624
('fl' , 'bibcode' ),
626
625
('fq' , '{!bitset}' ),
627
- ('file_field' , (StringIO (bibcodes ), 'filename' , 'big-query/csv' )),
628
- ('file_field' , (StringIO (bibcodes ), 'filename' , 'big-query/csv' )),
626
+ ('file_field' , (BytesIO (bibcodes . encode ( 'utf-8' ) ), 'filename' , 'big-query/csv' )),
627
+ ('file_field' , (BytesIO (bibcodes . encode ( 'utf-8' ) ), 'filename' , 'big-query/csv' )),
629
628
])
630
629
631
630
resp = self .client .post (
0 commit comments