Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
    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)
Esempio n. 4
0
    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)
Esempio n. 5
0
    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)
Esempio n. 6
0
    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"])
Esempio n. 8
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"])