1616__author__ = 'lundberg'
1717
1818
19- uri_list = ["mongodb://localhost:1234/pyop" , "redis://localhost/0" ]
19+ db_specs_list = [
20+ {"uri" : "mongodb://localhost:1234/pyop" , "name" : "pyop" },
21+ {"uri" : "redis://localhost/0" , "name" : 0 },
22+ ]
23+
2024
2125@pytest .fixture (autouse = True )
2226def mock_redis (monkeypatch ):
2327 def mockreturn (* args , ** kwargs ):
24- return fakeredis .FakeStrictRedis (decode_responses = True )
28+ return fakeredis .FakeStrictRedis (* args , ** kwargs )
2529 monkeypatch .setattr (Redis , "from_url" , mockreturn )
2630
2731@pytest .fixture (autouse = True )
@@ -30,10 +34,10 @@ def mock_mongo():
3034
3135
3236class TestStorage (object ):
33- @pytest .fixture (params = uri_list )
37+ @pytest .fixture (params = db_specs_list )
3438 def db (self , request ):
3539 return pyop .storage .StorageBase .from_uri (
36- request .param , db_name = "pyop" , collection = "test"
40+ request .param [ "uri" ] , db_name = request . param [ "name" ] , collection = "test"
3741 )
3842
3943 def test_write (self , db ):
@@ -69,15 +73,15 @@ def test_items(self, db):
6973 @pytest .mark .parametrize (
7074 "args,kwargs" ,
7175 [
72- (["redis://localhost" ], {"collection" : "test" }),
73- (["redis://localhost" , "test" ], {}),
74- (["unix://localhost/0" ], {"collection" : "test" , "ttl" : 3 }),
7576 (["mongodb://localhost/pyop" ], {"collection" : "test" , "ttl" : 3 }),
7677 (["mongodb://localhost" ], {"db_name" : "pyop" , "collection" : "test" }),
7778 (["mongodb://localhost" , "test" , "pyop" ], {}),
7879 (["mongodb://localhost/pyop" , "test" ], {}),
7980 (["mongodb://localhost/pyop" ], {"db_name" : "other" , "collection" : "test" }),
80- (["redis://localhost/0" ], {"db_name" : "pyop" , "collection" : "test" }),
81+ (["redis://localhost" ], {"collection" : "test" }),
82+ (["redis://localhost" , "test" ], {}),
83+ (["redis://localhost" ], {"db_name" : 2 , "collection" : "test" }),
84+ (["unix://localhost/0" ], {"collection" : "test" , "ttl" : 3 }),
8185 ],
8286 )
8387 def test_from_uri (self , args , kwargs ):
@@ -88,11 +92,7 @@ def test_from_uri(self, args, kwargs):
8892 @pytest .mark .parametrize (
8993 "error,args,kwargs" ,
9094 [
91- (
92- TypeError ,
93- ["redis://localhost" , "ouch" ],
94- {"db_name" : 3 , "collection" : "test" , "ttl" : None },
95- ),
95+ (ValueError , ["mongodb://localhost" ], {"collection" : "test" , "ttl" : None }),
9696 (
9797 TypeError ,
9898 ["mongodb://localhost" , "ouch" ],
@@ -110,12 +110,11 @@ def test_from_uri(self, args, kwargs):
110110 ),
111111 (
112112 TypeError ,
113- ["mongodb ://localhost" ],
114- {"db_name" : "pyop" , "collection" : "test" , "ttl" : None , "extra" : True },
113+ ["redis ://localhost" , "ouch " ],
114+ {"db_name" : 3 , "collection" : "test" , "ttl" : None },
115115 ),
116116 (TypeError , ["redis://localhost/0" ], {}),
117117 (TypeError , ["redis://localhost/0" ], {"db_name" : "pyop" }),
118- (ValueError , ["mongodb://localhost" ], {"collection" : "test" , "ttl" : None }),
119118 ],
120119 )
121120 def test_from_uri_invalid_parameters (self , error , args , kwargs ):
@@ -153,11 +152,11 @@ def execute_ttl_test(self, uri, ttl):
153152 with pytest .raises (KeyError ):
154153 self .db ["foo" ]
155154
156- @pytest .mark .parametrize ("uri " , uri_list )
155+ @pytest .mark .parametrize ("spec " , db_specs_list )
157156 @pytest .mark .parametrize ("ttl" , ["invalid" , - 1 , 2.3 , {}])
158- def test_invalid_ttl (self , uri , ttl ):
157+ def test_invalid_ttl (self , spec , ttl ):
159158 with pytest .raises (ValueError ):
160- self .prepare_db (uri , ttl )
159+ self .prepare_db (spec [ " uri" ] , ttl )
161160
162161
163162class TestRedisTTL (StorageTTLTest ):
0 commit comments