def upload(storetype, url, database, filename, dirname, subdir, extension, verbose=False): config = MongoStorageConfiguration() config.url = url config.database = database engine = MongoStorageEngine(config) engine.initialise() store = Uploader._get_store(storetype, engine) outputLog(None, "Emptying [%s]" % storetype) store.empty() outputLog(None, "Loading [%s]" % storetype) if filename is not None: count, success = store.upload_from_file(filename, fileformat=Store.TEXT_FORMAT, commit=True, verbose=verbose) outputLog(None, "Lines processed: %d" % count) outputLog(None, "Entities successful: %d" % success) elif dirname is not None: count, success = store.upload_from_directory(directory=dirname, subdir=subdir, extension=extension, commit=True, verbose=verbose) outputLog(None, "Lines processed: %d" % count) outputLog(None, "Entities successful: %d" % success) else: raise Exception("You must specify either --file or --dir") return count, success
def test_create_mongostorage_config_no_defaults(self): config = MongoStorageConfiguration() config.url = 'mongodb://localhost:666/' config.database = "testy" config.drop_all_first = False self.assertEquals({'database': 'testy', 'drop_all_first': False, 'url': 'mongodb://localhost:666/'}, config.create_mongostorage_config())
def test_getters_setters(self): config = MongoStorageConfiguration() config.url = 'mongodb://localhost:666/' self.assertEquals(config.url, 'mongodb://localhost:666/') config.database = "testy" self.assertEquals("testy", config.database) config.drop_all_first = False self.assertFalse(config.drop_all_first)
def test_to_yaml_no_defaults(self): config = MongoStorageConfiguration() config.url = 'mongodb://localhost:666/' config.database = "testy" config.drop_all_first = False data = {} config.to_yaml(data, defaults=False) self.assertEquals({'database': 'testy', 'drop_all_first': False, 'url': 'mongodb://localhost:666/'}, data)