Server Tests¶
There are 5 tests covering server creation, database operations, custom config, context managers, and the default host. For advanced patterns (embedded + HTTP), see Server Patterns.
Note: the first four tests construct the server directly with the ArcadeDBServer class, are marked @pytest.mark.server, and are skipped unless server support is available.
Quick Example¶
import arcadedb_embedded as arcadedb
# Create and start server
server = arcadedb.create_server(
root_path="./databases",
root_password="mypassword"
)
server.start()
# Create database
# "mydb" will be created at ./databases/databases/mydb
db = server.create_database("mydb")
# Use it
db.command("sql", "CREATE DOCUMENT TYPE Person")
with db.transaction():
person = db.new_document("Person")
person.set("name", "Alice").save()
# Query
result = db.query("sql", "SELECT FROM Person")
for person in result:
print(person.get("name"))
# Stop server
server.stop()
Test Cases¶
1. Server Creation and Startup¶
Test: test_server_creation
from arcadedb_embedded import ArcadeDBServer
server = ArcadeDBServer(
root_path="./databases",
root_password="mypassword",
config={"http_port": 2480},
)
assert not server.is_started()
server.start()
assert server.is_started()
assert server.get_http_port() == 2480
assert "http://" in server.get_studio_url()
server.stop()
assert not server.is_started()
2. Database Operations Through Server¶
Test: test_server_database_operations
with arcadedb.create_server(root_path="./databases") as server:
server.start()
# Create database through server
db = server.create_database("testdb")
db.command("sql", "CREATE DOCUMENT TYPE Person")
with db.transaction():
person = db.new_document("Person")
person.set("name", "Alice").save()
# Query
result = db.query("sql", "SELECT FROM Person")
for person in result:
print(person.get("name"))
3. Custom Configuration¶
Test: test_server_custom_config
server = arcadedb.create_server(
root_path="./databases",
root_password="secure_password",
config={
"http_port": 8080,
"host": "127.0.0.1",
"mode": "production"
}
)
server.start()
assert server.get_http_port() == 8080
4. Context Manager¶
Test: test_server_context_manager
with ArcadeDBServer(root_path="./databases", root_password="mypassword") as server:
# Server auto-starts in the context manager
assert server.is_started()
# Server automatically stopped on exit
5. Default Host¶
Test: test_default_host_is_localhost
Verifies that the default host is localhost (binding to all interfaces must be
opt-in). The server is not started here; the assertion is made on the
publicly-observable Studio URL, which is a faithful proxy for the configured host.
from arcadedb_embedded.server import ArcadeDBServer
server = ArcadeDBServer(root_path="./databases", root_password="mypassword")
assert server.get_studio_url().startswith("http://localhost:")
Running These Tests¶
# Run all server tests
pytest tests/test_server.py -v
# Run specific test
pytest tests/test_server.py::test_server_creation -v
Related Documentation¶
- Server Patterns - Advanced patterns
- Server API Reference
- Server Guide
- Concurrency Tests - Multi-process access