def test_create_single_detailed_forest(self): """ Test the following scenario: The database is given a forest object. It should create a forest with the given name. That forest should match the features of the datailed forest. """ hosts = Host.list(self.connection) db = Database("detailed-forest-create-test-db", hosts[0]) forest = Forest("detailed-forest-create-forest1", host=hosts[0]) forest.set_large_data_directory("") db.set_forest_names([forest.forest_name()]) db.create(self.connection) forest = Forest.lookup(self.connection, "detailed-forest-create-forest1") try: assert "detailed-forest-create-forest1" == forest.forest_name() #this isn't in the properties...oddly. #self.assertEqual(ds.large_data_directory, forest.large_data_directory()) finally: db.delete(connection=self.connection)
def test_create_simple_forests(self): """ Test the following scenario: The database is given the names of two forests. It should then create the two named forests. """ conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) hosts = Host.list_hosts(conn) db = Database("simple-forest-create-test-db", hosts[0].host_name()) db.set_forests(["simple-forest-create-forest1", "simple-forest-create-forest2"]) db.create(conn) db = Database.lookup("simple-forest-create-test-db", conn) try: self.assertEqual(2, len(db.forests())) self.assertIn("simple-forest-create-forest1", db.forests()) self.assertIn("simple-forest-create-forest2", db.forests()) finally: db.remove(conn)
def test_create_simple_forests(self): """ Test the following scenario: The database is given the names of two forests. It should then create the two named forests. """ conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) hosts = Host.list(conn) db = Database("simple-forest-create-test-db", hosts[0]) db.set_forest_names( ["simple-forest-create-forest1", "simple-forest-create-forest2"]) db.create(conn) db = Database.lookup(conn, "simple-forest-create-test-db") try: self.assertEqual(2, len(db.forest_names())) self.assertIn("simple-forest-create-forest1", db.forest_names()) self.assertIn("simple-forest-create-forest2", db.forest_names()) finally: db.delete(conn)
def test_simple_create(self): """ TODO: The hostname should come from the server's hostname Test the basic create function. Creates a database and then check to see that it exists by getting the database configuration from the server. It then destroys the database. :return: None """ conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) hosts = Host.list_hosts(conn) db = Database("test-db", hosts[0].host_name()) db.create(conn) validate_db = Database.lookup("test-db", conn) try: self.assertIsNotNone(validate_db) self.assertEqual('test-db', validate_db.database_name()) finally: validate_db.remove(conn) validate_db = Database.lookup("test-db", conn) self.assertIsNone(validate_db)
def test_create_simple_forests(self): """ Test the following scenario: The database is given the names of two forests. It should then create the two named forests. """ hosts = Host.list(self.connection) db = Database("simple-forest-create-test-db", hosts[0], connection=self.connection) db.set_forest_names( ["simple-forest-create-forest1", "simple-forest-create-forest2"]) db.create() db = Database.lookup(self.connection, "simple-forest-create-test-db") try: assert 2 == len(db.forest_names()) assert "simple-forest-create-forest1" in db.forest_names() assert "simple-forest-create-forest2" in db.forest_names() finally: db.delete(connection=self.connection)
def test_create_forest(self): conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) host = Host.list(conn)[0] forest = Forest( "test-forest-simple-create", host=host, large_data_directory=ds.large_data_directory, fast_data_directory=ds.fast_data_directory, ) forest.create(conn) forest = Forest.lookup(conn, "test-forest-simple-create") try: self.assertIsNotNone(forest) self.assertEqual("test-forest-simple-create", forest.forest_name()) self.assertEqual(host.host_name(), forest.host()) self.assertEqual(ds.large_data_directory, forest.large_data_directory()) self.assertEqual(ds.fast_data_directory, forest.fast_data_directory()) finally: forest.remove(conn)
def test_create_single_detailed_forest(self): """ Test the following scenario: The database is given a forest object. It should create a forest with the given name. That forest should match the features of the datailed forest. """ conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) hosts = Host.list_hosts(conn) db = Database("detailed-forest-create-test-db", hosts[0].host_name()) forest = Forest("detailed-forest-create-forest1", host=hosts[0].host_name(), large_data_directory=ds.large_data_directory) db.set_forests([forest]) db.create(conn) forest = Forest.lookup("detailed-forest-create-forest1", conn) try: self.assertEqual("detailed-forest-create-forest1", forest.name()) self.assertEqual(ds.large_data_directory, forest.large_data_directory()) finally: db.remove(conn)
def test_create_single_detailed_forest(self): """ Test the following scenario: The database is given a forest object. It should create a forest with the given name. That forest should match the features of the datailed forest. """ conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) hosts = Host.list(conn) db = Database("detailed-forest-create-test-db", hosts[0]) forest = Forest("detailed-forest-create-forest1", host=hosts[0], large_data_directory=ds.large_data_directory) db.set_forest_names([forest.forest_name()]) db.create(conn) forest = Forest.lookup(conn, "detailed-forest-create-forest1") try: self.assertEqual("detailed-forest-create-forest1", forest.forest_name()) self.assertEqual(ds.large_data_directory, forest.large_data_directory()) finally: db.delete(conn)
def test_load_data(self): simpledb = SimpleDatabase("example_app", port=8400) conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) hostname = Host.list(conn)[0] exampledb = simpledb.create(conn, hostname) loader = MLCPLoader() loader.download_mlcp() try: loader.load_directory(conn, exampledb['content'], os.path.join("examples", "data"), collections=["example1"], prefix="/test/data1") self.assertIsNotNone(exampledb['content'].get_document( conn, "/test/data1/purchases/december/purchase-001.json")) self.assertIsNotNone(exampledb['content'].get_document( conn, "/test/data1/customer-001.json")) finally: exampledb['server'].delete(conn) exampledb['modules'].delete(conn) exampledb['content'].delete(conn)
def __init__(self): self.name = settings['BOT_NAME'] self.OUTFolder = settings['OUT_FOLDER'] log.msg("---{0} OUT_FOLDER={1}".format(self.name, self.OUTFolder), level=log.DEBUG) if not os.path.exists(self.OUTFolder): os.makedirs(self.OUTFolder) self.fmt = settings['MARKLOGIC_FORMAT'] self.DO_MarkLogic = settings['MARKLOGIC_UPLOAD'] if self.DO_MarkLogic: self.KeepOrig = settings['MARKLOGIC_KEEP_ORIGINAL_FILE'] self.ML_Host = settings['MARKLOGIC_HOSTNAME'] log.msg("---{0} MARKLOGIC_HOSTNAME={1}".format(self.name, self.ML_Host), level=log.DEBUG) self.admin = settings['MARKLOGIC_ADMIN'] self.password = settings['MARKLOGIC_PASSWORD'] self.db_name = settings['MARKLOGIC_DB'] log.msg("---{0}: MarkLogic Database initialization: {1}".format(self.name, self.db_name), level=log.DEBUG) self.conn = Connection(self.ML_Host, HTTPDigestAuth(self.admin, self.password)) self.db = Database.lookup(self.conn, self.db_name) if self.db == None: log.msg("---{0}: MarkLogic Database {1} does not exist, creating on host: {2}.".format(self.name, self.db_name, self.ML_Host), level=log.DEBUG) hosts = Host.list(self.conn) self.db = Database(self.db_name, hosts[0]) self.db.create(self.conn) else: log.msg("---{0}: MarkLogic Database {1} already exists on host: {2}.".format(self.name, self.db_name, self.ML_Host), level=log.DEBUG)
def test_create_single_detailed_forest(self): """ Test the following scenario: The database is given a forest object. It should create a forest with the given name. That forest should match the features of the datailed forest. """ hosts = Host.list(self.connection) db = Database("detailed-forest-create-test-db", hosts[0]) forest = Forest("detailed-forest-create-forest1", host=hosts[0]) forest.set_large_data_directory("") db.set_forest_names([forest.forest_name()]) db.create(self.connection) forest = Forest.lookup(self.connection, "detailed-forest-create-forest1") try: assert "detailed-forest-create-forest1" == forest.forest_name() # this isn't in the properties...oddly. # self.assertEqual(ds.large_data_directory, forest.large_data_directory()) finally: db.delete(connection=self.connection)
def test_simple_create(self): """ TODO: The hostname should come from the server's hostname Test the basic create function. Creates a database and then check to see that it exists by getting the database configuration from the server. It then destroys the database. :return: None """ conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) hosts = Host.list(conn) db = Database("test-db", hosts[0]) db.create(conn) validate_db = Database.lookup(conn, "test-db") try: self.assertIsNotNone(validate_db) self.assertEqual('test-db', validate_db.database_name()) finally: validate_db.delete(conn) validate_db = Database.lookup(conn, "test-db") self.assertIsNone(validate_db)
def load_data(self): simpleapp = SimpleApplication(tc.appname, tc.port) conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) hostname = Host.list(conn)[0] exampleapp = simpleapp.create(conn, hostname) loader = MLCPLoader() loader.load_directory(conn, exampleapp['content'], "data", collections=["example1"], prefix="/test/data1")
def test_create_forest(self): conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) host = Host.list_hosts(conn)[0] forest = Forest("test-forest-simple-create", host=host.host_name(), large_data_directory=ds.large_data_directory, fast_data_directory=ds.fast_data_directory, ) forest.create(conn) forest = Forest.lookup("test-forest-simple-create", conn) try: self.assertIsNotNone(forest) self.assertEqual("test-forest-simple-create", forest.name()) self.assertEqual(host.host_name(), forest.host()) self.assertEqual(ds.large_data_directory, forest.large_data_directory()) self.assertEqual(ds.fast_data_directory, forest.fast_data_directory()) finally: forest.remove(conn)
def test_create_forest(self): host = Host.list(self.connection)[0] forest = Forest("test-forest-simple-create", host=host) forest.set_large_data_directory("") forest.set_fast_data_directory("") forest.create(self.connection) forest = Forest.lookup(self.connection, "test-forest-simple-create") try: assert forest is not None assert "test-forest-simple-create" == forest.forest_name() assert host == forest.host() assert "" == forest.large_data_directory() assert "" == forest.fast_data_directory() finally: forest.delete(connection=self.connection)
def test_create_forest(self): conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) host = Host.list(conn)[0] forest = Forest("test-forest-simple-create", host=host) forest.set_large_data_directory(ds.large_data_directory) forest.set_fast_data_directory(ds.fast_data_directory) forest.create(conn) forest = Forest.lookup(conn, "test-forest-simple-create") try: self.assertIsNotNone(forest) self.assertEqual("test-forest-simple-create", forest.forest_name()) self.assertEqual(host, forest.host()) self.assertEqual(ds.large_data_directory, forest.large_data_directory()) self.assertEqual(ds.fast_data_directory, forest.fast_data_directory()) finally: forest.delete(connection=conn)
def test_create_simple_forests(self): """ Test the following scenario: The database is given the names of two forests. It should then create the two named forests. """ hosts = Host.list(self.connection) db = Database("simple-forest-create-test-db", hosts[0], connection=self.connection) db.set_forest_names(["simple-forest-create-forest1", "simple-forest-create-forest2"]) db.create() db = Database.lookup(self.connection, "simple-forest-create-test-db") try: assert 2 == len(db.forest_names()) assert "simple-forest-create-forest1" in db.forest_names() assert "simple-forest-create-forest2" in db.forest_names() finally: db.delete(connection=self.connection)
def test_simple_create(self): """TODO: The hostname should come from the server's hostname Test the basic create function. Creates a database and then check to see that it exists by getting the database configuration from the server. It then destroys the database. :return: None """ hosts = Host.list(self.connection) db = Database("test-db", hosts[0]) db.create(self.connection) validate_db = Database.lookup(self.connection, "test-db") try: assert validate_db is not None assert 'test-db' == validate_db.database_name() finally: validate_db.delete(connection=self.connection) validate_db = Database.lookup(self.connection, "test-db") assert validate_db is None
def test_simple_create(self): """TODO: The hostname should come from the server's hostname Test the basic create function. Creates a database and then check to see that it exists by getting the database configuration from the server. It then destroys the database. :return: None """ hosts = Host.list(self.connection) db = Database("test-db", hosts[0]) db.create(self.connection) validate_db = Database.lookup(self.connection, "test-db") try: assert validate_db is not None assert "test-db" == validate_db.database_name() finally: validate_db.delete(connection=self.connection) validate_db = Database.lookup(self.connection, "test-db") assert validate_db is None
def test_list_hosts(self): hosts = Host.list(self.connection) assert len(hosts) > 0 assert hosts
def test_list_hosts(self): conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) hosts = Host.list_hosts(conn) self.assertGreater(len(hosts), 0) self.assertIsNotNone(hosts[0])
__author__ = 'phoehne' from requests.auth import HTTPDigestAuth from marklogic.models import Database, Connection, Host, HttpServer, ElementRange, ElementAttributeRange conn = Connection("192.168.57.141", HTTPDigestAuth("admin", "admin")) server_hostname = hosts = Host.list_hosts(conn)[0].host_name() db = Database("test-one", server_hostname) db.create(conn).load_file(conn, "example_doc.json", "/test/document.json", ["example", "collection"]) modules = Database("test-one-modules", server_hostname) modules.create(conn) db = Database.lookup("test-one", conn) db.add_index(ElementRange("order-id", u'int')) db.add_index( ElementAttributeRange("customer", "id", scalar_type=u'int', element_namespace="http://foo.bar.com")) db.save(conn) srvr = HttpServer("test-one-http", 8400) srvr.set_content_database(db.config[u'database-name']).set_modules_database( modules.config[u'database-name']) srvr.create(conn) db.load_file(conn, "example_doc.json", "/example/file.json", ["test"])
def test_list_hosts(self): conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) hosts = Host.list(conn) self.assertGreater(len(hosts), 0) self.assertIsNotNone(hosts[0])
__author__ = 'phoehne' from requests.auth import HTTPDigestAuth from marklogic.models import Database, Connection, Host, HttpServer, ElementRange, ElementAttributeRange conn = Connection("192.168.57.141", HTTPDigestAuth("admin", "admin")) server_hostname = hosts = Host.list_hosts(conn)[0].host_name() db = Database("test-one", server_hostname) db.create(conn).load_file(conn, "example_doc.json", "/test/document.json", ["example", "collection"]) modules = Database("test-one-modules", server_hostname) modules.create(conn) db = Database.lookup("test-one", conn) db.add_index(ElementRange("order-id", u'int')) db.add_index(ElementAttributeRange("customer", "id", scalar_type=u'int', element_namespace="http://foo.bar.com")) db.save(conn) srvr = HttpServer("test-one-http", 8400) srvr.set_content_database(db.config[u'database-name']).set_modules_database(modules.config[u'database-name']) srvr.create(conn) db.load_file(conn, "example_doc.json", "/example/file.json", ["test"]) db.load_directory_files(conn, "data", "/test/data/", ["test2"]) db.load_directory(conn, "data", collections=["this", "that"])