def test_lookup(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) privilege = Privilege.lookup(connection, "manage-admin", "execute") self.assertIsNotNone(privilege) self.assertEqual(privilege.privilege_name(), "manage-admin")
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_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_list(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) names = Server.list(connection) self.assertGreater(len(names), 3) self.assertIn("Default|Manage", names)
def test_load_data(self): simpledb = SimpleDatabase("example_app", port=8400) conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) ## auth = HTTPDigestAuth("admin", "admin") ## conn = Connection("192.168.1.11", auth) exampledb = simpledb.create(conn) loader = MLCPLoader() loader.download_mlcp() try: loader.load_directory(conn, exampledb[u'content'], "../../examples/data", collections=["example1"], prefix="/test/data1") self.assertIsNotNone(exampledb[u'content'].get_document( conn, "/test/data1/purchases/december/purchase-001.json")) self.assertIsNotNone(exampledb[u'content'].get_document( conn, "/test/data1/customer-001.json")) finally: exampledb[u'server'].remove(conn) print("Pausing 15 seconds for server restart") time.sleep(15) exampledb[u'modules'].remove(conn) exampledb[u'content'].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 test_lookup(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) role = Role.lookup("admin", connection) self.assertIsNotNone(role) self.assertEqual(role.name(), "admin")
def test_list(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) privileges = Privilege.list(connection) self.assertGreater(len(privileges), 300) self.assertIn("execute|manage-admin", privileges)
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_lookup(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) user = User.lookup("nobody", connection) self.assertIsNotNone(user) self.assertEqual(user.name(), "nobody")
def test_lookup(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) role = Role.lookup(connection, "admin") self.assertIsNotNone(role) self.assertEqual(role.role_name(), "admin")
def test_list(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) roles = Role.list_roles(connection) names = [role.name() for role in roles] self.assertGreater(len(names), 65) self.assertIn("admin", names)
def test_load(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) server = HttpServer("Manage", "Default") self.assertEqual(server.server_name(), "Manage") self.assertIsNotNone(server.read(connection)) self.assertEqual("http", server.server_type())
def test_lookup(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) server = Server.lookup(connection, "Manage") self.assertIsNotNone(server) self.assertEqual(server.server_name(), "Manage")
def test_list(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) users = User.list_users(connection) names = [user.name() for user in users] self.assertGreater(len(names), 2) self.assertIn("nobody", names)
def test_list(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) names = Role.list(connection) self.assertGreater(len(names), 65) self.assertIn("admin", names)
def test_lookup(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) user = User.lookup("nobody", connection) self.assertIsNotNone(user) self.assertEqual(user.name(), "nobody")
def test_list(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) users = User.list_users(connection) names = [user.name() for user in users] self.assertGreater(len(names), 2) self.assertIn("nobody", names)
def test_list_databases(self): conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) databases = Database.list_databases(conn) self.assertGreater(len(databases), 4) db_names = [db.database_name() for db in databases] self.assertTrue("Modules" in db_names) self.assertTrue("Documents" in db_names)
def test_save_privilege(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) privilege = Privilege("foo-privilege","http://example.com/","execute") privilege.create(connection) privilege.add_role_name("manage-user") privilege.update(connection) self.assertIn("manage-user", privilege.role_names()) privilege.delete(connection)
def test_create_webdav_server(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) server = WebDAVServer("foo-webdav", "Default", 10101, '/', 'Documents') self.assertEqual(server.server_name(), "foo-webdav") server.create(connection) self.assertIsNotNone(server) self.assertEqual("webdav", server.server_type()) server.delete(connection) server = Server.lookup(connection, "foo-webdav") self.assertIsNone(server)
def test_create_remove_privilege(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) privilege = Privilege("foo-privilege","http://example.com/","execute") privilege.create(connection) the_privilege = Privilege.lookup(connection, "foo-privilege", "execute") self.assertIsNotNone(the_privilege) the_privilege.delete(connection) the_privilege = Privilege.lookup(connection, "foo-privilege", "execute") self.assertIsNone(the_privilege)
def test_create_remove_role(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) role = Role("foo-role") role.create(connection) the_role = Role.lookup("foo-role", connection) self.assertIsNotNone(the_role) the_role.remove(connection) the_role = Role.lookup("foo-role", connection) self.assertIsNone(the_role)
def test_create_privilege(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) new_privilege = Privilege("foo-privilege","http://example.com/","execute") self.assertEqual(new_privilege.privilege_name(), "foo-privilege") new_privilege.create(connection) privileges = Privilege.list(connection) self.assertIn("execute|foo-privilege", privileges) new_privilege.delete(connection)
def test_create_remove_user(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) user = User("foo-user") user.create(connection) the_user = User.lookup("foo-user", connection) self.assertIsNotNone(the_user) the_user.remove(connection) the_user = User.lookup("foo-user", connection) self.assertIsNone(the_user)
def test_create_remove_role(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) role = Role("foo-role") role.create(connection) the_role = Role.lookup(connection, "foo-role") self.assertIsNotNone(the_role) the_role.delete(connection) the_role = Role.lookup(connection, "foo-role") self.assertIsNone(the_role)
def test_create_remove_user(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) user = User("foo-user") user.create(connection) the_user = User.lookup("foo-user", connection) self.assertIsNotNone(the_user) the_user.remove(connection) the_user = User.lookup("foo-user", connection) self.assertIsNone(the_user)
def test_save_role(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) role = Role("foo-role") self.assertIsNone(role.create(connection).description()) role.set_description("This is the foo role") role.save(connection) role = Role.lookup("foo-role", connection) self.assertEqual("This is the foo role", role.description()) role.remove(connection)
def test_save_user(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) user = User("foo-user") self.assertIsNone(user.create(connection).description()) user.set_description("This is the foo user") user.save(connection) user = User.lookup("foo-user", connection) self.assertEqual("This is the foo user", user.description()) user.remove(connection)
def test_save_role(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) role = Role("foo-role") self.assertIsNone(role.create(connection).description()) role.set_description("This is the foo role") role.update(connection) role = Role.lookup(connection, "foo-role") self.assertEqual("This is the foo role", role.description()) role.delete(connection)
def test_save_user(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) user = User("foo-user") self.assertIsNone(user.create(connection).description()) user.set_description("This is the foo user") user.save(connection) user = User.lookup("foo-user", connection) self.assertEqual("This is the foo user", user.description()) user.remove(connection)
def test_no_database_found(self): conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) db = Database.lookup(conn, "No-Such-Database") self.assertIsNone(db)
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])
# # 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"])