Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_overlay_library():
a = Mock(Arctic, autospec=True)
fix.overlay_library(a, "test")
a.initialize_library.assert_called_with("test_RAW", "VersionStore", segment='year')
def test_arctic_connect_with_environment_name():
with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True) as mc, \
patch('arctic.arctic.mongo_retry', autospec=True) as ar, \
patch('arctic.arctic.get_auth', autospec=True), \
patch('arctic._cache.Cache._is_not_expired', return_value=True), \
patch('arctic.arctic.get_mongodb_uri') as gmfe:
store = Arctic('live', socketTimeoutMS=sentinel.socket_timeout,
connectTimeoutMS=sentinel.connect_timeout,
serverSelectionTimeoutMS=sentinel.select_timeout)
# do something to trigger lazy arctic init
store.list_libraries()
assert gmfe.call_args_list == [call('live')]
assert mc.call_args_list == [call(host=gmfe.return_value, maxPoolSize=4,
socketTimeoutMS=sentinel.socket_timeout,
connectTimeoutMS=sentinel.connect_timeout,
serverSelectionTimeoutMS=sentinel.select_timeout)]
def test__conn_auth_issue():
auth_timeout = [0]
a = Arctic("host:12345")
sentinel.creds = Mock()
def flaky_auth(*args, **kwargs):
if not auth_timeout[0]:
auth_timeout[0] = 1
raise AutoReconnect()
with patch('arctic.arctic.authenticate', flaky_auth), \
patch('arctic.arctic.get_auth', return_value=sentinel.creds), \
patch('arctic._cache.Cache.__init__', autospec=True, return_value=None), \
patch('arctic.decorators._handle_error') as he:
a._conn
assert he.call_count == 1
assert auth_timeout[0]
def test_init_library(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', 'arctic_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_connect_to_Arctic_connection(mongo_server, mongo_host):
arctic = Arctic(mongo_server.api)
assert arctic.list_libraries() == []
assert arctic.mongo_host == mongo_host
def test_connect_to_Arctic_string(mongo_host):
arctic = Arctic(mongo_host=mongo_host)
assert arctic.list_libraries() == []
assert arctic.mongo_host == mongo_host
def arctic(mongo_server):
logger.info('arctic.fixtures: arctic init()')
mongo_server.api.drop_database('arctic')
mongo_server.api.drop_database('arctic_{}'.format(getpass.getuser()))
arctic = m.Arctic(mongo_host=mongo_server.api)
# Do not add global libraries here: use specific fixtures below.
# Remember, for testing it does not usually matter what your libraries are called.
return arctic
parser.add_option("--keep-mins", default=10, help="Ensure there's a version at least keep-mins old. Default:10")
(opts, _) = parser.parse_args()
if not opts.library:
parser.error('Must specify the Arctic library e.g. arctic_jblackburn.library!')
db_name, _ = ArcticLibraryBinding._parse_db_lib(opts.library)
print("Pruning (old) versions in : %s on mongo %s" % (opts.library, opts.host))
print("Keeping all versions <= %s mins old" % (opts.keep_mins))
c = pymongo.MongoClient(get_mongodb_uri(opts.host))
if not do_db_auth(opts.host, c, db_name):
logger.error('Authentication Failed. Exiting.')
return
lib = Arctic(c)[opts.library]
if opts.symbols:
symbols = opts.symbols.split(',')
else:
symbols = lib.list_symbols(all_symbols=True)
logger.info("Found %s symbols" % len(symbols))
prune_versions(lib, symbols, opts.keep_mins)
logger.info("Done")
parser.add_argument("--host", default='localhost', help="Hostname, or clustername. Default: localhost")
parser.add_argument("--library", nargs='+', required=True, help="The name of the library. e.g. 'arctic_jblackburn.lib'")
parser.add_argument("-v", action='store_true', help="Verbose mode")
parser.add_argument("-f", action='store_true', help="Force ; Cleanup any problems found. (Default is dry-run.)")
parser.add_argument("-n", action='store_true', help="No FSCK ; just print stats.)")
opts = parser.parse_args()
if opts.v:
logger.setLevel(logging.DEBUG)
if not opts.f:
logger.info("DRY-RUN: No changes will be made.")
logger.info("FSCK'ing: %s on mongo %s" % (opts.library, opts.host))
store = Arctic(get_mongodb_uri(opts.host))
for lib in opts.library:
# Auth to the DB for making changes
if opts.f:
database_name, _ = ArcticLibraryBinding._parse_db_lib(lib)
do_db_auth(opts.host, store._conn, database_name)
orig_stats = store[lib].stats()
logger.info('----------------------------')
if not opts.n:
store[lib]._fsck(not opts.f)
logger.info('----------------------------')
final_stats = store[lib].stats()
logger.info('Stats:')