4848 test_server .prepare ()
4949 test_server .start ()
5050
51+ testrun_search_bucket = None
52+ testrun_props_bucket = None
53+ testrun_sibs_bucket = None
54+
55+ def setUpModule ():
56+ global testrun_search_bucket , testrun_props_bucket , \
57+ testrun_sibs_bucket
58+
59+ c = RiakClient (transport = 'http' , http_port = HTTP_PORT )
60+
61+ testrun_props_bucket = 'propsbucket'
62+ testrun_sibs_bucket = 'sibsbucket'
63+ c .bucket (testrun_sibs_bucket ).allow_mult = True
64+
65+ if not int (os .environ .get ('SKIP_SEARCH' , '0' )):
66+ testrun_search_bucket = 'searchbucket'
67+ b = c .bucket (testrun_search_bucket )
68+ b .enable_search ()
69+
70+ def tearDownModule ():
71+ c = RiakClient (transport = 'http' , http_port = HTTP_PORT )
72+ if not int (os .environ .get ('SKIP_SEARCH' , '0' )):
73+ b = c .bucket (testrun_search_bucket )
74+ b .clear_properties ()
75+ b = c .bucket (testrun_sibs_bucket )
76+ b .clear_properties ()
77+ b = c .bucket (testrun_props_bucket )
78+ b .clear_properties ()
5179
5280class BaseTestCase (object ):
5381
@@ -59,6 +87,13 @@ class BaseTestCase(object):
5987 def randint ():
6088 return random .randint (1 , 999999 )
6189
90+ @staticmethod
91+ def randname (length = 12 ):
92+ out = ''
93+ for i in range (length ):
94+ out += chr (random .randint (ord ('a' ), ord ('z' )))
95+ return out
96+
6297 def create_client (self , host = None , http_port = None , pb_port = None ,
6398 protocol = None , ** client_args ):
6499 host = host or self .host or HOST
@@ -71,14 +106,13 @@ def create_client(self, host=None, http_port=None, pb_port=None,
71106 pb_port = pb_port , ** client_args )
72107
73108 def setUp (self ):
74- self .client = self .create_client ()
109+ self .bucket_name = self .randname ()
110+ self .key_name = self .randname ()
111+ self .search_bucket = testrun_search_bucket
112+ self .sibs_bucket = testrun_sibs_bucket
113+ self .props_bucket = testrun_props_bucket
75114
76- # make sure these are not left over from a previous, failed run
77- bucket = self .client .bucket ('bucket' )
78- o = bucket .get ('nonexistent_key_json' )
79- o .delete ()
80- o = bucket .get ('nonexistent_key_binary' )
81- o .delete ()
115+ self .client = self .create_client ()
82116
83117
84118class RiakPbcTransportTestCase (BasicKVTests ,
@@ -100,6 +134,8 @@ def setUp(self):
100134 self .host = PB_HOST
101135 self .pb_port = PB_PORT
102136 self .protocol = 'pbc'
137+ self .http_client = self .create_client (HTTP_HOST ,
138+ http_port = HTTP_PORT )
103139 super (RiakPbcTransportTestCase , self ).setUp ()
104140
105141 def test_uses_client_id_if_given (self ):
@@ -109,12 +145,12 @@ def test_uses_client_id_if_given(self):
109145
110146 def test_bucket_search_enabled (self ):
111147 with self .assertRaises (NotImplementedError ):
112- bucket = self .client .bucket ("unsearch_bucket" )
148+ bucket = self .client .bucket (self . bucket_name )
113149 bucket .search_enabled ()
114150
115151 def test_enable_search_commit_hook (self ):
116152 with self .assertRaises (NotImplementedError ):
117- bucket = self .client .bucket ("search_bucket" )
153+ bucket = self .client .bucket (self . bucket_name )
118154 bucket .enable_search ()
119155
120156
@@ -140,12 +176,12 @@ def setUp(self):
140176 super (RiakHttpTransportTestCase , self ).setUp ()
141177
142178 def test_no_returnbody (self ):
143- bucket = self .client .bucket ("bucket" )
144- o = bucket .new ("foo" , "bar" ).store (return_body = False )
179+ bucket = self .client .bucket (self . bucket_name )
180+ o = bucket .new (self . key_name , "bar" ).store (return_body = False )
145181 self .assertEqual (o .vclock , None )
146182
147183 def test_too_many_link_headers_shouldnt_break_http (self ):
148- bucket = self .client .bucket ("bucket" )
184+ bucket = self .client .bucket (self . bucket_name )
149185 o = bucket .new ("lots_of_links" , "My god, it's full of links!" )
150186 for i in range (0 , 400 ):
151187 link = RiakLink ("other" , "key%d" % i , "next" )
@@ -156,7 +192,7 @@ def test_too_many_link_headers_shouldnt_break_http(self):
156192 self .assertEqual (len (stored_object .get_links ()), 400 )
157193
158194 def test_clear_bucket_properties (self ):
159- bucket = self .client .bucket ('bucket' )
195+ bucket = self .client .bucket (self . props_bucket )
160196 bucket .allow_mult = True
161197 self .assertTrue (bucket .allow_mult )
162198 bucket .n_val = 1
0 commit comments