How to use arango_test_ops method in testcontainers-python

Best Python code snippet using testcontainers-python_python

test_arangodb.py

Source:test_arangodb.py Github

copy

Full Screen

...5from arango import ArangoClient6from arango.exceptions import DatabaseCreateError, ServerVersionError7from testcontainers.arangodb import ArangoDbContainer8ARANGODB_IMAGE_NAME = 'arangodb'9def arango_test_ops(arango_client, expeced_version, db_user='root', db_pass=''):10 """11 Basic ArangoDB operations to test DB really up and running.12 """13 students_to_insert_cnt = 314 # Taken from https://github.com/ArangoDB-Community/python-arango/blob/main/README.md15 # Connect to "_system" database as root user.16 sys_db = arango_client.db("_system", username=db_user, password=db_pass)17 assert sys_db.version() == expeced_version18 # Create a new database named "test".19 sys_db.create_database("test")20 # Connect to "test" database as root user.21 database = arango_client.db("test", username=db_user, password=db_pass)22 # Create a new collection named "students".23 students = database.create_collection("students")24 # Add a hash index to the collection.25 students.add_hash_index(fields=["name"], unique=True)26 # Insert new documents into the collection. (students_to_insert_cnt)27 students.insert({"name": "jane", "age": 39})28 students.insert({"name": "josh", "age": 18})29 students.insert({"name": "judy", "age": 21})30 # Execute an AQL query and iterate through the result cursor.31 cursor = database.aql.execute("FOR doc IN students RETURN doc")32 student_names = [document["name"] for document in cursor]33 assert len(student_names) == students_to_insert_cnt34def test_docker_run_arango():35 """36 Test ArangoDB container with default settings.37 """38 image_version = '3.9.1'39 image = f'{ARANGODB_IMAGE_NAME}:{image_version}'40 arango_db_root_password = 'passwd'41 with ArangoDbContainer(image) as arango:42 client = ArangoClient(hosts=arango.get_connection_url())43 # Test invalid auth44 with pytest.raises(DatabaseCreateError):45 sys_db = client.db("_system", username="root", password='notTheRightPass')46 sys_db.create_database("test")47 arango_test_ops(48 arango_client=client,49 expeced_version=image_version,50 db_pass=arango_db_root_password)51def test_docker_run_arango_without_auth():52 """53 Test ArangoDB container with ARANGO_NO_AUTH var set.54 """55 image_version = '3.9.1'56 image = f'{ARANGODB_IMAGE_NAME}:{image_version}'57 with ArangoDbContainer(image, arango_no_auth=True) as arango:58 client = ArangoClient(hosts=arango.get_connection_url())59 arango_test_ops(60 arango_client=client,61 expeced_version=image_version,62 db_pass='')63def test_docker_run_arango_older_version():64 """65 Test ArangoDB container with older tag/version.66 the idea behind it hides in the logic of arangodb._connect() ->67 Where it waits the container to sign "ready for business" -68 If someone will change the logic in the future69 we must verify older image tags still supported. (without that logic - we'll face race issues70 where we try to create & populate DB when ArangoDB not really ready.71 """72 image_version = '3.1.7'73 image = f'{ARANGODB_IMAGE_NAME}:{image_version}'74 with ArangoDbContainer(image, arango_no_auth=True) as arango:75 client = ArangoClient(hosts=arango.get_connection_url())76 arango_test_ops(77 arango_client=client,78 expeced_version=image_version,79 db_pass='')80def test_docker_run_arango_random_root_password():81 """82 Test ArangoDB container with ARANGO_RANDOM_ROOT_PASSWORD var set.83 """84 image_version = '3.9.1'85 image = f'{ARANGODB_IMAGE_NAME}:{image_version}'86 arango_db_root_password = 'passwd'87 with ArangoDbContainer(image, arango_random_root_password=True) as arango:88 client = ArangoClient(hosts=arango.get_connection_url())89 # Test invalid auth (we don't know the password in random mode)90 with pytest.raises(ServerVersionError):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run testcontainers-python automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful