|
| 1 | +import pytest |
| 2 | +from packaging import version |
| 3 | + |
| 4 | +from arango.client import ArangoClient |
1 | 5 | from arango.collection import StandardCollection
|
2 | 6 | from arango.exceptions import (
|
3 | 7 | CollectionChecksumError,
|
|
13 | 17 | CollectionStatisticsError,
|
14 | 18 | CollectionTruncateError,
|
15 | 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, |
16 | 28 | )
|
17 |
| -from tests.helpers import assert_raises, extract, generate_col_name |
18 | 29 |
|
19 | 30 |
|
20 | 31 | def test_collection_attributes(db, col, username):
|
@@ -228,3 +239,84 @@ def test_collection_management(db, bad_db, cluster):
|
228 | 239 | with assert_raises(CollectionRenameError) as err:
|
229 | 240 | bad_db.collection(new_name).rename(new_name)
|
230 | 241 | assert err.value.error_code in {11, 1228}
|
| 242 | + |
| 243 | + |
| 244 | +@pytest.fixture |
| 245 | +def special_collection_names(db): |
| 246 | + names = ["abc123", "maçã", "mötör", "😀", "ﻚﻠﺑ ﻞﻄﻴﻓ", "かわいい犬"] |
| 247 | + |
| 248 | + yield names |
| 249 | + |
| 250 | + for name in names: |
| 251 | + try: |
| 252 | + db.delete_collection(name) |
| 253 | + except CollectionDeleteError: |
| 254 | + pass |
| 255 | + |
| 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 | + |
| 271 | +def test_collection_utf8(db, db_version, special_collection_names): |
| 272 | + if db_version < version.parse("3.11.0"): |
| 273 | + pytest.skip("UTF8 collection names require ArangoDB 3.11+") |
| 274 | + |
| 275 | + for name in special_collection_names: |
| 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