Skip to content

Commit

Permalink
@leplatrem review.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémy HUBSCHER committed Jan 29, 2016
1 parent 855fc6a commit 9c6e2ff
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
40 changes: 29 additions & 11 deletions kinto_client/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,41 @@ def is_same_record(fields, one, two):

class KintoImporter(object):
# Default configure parser values
"""Configure the parser with all parameters."""
include_all_default_parameters = False
"""Configure the parser to allow remote_server configuration."""
include_remote_server = None
"""Configure the parser to allow authentication configuration."""
include_authentication = None
"""Configure the parser to allow files selection."""
include_files = None
"""Configure the parser to allow verbosity configuration."""
include_verbosity = None

# Remote Permissions
bucket_permissions = None
collection_permissions = None

# Default values
"""Default value for the remote server host value."""
default_host = "http://localhost:8888/v1"
"""Default bucket name for the remote server."""
default_bucket = None
"""Default collection name for the remote server."""
default_collection = None
"""Default authentication credentials for the remote server."""
default_auth = None
"""Default files to load for the local records."""
default_files = None

# Remote Permissions
"""Remote bucket permissions on bucket creation."""
bucket_permissions = None
"""Remote collection permission on collection creation."""
collection_permissions = None

# Sync flags
"""Create new records."""
create = True
"""Update out-of-date records."""
update = True
"""Delete records not present in local-files."""
delete = True

def __init__(self, logger=None, arguments=None,
Expand Down Expand Up @@ -86,7 +101,8 @@ def configure_parser(self, parser=None,
--auth token # Will ask for the password on STDIN
:param boolean include_files:
Allow input files configuration (a list of files)
Allow input files for local_records loading (can be a list
of files)
:param boolean include_verbosity: Allow verbosity configuration
Configure the log level to logging.INFO
Expand Down Expand Up @@ -143,7 +159,8 @@ def configure_parser(self, parser=None,
help='Collection name',
type=str, default=self.default_collection)
if include_authentication:
parser.add_argument('-u', '--auth', help='BasicAuth user:pass',
parser.add_argument('-u', '--auth',
help='BasicAuth token:my-secret',
type=str, default=self.default_auth)

if include_files:
Expand Down Expand Up @@ -210,7 +227,7 @@ def setup_local_client(self, local_client=None):
return local_client

def setup_remote_client(self, remote_client=None):
# If the client is already created, just return it.
# If the client is specified, just return it.
if remote_client:
return remote_client

Expand All @@ -233,8 +250,8 @@ def setup_remote_client(self, remote_client=None):
collection=self.args['collection'])

# Create bucket
# XXX: Move this to a configure
# XXX: Add a create if not exist functionality
# XXX: Move this to a configure (Refs #41)
# XXX: Add a create if not exist functionality (Refs #42)
try:
remote_client.create_bucket(
permissions=self.bucket_permissions)
Expand Down Expand Up @@ -271,8 +288,9 @@ def remote_records(self):
def sync(self, create=None, update=None, delete=None):
"""Sync local and remote collection using args.
Take the arguments as well as a local_klass constructor a sync the
local and remote collection.
Take the arguments as well as a ``local_klass`` constructor a
sync the local and remote collection.
"""
if create is None:
create = self.create
Expand Down
16 changes: 8 additions & 8 deletions kinto_client/tests/test_batch.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import unittest2 as unittest
import mock

from kinto_client.batch import Session
from kinto_client.batch import Session as BatchSession


class SessionRequestsTest(unittest.TestCase):
class BatchSessionRequestsTest(unittest.TestCase):
def setUp(self):
self.client = mock.MagicMock()
self.client.session.request.return_value = (mock.sentinel.resp,
mock.sentinel.headers)

def test_requests_are_stacked(self):
batch = Session(self.client)
batch = BatchSession(self.client)
batch.request('GET', '/foobar/baz',
mock.sentinel.data,
mock.sentinel.permissions)
assert len(batch.requests) == 1

def test_send_adds_data_attribute(self):
batch = Session(self.client)
batch = BatchSession(self.client)
batch.request('GET', '/foobar/baz', data={'foo': 'bar'})
batch.send()

Expand All @@ -33,7 +33,7 @@ def test_send_adds_data_attribute(self):
)

def test_send_adds_permissions_attribute(self):
batch = Session(self.client)
batch = BatchSession(self.client)
batch.request('GET', '/foobar/baz',
permissions=mock.sentinel.permissions)
batch.send()
Expand All @@ -49,7 +49,7 @@ def test_send_adds_permissions_attribute(self):
)

def test_send_adds_headers_if_specified(self):
batch = Session(self.client)
batch = BatchSession(self.client)
batch.request('GET', '/foobar/baz', headers={'Foo': 'Bar'})
batch.send()

Expand All @@ -65,7 +65,7 @@ def test_send_adds_headers_if_specified(self):
)

def test_batch_send_multiple_requests_if_too_many_requests(self):
batch = Session(self.client, batch_max_requests=3)
batch = BatchSession(self.client, batch_max_requests=3)
for i in range(5):
batch.request('GET', '/foobar/%s' % i)
batch.send()
Expand All @@ -78,7 +78,7 @@ def test_batch_send_multiple_requests_if_too_many_requests(self):
assert kwargs2['payload']['requests'][0]['path'] == '/foobar/3'

def test_reset_empties_the_requests_cache(self):
batch = Session(self.client)
batch = BatchSession(self.client)
batch.request('GET', '/foobar/baz',
permissions=mock.sentinel.permissions)
assert len(batch.requests) == 1
Expand Down
2 changes: 1 addition & 1 deletion kinto_client/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_context_manager_works_as_expected(self):
'method': 'PUT',
'headers': {'If-None-Match': '*'}}]})

def test_context_manager_handle_delete(self):
def test_context_manager_handles_delete(self):
mock_batch(self.session)

with self.client.batch(bucket='mozilla', collection='test') as batch:
Expand Down

0 comments on commit 9c6e2ff

Please sign in to comment.