Best Python code snippet using localstack_python
test_documentmanager.py
Source:test_documentmanager.py
...22 def tearDownClass(cls):23 cls.database_manager.delete_database(DATABASE_NAME)24 def setUp(self):25 self.document_manager = DocumentManager(client)26 def test_create_get_delete_document(self):27 try:28 self.document_manager.upsert_document(29 DocumentManagerTests.get_test_document("foobar"),30 COLLECTION_NAME,31 DATABASE_NAME,32 )33 document = self.document_manager.get_document(34 "foobar", COLLECTION_NAME, DATABASE_NAME35 )36 self.assertEqual("foobar", document.resource_id)37 finally:38 self.document_manager.delete_document(39 "foobar", COLLECTION_NAME, DATABASE_NAME40 )41 def test_upsert_document(self):42 try:43 self.document_manager.upsert_document(44 DocumentManagerTests.get_test_document("foobar"),45 COLLECTION_NAME,46 DATABASE_NAME,47 )48 document = self.document_manager.upsert_document(49 DocumentManagerTests.get_test_document("foobar"),50 COLLECTION_NAME,51 DATABASE_NAME,52 )53 self.assertEqual("foobar", document.resource_id)54 finally:55 self.document_manager.delete_document(56 "foobar", COLLECTION_NAME, DATABASE_NAME57 )58 def test_get_documents(self):59 try:60 self.document_manager.upsert_document(61 DocumentManagerTests.get_test_document("foobar"),62 COLLECTION_NAME,63 DATABASE_NAME,64 )65 query_results = self.document_manager.get_documents(66 COLLECTION_NAME, DATABASE_NAME67 )68 self.assertEqual(1, len(query_results.fetch_next()))69 finally:70 self.document_manager.delete_document(71 "foobar", COLLECTION_NAME, DATABASE_NAME72 )73 def test_get_documents_with_max_item_count(self):74 try:75 for i in range(1, 11):76 self.document_manager.upsert_document(77 DocumentManagerTests.get_test_document(f"foobar-{i}"),78 COLLECTION_NAME,79 DATABASE_NAME,80 )81 query_results = self.document_manager.get_documents(82 COLLECTION_NAME, DATABASE_NAME, max_item_count=383 )84 self.assertEqual(3, len(query_results.fetch_next()))85 finally:86 for i in range(1, 11):87 self.document_manager.delete_document(88 f"foobar-{i}", COLLECTION_NAME, DATABASE_NAME89 )90 def test_delete_non_existent_document_raises_DocumentError(self):91 self.assertRaises(92 DocumentError, self.document_manager.delete_document, "foo", "bar", "baz"93 )94 def test_query_documents(self):95 try:96 self.document_manager.upsert_document(97 DocumentManagerTests.get_test_document("foobar"),98 COLLECTION_NAME,99 DATABASE_NAME,100 )101 query_result = self.document_manager.query_documents(102 COLLECTION_NAME, DATABASE_NAME, "SELECT * FROM r WHERE r.id='foobar'",103 )104 self.assertEqual(1, len(query_result.fetch_next()))105 finally:106 self.document_manager.delete_document(107 "foobar", COLLECTION_NAME, DATABASE_NAME108 )109 def test_query_documents_limit_results(self):110 try:111 for i in range(0, 10):112 self.document_manager.upsert_document(113 DocumentManagerTests.get_test_document(f"foobar-{i}"),114 COLLECTION_NAME,115 DATABASE_NAME,116 )117 query_result = self.document_manager.query_documents(118 COLLECTION_NAME,119 DATABASE_NAME,120 "SELECT * FROM r WHERE r.id>'0'",121 max_item_count=3,122 )123 documents: list = query_result.fetch_next()124 self.assertEqual(3, len(documents))125 finally:126 for i in range(0, 10):127 self.document_manager.delete_document(128 f"foobar-{i}", COLLECTION_NAME, DATABASE_NAME129 )130 def test_query_documents_with_parameters(self):131 try:132 self.document_manager.upsert_document(133 DocumentManagerTests.get_test_document("foobar"),134 COLLECTION_NAME,135 DATABASE_NAME,136 )137 query_result = self.document_manager.query_documents(138 COLLECTION_NAME,139 DATABASE_NAME,140 "SELECT * FROM r WHERE r.subtotal>@subtotal AND EXISTS(SELECT VALUE n FROM n in r.items WHERE n.product_id=@product_id)",141 [142 dict(name="@subtotal", value=400),143 dict(name="@product_id", value=100),144 ],145 )146 self.assertEqual(1, len(query_result.fetch_next()))147 finally:148 self.document_manager.delete_document(149 "foobar", COLLECTION_NAME, DATABASE_NAME150 )151 @staticmethod152 def get_test_document(document_id: str) -> dict:153 return {154 "id": document_id,155 "account_number": "Account1",156 "purchase_order_number": "PO18009186470",157 "order_date": date(2020, 5, 14).strftime("%c"),158 "subtotal": 419.4589,159 "tax_amount": 12.5838,160 "freight": 472.3108,161 "total_due": 985.018,162 "items": [...
urls.py
Source:urls.py
1"""notes URL Configuration2The `urlpatterns` list routes URLs to views. For more information please see:3 https://docs.djangoproject.com/en/3.0/topics/http/urls/4Examples:5Function views6 1. Add an import: from my_app import views7 2. Add a URL to urlpatterns: path('', views.home, name='home')8Class-based views9 1. Add an import: from other_app.views import Home10 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')11Including another URLconf12 1. Import the include() function: from django.urls import include, path13 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))14"""15from django.contrib import admin16from django.urls import path17from document .views import editor,delete_document18urlpatterns = [19 path('', editor,name = 'editor'),20 path('delete_document/<int:docid>/', delete_document, name='delete_document'),21 path('admin/', admin.site.urls),...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!