|
1 | 1 | import pytest
|
2 | 2 | from packaging import version
|
3 | 3 |
|
| 4 | +from arango.client import ArangoClient |
4 | 5 | from arango.collection import StandardCollection
|
5 | 6 | from arango.exceptions import (
|
6 | 7 | CollectionChecksumError,
|
|
16 | 17 | CollectionStatisticsError,
|
17 | 18 | CollectionTruncateError,
|
18 | 19 | CollectionUnloadError,
|
| 20 | + DatabaseDeleteError, |
| 21 | +) |
| 22 | +from tests.helpers import ( |
| 23 | + assert_raises, |
| 24 | + extract, |
| 25 | + generate_col_name, |
| 26 | + generate_string, |
| 27 | + generate_username, |
19 | 28 | )
|
20 |
| -from tests.helpers import assert_raises, extract, generate_col_name |
21 | 29 |
|
22 | 30 |
|
23 | 31 | def test_collection_attributes(db, col, username):
|
@@ -246,15 +254,69 @@ def special_collection_names(db):
|
246 | 254 | pass
|
247 | 255 |
|
248 | 256 |
|
| 257 | +# Code duplication from `test_database.py`... |
| 258 | +@pytest.fixture |
| 259 | +def special_db_names(sys_db): |
| 260 | + names = ["abc123", "maçã", "mötör", "😀", "ﻚﻠﺑ ﻞﻄﻴﻓ", "かわいい犬"] |
| 261 | + |
| 262 | + yield names |
| 263 | + |
| 264 | + for name in names: |
| 265 | + try: |
| 266 | + sys_db.delete_database(name) |
| 267 | + except DatabaseDeleteError: |
| 268 | + pass |
| 269 | + |
| 270 | + |
249 | 271 | def test_collection_utf8(db, db_version, special_collection_names):
|
250 | 272 | if db_version < version.parse("3.11.0"):
|
251 | 273 | pytest.skip("UTF8 collection names require ArangoDB 3.11+")
|
252 | 274 |
|
253 | 275 | for name in special_collection_names:
|
254 |
| - col = db.create_collection(name) |
255 |
| - assert col.name == name |
256 |
| - assert db.has_collection(name) is True |
257 |
| - index_id = col.add_hash_index(fields=["foo"])["name"] |
258 |
| - assert index_id == col.indexes()[-1]["name"] |
259 |
| - assert db.delete_collection(name) is True |
260 |
| - assert db.has_collection(name) is False |
| 276 | + create_and_delete_collection(db, name) |
| 277 | + |
| 278 | + |
| 279 | +# Not sure if this belongs in here or in `test_database.py`... |
| 280 | +def test_database_and_collection_utf8( |
| 281 | + sys_db, db_version, special_collection_names, special_db_names |
| 282 | +): |
| 283 | + if db_version < version.parse("3.11.0"): |
| 284 | + pytest.skip("UTF8 collection names require ArangoDB 3.11+") |
| 285 | + |
| 286 | + client = ArangoClient(hosts="http://127.0.0.1:8529") |
| 287 | + for db_name in special_db_names: |
| 288 | + username = generate_username() |
| 289 | + password = generate_string() |
| 290 | + |
| 291 | + assert sys_db.create_database( |
| 292 | + name=db_name, |
| 293 | + users=[ |
| 294 | + { |
| 295 | + "active": True, |
| 296 | + "username": username, |
| 297 | + "password": password, |
| 298 | + } |
| 299 | + ], |
| 300 | + ) |
| 301 | + |
| 302 | + assert sys_db.has_database(db_name) |
| 303 | + |
| 304 | + db = client.db(db_name, username, password, verify=True) |
| 305 | + |
| 306 | + for col_name in special_collection_names: |
| 307 | + create_and_delete_collection(db, col_name) |
| 308 | + |
| 309 | + assert sys_db.delete_database(db_name) |
| 310 | + |
| 311 | + |
| 312 | +def create_and_delete_collection(db, name): |
| 313 | + col = db.create_collection(name) |
| 314 | + assert col.name == name |
| 315 | + assert db.has_collection(name) is True |
| 316 | + |
| 317 | + index_id = col.add_hash_index(fields=["foo"])["name"] |
| 318 | + assert index_id == col.indexes()[-1]["name"] |
| 319 | + assert col.delete_index(index_id) is True |
| 320 | + |
| 321 | + assert db.delete_collection(name) is True |
| 322 | + assert db.has_collection(name) is False |
0 commit comments