16
16
__author__ = 'lundberg'
17
17
18
18
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
+
20
24
21
25
@pytest .fixture (autouse = True )
22
26
def mock_redis (monkeypatch ):
23
27
def mockreturn (* args , ** kwargs ):
24
- return fakeredis .FakeStrictRedis (decode_responses = True )
28
+ return fakeredis .FakeStrictRedis (* args , ** kwargs )
25
29
monkeypatch .setattr (Redis , "from_url" , mockreturn )
26
30
27
31
@pytest .fixture (autouse = True )
@@ -30,10 +34,10 @@ def mock_mongo():
30
34
31
35
32
36
class TestStorage (object ):
33
- @pytest .fixture (params = uri_list )
37
+ @pytest .fixture (params = db_specs_list )
34
38
def db (self , request ):
35
39
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"
37
41
)
38
42
39
43
def test_write (self , db ):
@@ -69,15 +73,15 @@ def test_items(self, db):
69
73
@pytest .mark .parametrize (
70
74
"args,kwargs" ,
71
75
[
72
- (["redis://localhost" ], {"collection" : "test" }),
73
- (["redis://localhost" , "test" ], {}),
74
- (["unix://localhost/0" ], {"collection" : "test" , "ttl" : 3 }),
75
76
(["mongodb://localhost/pyop" ], {"collection" : "test" , "ttl" : 3 }),
76
77
(["mongodb://localhost" ], {"db_name" : "pyop" , "collection" : "test" }),
77
78
(["mongodb://localhost" , "test" , "pyop" ], {}),
78
79
(["mongodb://localhost/pyop" , "test" ], {}),
79
80
(["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 }),
81
85
],
82
86
)
83
87
def test_from_uri (self , args , kwargs ):
@@ -88,11 +92,7 @@ def test_from_uri(self, args, kwargs):
88
92
@pytest .mark .parametrize (
89
93
"error,args,kwargs" ,
90
94
[
91
- (
92
- TypeError ,
93
- ["redis://localhost" , "ouch" ],
94
- {"db_name" : 3 , "collection" : "test" , "ttl" : None },
95
- ),
95
+ (ValueError , ["mongodb://localhost" ], {"collection" : "test" , "ttl" : None }),
96
96
(
97
97
TypeError ,
98
98
["mongodb://localhost" , "ouch" ],
@@ -110,12 +110,11 @@ def test_from_uri(self, args, kwargs):
110
110
),
111
111
(
112
112
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 },
115
115
),
116
116
(TypeError , ["redis://localhost/0" ], {}),
117
117
(TypeError , ["redis://localhost/0" ], {"db_name" : "pyop" }),
118
- (ValueError , ["mongodb://localhost" ], {"collection" : "test" , "ttl" : None }),
119
118
],
120
119
)
121
120
def test_from_uri_invalid_parameters (self , error , args , kwargs ):
@@ -153,11 +152,11 @@ def execute_ttl_test(self, uri, ttl):
153
152
with pytest .raises (KeyError ):
154
153
self .db ["foo" ]
155
154
156
- @pytest .mark .parametrize ("uri " , uri_list )
155
+ @pytest .mark .parametrize ("spec " , db_specs_list )
157
156
@pytest .mark .parametrize ("ttl" , ["invalid" , - 1 , 2.3 , {}])
158
- def test_invalid_ttl (self , uri , ttl ):
157
+ def test_invalid_ttl (self , spec , ttl ):
159
158
with pytest .raises (ValueError ):
160
- self .prepare_db (uri , ttl )
159
+ self .prepare_db (spec [ " uri" ] , ttl )
161
160
162
161
163
162
class TestRedisTTL (StorageTTLTest ):
0 commit comments