Skip to content

Commit

Permalink
Merge pull request pandas-dev#23 from manahl/arctic_init_library_impr…
Browse files Browse the repository at this point in the history
…ovement

Simplify arctic_init_library to not require the 'arctic_' prefix.
  • Loading branch information
jamesblackburn committed Aug 7, 2015
2 parents feffebe + 2f25f4c commit 9a0fc60
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
5 changes: 2 additions & 3 deletions arctic/scripts/arctic_init_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ def main():

opts = parser.parse_args()

if not opts.library or '.' not in opts.library \
or not opts.library.startswith('arctic'):
parser.error('Must specify the full path of the library e.g. arctic_jblackburn.library!')
if not opts.library or '.' not in opts.library:
parser.error('Must specify the full path of the library e.g. user.library!')
db_name, _ = ArcticLibraryBinding._parse_db_lib(opts.library)

print "Initializing: %s on mongo %s" % (opts.library, opts.host)
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/scripts/test_initialize_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ def test_init_library(mongo_host):
assert store['user.library'].read('key').data == {'a': 'b'}


def test_init_library_no_arctic_prefix(mongo_host):
# Create the user agains the current mongo database
with patch('arctic.scripts.arctic_init_library.do_db_auth', return_value=True), \
patch('pymongo.database.Database.authenticate', return_value=True):
run_as_main(mil.main, '--host', mongo_host, '--library', 'user.library')

# Should be able to write something to the library now
store = Arctic(mongo_host)
assert store['user.library']._arctic_lib.get_library_metadata('QUOTA') == 10240 * 1024 * 1024
store['user.library'].write('key', {'a': 'b'})
assert store['user.library'].read('key').data == {'a': 'b'}


def test_init_library_quota(mongo_host):
# Create the user agains the current mongo database
with patch('arctic.scripts.arctic_init_library.do_db_auth', return_value=True), \
Expand Down
9 changes: 2 additions & 7 deletions tests/unit/scripts/test_initialize_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,12 @@ def test_init_library_no_admin_no_user_creds():


def test_bad_library_name():
with pytest.raises(Exception):
with patch('argparse.ArgumentParser.error', side_effect=Exception) as error:
run_as_main(mil.main, '--library', 'user.library')
error.assert_called_once_with('Must specify the full path of the library e.g. arctic_jblackburn.library!')

with pytest.raises(Exception):
with patch('argparse.ArgumentParser.error', side_effect=Exception) as error:
run_as_main(mil.main, '--library', 'arctic_jblackburn')
error.assert_called_once_with('Must specify the full path of the library e.g. arctic_jblackburn.library!')
error.assert_called_once_with('Must specify the full path of the library e.g. user.library!')

with pytest.raises(Exception):
with patch('argparse.ArgumentParser.error', side_effect=Exception) as error:
run_as_main(mil.main)
error.assert_called_once_with('Must specify the full path of the library e.g. arctic_jblackburn.library!')
error.assert_called_once_with('Must specify the full path of the library e.g. user.library!')

0 comments on commit 9a0fc60

Please sign in to comment.