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_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_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 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. """ 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_exclude_references(self): db = Database("testdb") field = Field( "invoice-id", excludes=[FieldReference("http://foo.bar.com/invoice", "id")]) self.assertEqual(1, len(field.excludes())) self.assertEqual("http://foo.bar.com/invoice", field.excludes(0).namespace_uri()) self.assertEqual("id", field.excludes(0).localname())
def test_create_paths(self): db = Database(u'testdb') self.assertNotIn(u'path-namespaces', db.config) return_val = db.add_path_namespace("inv", "http://foo.bar.com/invoice") namespaces = db.path_namespaces() self.assertEqual(1, len(namespaces)) self.assertEqual("inv", namespaces[0][u'prefix']) self.assertEqual('http://foo.bar.com/invoice', namespaces[0][u'namespace-uri']) self.assertEqual(db, return_val)
def test_create_paths(self): db = Database(u'testdb') assert 'path-namespaces' not in db._config return_val = db.add_path_namespace( PathNamespace("inv", "http://foo.bar.com/invoice")) namespaces = db.path_namespaces() assert 1 == len(namespaces) assert "inv" == namespaces[0].prefix() assert 'http://foo.bar.com/invoice' == namespaces[0].namespace_uri() assert db == return_val
def test_create_paths(self): db = Database('testdb') self.assertNotIn('path-namespaces', db._config) return_val = db.add_path_namespace( PathNamespace("inv", "http://foo.bar.com/invoice")) namespaces = db.path_namespaces() self.assertEqual(1, len(namespaces)) self.assertEqual("inv", namespaces[0].prefix()) self.assertEqual('http://foo.bar.com/invoice', namespaces[0].namespace_uri()) self.assertEqual(db, return_val)
def test_create_field_range(self): db = Database("foo") field = Field("invoice-id") db.add_field(field) field_range = FieldRange("invoice-id", "int") db.add_index(field_range) index = db.field_range_index(0) self.assertEqual("invoice-id", index.name()) self.assertEqual("int", index.type()) indexes = db.field_range_index() self.assertEqual(1, len(indexes))
def test_create_field(self): db = Database("testdb") self.assertNotIn(u'fields', db.config) field = Field("invoice-id") field.add_path("bill:invoice-id", 1) field.add_path("inv:id", 1) result = db.add_field(field) self.assertIn(u'field', db.config) self.assertEqual(result, db) self.assertEqual(1, len(db.config[u'field'])) field = db.fields(0) self.assertEqual("invoice-id", field.name()) field = db.fields(0) self.assertEqual(2, len(field.paths())) self.assertEqual("bill:invoice-id", field.paths(0)[u'path']) self.assertEqual(1, field.paths()[0][u'weight'])
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
# # Copyright 2015 MarkLogic Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0# # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # from marklogic.models import Connection, Database, FieldRange, Field, FieldReference from requests.auth import HTTPDigestAuth auth = HTTPDigestAuth("admin", "admin") conn = Connection("192.168.57.141", auth) db = Database("range-field-test", "localhost.localdomain") field = Field("test-field", includes=[FieldReference("http://foo.bar.com/invoice", "id")]) db.add_field(field) db.add_index(FieldRange("test-field", "int")) db.create(conn)
__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"])