Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zodburi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
zodburi
Commits
5014cc8d
Commit
5014cc8d
authored
May 27, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return to 100% coverage.
Also, fix bugs uncovered thereby in processing float / tuple arguments.
parent
9e187359
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
179 additions
and
159 deletions
+179
-159
zodburi/datatypes.py
zodburi/datatypes.py
+3
-0
zodburi/resolvers.py
zodburi/resolvers.py
+9
-9
zodburi/resolvers_relstorage.py
zodburi/resolvers_relstorage.py
+58
-54
zodburi/tests/test_resolvers.py
zodburi/tests/test_resolvers.py
+109
-96
No files found.
zodburi/datatypes.py
View file @
5014cc8d
...
...
@@ -36,3 +36,6 @@ def convert_int(value):
if
value
in
TRUETYPES
:
return
1
return
int
(
value
)
def
convert_tuple
(
value
):
return
tuple
(
value
.
split
(
','
))
zodburi/resolvers.py
View file @
5014cc8d
...
...
@@ -13,6 +13,7 @@ import ZConfig
from
zodburi.datatypes
import
convert_bytesize
from
zodburi.datatypes
import
convert_int
from
zodburi.datatypes
import
convert_tuple
class
Resolver
(
object
):
...
...
@@ -26,15 +27,14 @@ class Resolver(object):
unused
=
kw
.
copy
()
new
=
{}
convert_string
=
lambda
s
:
s
converters
=
(
convert_int
,
convert_string
,
convert_bytesize
)
args
=
(
self
.
_int_args
,
self
.
_string_args
,
self
.
_bytesize_args
)
for
convert
,
arg_names
in
zip
(
converters
,
args
):
converters
=
[
(
convert_int
,
self
.
_int_args
),
(
convert_string
,
self
.
_string_args
),
(
convert_bytesize
,
self
.
_bytesize_args
),
(
float
,
self
.
_float_args
),
(
convert_tuple
,
self
.
_tuple_args
),
]
for
convert
,
arg_names
in
converters
:
for
arg_name
in
arg_names
:
value
=
unused
.
pop
(
arg_name
,
None
)
if
value
is
not
None
:
...
...
zodburi/resolvers_relstorage.py
View file @
5014cc8d
import
cgi
import
urlparse
from
ZODB.DemoStorage
import
DemoStorage
from
relstorage.adapters.postgresql
import
PostgreSQLAdapter
from
relstorage.options
import
Options
from
relstorage.storage
import
RelStorage
from
.resolvers
import
Resolver
# Not a real resolver, but we use interpret_kwargs
class
PostgreSQLAdapterHelper
(
Resolver
):
try
:
from
relstorage.adapters.postgresql
import
PostgreSQLAdapter
from
relstorage.options
import
Options
from
relstorage.storage
import
RelStorage
except
ImportError
:
#pragma NO COVER
pass
else
:
# Not a real resolver, but we use interpret_kwargs
class
PostgreSQLAdapterHelper
(
Resolver
):
_int_args
=
(
'connect_timeout'
,
)
_string_args
=
(
'ssl_mode'
,
)
...
...
@@ -32,19 +35,20 @@ class PostgreSQLAdapterHelper(Resolver):
return
factory
,
unused
# The relstorage support is inspired by django-zodb.
# Oracle and mysql should be easily implementable from here
class
RelStorageURIResolver
(
Resolver
):
# The relstorage support is inspired by django-zodb.
# Oracle and mysql should be easily implementable from here
class
RelStorageURIResolver
(
Resolver
):
_int_args
=
(
'poll_interval'
,
'cache_local_mb'
,
'commit_lock_timeout'
,
'commit_lock_id'
,
'read_only'
,
'shared_blob_dir'
,
'keep_history'
,
'pack_gc'
,
'pack_dry_run'
,
'strict_tpc'
,
'create'
,
'demostorage'
,)
_string_args
=
(
'name'
,
'blob_dir'
,
'replica_conf'
,
'cache_module_name'
,
'cache_prefix'
,
'cache_delta_size_limit'
)
_string_args
=
(
'name'
,
'blob_dir'
,
'replica_conf'
,
'cache_module_name'
,
'cache_prefix'
,
'cache_delta_size_limit'
)
_bytesize_args
=
(
'blob_cache_size'
,
'blob_cache_size_check'
,
'blob_cache_chunk_size'
)
_float_args
=
(
'replica_timeout'
,
'pack_batch_timeout'
,
'pack_duty_cycle
'
,
'pack_max_delay'
)
_float_args
=
(
'replica_timeout'
,
'pack_batch_timeout
'
,
'pack_duty_cycle'
,
'pack_max_delay'
)
_tuple_args
=
(
'cache_servers'
,)
def
__init__
(
self
,
adapter_helper
):
...
...
@@ -69,4 +73,4 @@ class RelStorageURIResolver(Resolver):
return
storage
return
factory
,
unused
postgresql_resolver
=
RelStorageURIResolver
(
PostgreSQLAdapterHelper
())
\ No newline at end of file
postgresql_resolver
=
RelStorageURIResolver
(
PostgreSQLAdapterHelper
())
zodburi/tests/test_resolvers.py
View file @
5014cc8d
...
...
@@ -10,20 +10,19 @@ class Base:
def
test_bytesize_args
(
self
):
resolver
=
self
.
_makeOne
()
names
=
list
(
resolver
.
_bytesize_args
)
names
=
sorted
(
resolver
.
_bytesize_args
)
kwargs
=
{}
for
name
in
names
:
kwargs
[
name
]
=
'10MB'
args
=
resolver
.
interpret_kwargs
(
kwargs
)[
0
]
keys
=
args
.
keys
()
keys
.
sort
()
self
.
assertEqual
(
keys
,
names
)
self
.
assertEqual
(
sorted
(
keys
),
names
)
for
name
,
value
in
args
.
items
():
self
.
assertEqual
(
value
,
10
*
1024
*
1024
)
def
test_int_args
(
self
):
resolver
=
self
.
_makeOne
()
names
=
list
(
resolver
.
_int_args
)
names
=
sorted
(
resolver
.
_int_args
)
kwargs
=
{}
for
name
in
names
:
kwargs
[
name
]
=
'10'
...
...
@@ -36,40 +35,37 @@ class Base:
def
test_string_args
(
self
):
resolver
=
self
.
_makeOne
()
names
=
list
(
resolver
.
_string_args
)
names
=
sorted
(
resolver
.
_string_args
)
kwargs
=
{}
for
name
in
names
:
kwargs
[
name
]
=
'string'
args
=
resolver
.
interpret_kwargs
(
kwargs
)[
0
]
keys
=
args
.
keys
()
keys
.
sort
()
self
.
assertEqual
(
keys
,
names
)
self
.
assertEqual
(
sorted
(
keys
),
names
)
for
name
,
value
in
args
.
items
():
self
.
assertEqual
(
value
,
'string'
)
def
test_float_args
(
self
):
resolver
=
self
.
_makeOne
()
names
=
list
(
resolver
.
_float_args
)
names
=
sorted
(
resolver
.
_float_args
)
kwargs
=
{}
for
name
in
names
:
kwargs
[
name
]
=
'3.14'
args
=
resolver
.
interpret_kwargs
(
kwargs
)[
0
]
keys
=
args
.
keys
()
keys
.
sort
()
self
.
assertEqual
(
keys
,
names
)
self
.
assertEqual
(
sorted
(
keys
),
names
)
for
name
,
value
in
args
.
items
():
self
.
assertEqual
(
value
,
3.14
)
def
test_tuple_args
(
self
):
resolver
=
self
.
_makeOne
()
names
=
list
(
resolver
.
_tuple_args
)
names
=
sorted
(
resolver
.
_tuple_args
)
kwargs
=
{}
for
name
in
names
:
kwargs
[
name
]
=
'first,second,third'
args
=
resolver
.
interpret_kwargs
(
kwargs
)[
0
]
keys
=
args
.
keys
()
keys
.
sort
()
self
.
assertEqual
(
keys
,
names
)
self
.
assertEqual
(
sorted
(
keys
),
names
)
for
name
,
value
in
args
.
items
():
self
.
assertEqual
(
value
,
(
'first'
,
'second'
,
'third'
))
...
...
@@ -412,8 +408,12 @@ class TestMappingStorageURIResolver(Base, unittest.TestCase):
self
.
assertTrue
(
isinstance
(
storage
,
MappingStorage
))
self
.
assertEqual
(
storage
.
__name__
,
'storagename'
)
class
TestPostgreSQLURIResolver
(
unittest
.
TestCase
):
try
:
from
zodburi.resolvers_relstorage
import
RelStorageURIResolver
except
ImportError
:
#pragma NO COVER
pass
else
:
class
TestPostgreSQLURIResolver
(
unittest
.
TestCase
,
Base
):
def
_getTargetClass
(
self
):
from
zodburi.resolvers_relstorage
import
RelStorageURIResolver
return
RelStorageURIResolver
...
...
@@ -450,29 +450,35 @@ class TestPostgreSQLURIResolver(unittest.TestCase):
def
test_call
(
self
,
RelStorage
,
PostgreSQLAdapter
):
from
relstorage.options
import
Options
resolver
=
self
.
_makeOne
()
factory
,
dbkw
=
resolver
(
'postgres://someuser:somepass@somehost:5432/somedb?read_only=1'
)
factory
,
dbkw
=
resolver
(
'postgres://someuser:somepass@somehost:5432/somedb'
'?read_only=1'
)
factory
()
expected_options
=
Options
(
read_only
=
1
)
PostgreSQLAdapter
.
assert_called_once_with
(
dsn
=
"dbname='somedb' user='someuser' password='somepass' "
"host='somehost' port='5432'"
,
options
=
expected_options
)
RelStorage
.
assert_called_once_with
(
adapter
=
PostgreSQLAdapter
(),
options
=
expected_options
)
PostgreSQLAdapter
.
assert_called_once_with
(
dsn
=
"dbname='somedb' user='someuser' password='somepass' "
"host='somehost' port='5432'"
,
options
=
expected_options
)
RelStorage
.
assert_called_once_with
(
adapter
=
PostgreSQLAdapter
(),
options
=
expected_options
)
@
mock
.
patch
(
'zodburi.resolvers_relstorage.PostgreSQLAdapter'
)
@
mock
.
patch
(
'zodburi.resolvers_relstorage.RelStorage'
)
def
test_call_adapter_options
(
self
,
RelStorage
,
PostgreSQLAdapter
):
from
relstorage.options
import
Options
resolver
=
self
.
_makeOne
()
factory
,
dbkw
=
resolver
(
'postgres://someuser:somepass@somehost:5432/somedb?read_only=1'
'&connect_timeout=10'
)
factory
,
dbkw
=
resolver
(
'postgres://someuser:somepass@somehost:5432/somedb'
'?read_only=1&connect_timeout=10'
)
factory
()
expected_options
=
Options
(
read_only
=
1
)
PostgreSQLAdapter
.
assert_called_once_with
(
dsn
=
"dbname='somedb' user='someuser' password='somepass' "
PostgreSQLAdapter
.
assert_called_once_with
(
dsn
=
"dbname='somedb' user='someuser' password='somepass' "
"host='somehost' port='5432' connect_timeout='10'"
,
options
=
expected_options
)
RelStorage
.
assert_called_once_with
(
adapter
=
PostgreSQLAdapter
(),
options
=
expected_options
)
RelStorage
.
assert_called_once_with
(
adapter
=
PostgreSQLAdapter
(),
options
=
expected_options
)
@
mock
.
patch
(
'zodburi.resolvers_relstorage.PostgreSQLAdapter'
)
...
...
@@ -480,16 +486,17 @@ class TestPostgreSQLURIResolver(unittest.TestCase):
def
test_invoke_factory_demostorage
(
self
,
RelStorage
,
PostgreSQLAdapter
):
from
ZODB.DemoStorage
import
DemoStorage
resolver
=
self
.
_makeOne
()
factory
,
dbkw
=
resolver
(
'postgres://someuser:somepass@somehost:5432/somedb?read_only=1'
'&demostorage=true'
)
factory
,
dbkw
=
resolver
(
'postgres://someuser:somepass@somehost:5432/somedb'
'?read_only=1&demostorage=true'
)
self
.
assertTrue
(
isinstance
(
factory
(),
DemoStorage
))
def
test_dbargs
(
self
):
resolver
=
self
.
_makeOne
()
factory
,
dbkw
=
resolver
(
'postgres://someuser:somepass@somehost:5432/somedb?read_only=1&'
'connection_pool_size=1&
'
'connection_cache_size=1&
'
'
database_name=dbname'
)
factory
,
dbkw
=
resolver
(
'postgres://someuser:somepass@somehost:5432/somedb
'
'?read_only=1&connection_pool_size=1&connection_cache_size=1
'
'&
database_name=dbname'
)
self
.
assertEqual
(
dbkw
,
{
'connection_pool_size'
:
'1'
,
'connection_cache_size'
:
'1'
,
'database_name'
:
'dbname'
})
...
...
@@ -499,14 +506,20 @@ class TestEntryPoints(unittest.TestCase):
def
test_it
(
self
):
from
pkg_resources
import
load_entry_point
from
zodburi
import
resolvers
,
resolvers_relstorage
from
zodburi
import
resolvers
expected
=
[
(
'memory'
,
resolvers
.
MappingStorageURIResolver
),
(
'zeo'
,
resolvers
.
ClientStorageURIResolver
),
(
'file'
,
resolvers
.
FileStorageURIResolver
),
(
'zconfig'
,
resolvers
.
ZConfigURIResolver
),
(
'postgres'
,
resolvers_relstorage
.
RelStorageURIResolver
),
]
try
:
from
zodburi.resolvers_relstorage
import
RelStorageURIResolver
except
ImportError
:
#pragma NO COVER
pass
else
:
expected
.
append
(
(
'postgres'
,
RelStorageURIResolver
))
for
name
,
cls
in
expected
:
target
=
load_entry_point
(
'zodburi'
,
'zodburi.resolvers'
,
name
)
self
.
assertTrue
(
isinstance
(
target
,
cls
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment