How to use get_document method in localstack

Best Python code snippet using localstack_python

views.py

Source:views.py Github

copy

Full Screen

...18 object_verbose_name = _('Comment')19 def dispatch(self, request, *args, **kwargs):20 AccessControlList.objects.check_access(21 permissions=permission_comment_create, user=request.user,22 obj=self.get_document()23 )24 return super(25 DocumentCommentCreateView, self26 ).dispatch(request, *args, **kwargs)27 def get_document(self):28 return get_object_or_404(Document, pk=self.kwargs['pk'])29 def get_extra_context(self):30 return {31 'object': self.get_document(),32 'title': _('Add comment to document: %s') % self.get_document(),33 }34 def get_instance_extra_data(self):35 return {36 'document': self.get_document(), 'user': self.request.user,37 }38 def get_save_extra_data(self):39 return {40 '_user': self.request.user,41 }42 def get_post_action_redirect(self):43 return reverse(44 'comments:comments_for_document', args=(self.kwargs['pk'],)45 )46class DocumentCommentDeleteView(SingleObjectDeleteView):47 model = Comment48 def dispatch(self, request, *args, **kwargs):49 AccessControlList.objects.check_access(50 permissions=permission_comment_delete, user=request.user,51 obj=self.get_object().document52 )53 return super(54 DocumentCommentDeleteView, self55 ).dispatch(request, *args, **kwargs)56 def get_delete_extra_data(self):57 return {'_user': self.request.user}58 def get_extra_context(self):59 return {60 'object': self.get_object().document,61 'title': _('Delete comment: %s?') % self.get_object(),62 }63 def get_post_action_redirect(self):64 return reverse(65 'comments:comments_for_document',66 args=(self.get_object().document.pk,)67 )68class DocumentCommentListView(SingleObjectListView):69 def get_document(self):70 return get_object_or_404(Document, pk=self.kwargs['pk'])71 def get_extra_context(self):72 return {73 'hide_link': True,74 'hide_object': True,75 'object': self.get_document(),76 'title': _('Comments for document: %s') % self.get_document(),77 }78 def get_object_list(self):79 AccessControlList.objects.check_access(80 permissions=permission_comment_view, user=self.request.user,81 obj=self.get_document()82 )...

Full Screen

Full Screen

patch_atomic_concurrency.py

Source:patch_atomic_concurrency.py Github

copy

Full Screen

...11The atomic ETag check was removed during issue #920 in 54fd69712When running Eve in a scale-out environment (multiple processes),13concurrent simultaneous updates are sometimes allowed, because14the Python-only ETag check is not atomic.15There is a critical section in patch_internal() between get_document()16and app.data.update() where a competing Eve process can change the17document and ETag.18This test simulates another process changing data & ETag during19the critical section. The test patches get_document() to return an20intentionally wrong ETag.21"""22def get_document_simulate_concurrent_update(*args, **kwargs):23 """24 Hostile version of get_document25 This simluates another process updating MongoDB (and ETag) in26 eve.methods.patch.patch_internal() during the critical area27 between get_document() and app.data.update()28 """29 document = eve.methods.common.get_document(*args, **kwargs)30 document[config.ETAG] = "unexpected change!"31 return document32class TestPatchAtomicConcurrent(TestBase):33 def setUp(self):34 """35 Patch eve.methods.patch.get_document with a hostile version36 that simulates simultaneous updates37 """38 self.original_get_document = sys.modules["eve.methods.patch"].get_document39 sys.modules[40 "eve.methods.patch"41 ].get_document = get_document_simulate_concurrent_update42 return super(TestPatchAtomicConcurrent, self).setUp()43 def test_etag_changed_after_get_document(self):44 """45 Try to update a document after the ETag was adjusted46 outside this process47 """48 changes = {"ref": "1234567890123456789054321"}49 _r, status = self.patch(50 self.item_id_url, data=changes, headers=[("If-Match", self.item_etag)]51 )52 self.assertEqual(status, 412)53 def tearDown(self):54 """Remove patch of eve.methods.patch.get_document"""55 sys.modules["eve.methods.patch"].get_document = self.original_get_document56 return super(TestPatchAtomicConcurrent, self).tearDown()57 def patch(self, url, data, headers=[]):...

Full Screen

Full Screen

mongo_db.py

Source:mongo_db.py Github

copy

Full Screen

1from pymongo import MongoClient2from bson.objectid import ObjectId3db_doc = MongoClient('mongodb://localhost:27017/').btcdb.info4def get_document(query_dict):5 return db_doc.find_one(query_dict)6def create_document(new_dict):7 db_doc.insert_one(new_dict)8def update_document(query_dict, update_data):9 return db_doc.update_one(query_dict, {"$set":update_data}).modified_count != 010def main():11 # Testing12 query = {"title":"None"}13 new_data = {"title":"testtest"}14 print(f"DEBUG get_document: {get_document(query)}")15 create_document(query)16 print(f"DEBUG get_document: {get_document(query)}")17 print(f"DEBUG update_document: {update_document(query, new_data)}")18 print(f"DEBUG get_document: {get_document(query)}")19 print(f"DEBUG get_document: {get_document(new_data)}")20 print(f"DEBUG update_document: {update_document(query, new_data)}")21if __name__ == "__main__":...

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 localstack 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