How to use create_document method in localstack

Best Python code snippet using localstack_python

test_context.py

Source:test_context.py Github

copy

Full Screen

...8 self.assertEqual(context.count_tags(), 0)9 self.assertEqual(context.count_relations(), 0)10 def test_document_creation(self):11 context = Context()12 context.create_document(1, 'first.txt', 'txt', '/tmp/first.txt')13 self.assertEqual(context.count_documents(), 1)14 document = context.get_document(1)15 self.assertEqual(document.id, 1)16 self.assertEqual(document.name, 'first.txt')17 self.assertEqual(document.type, 'txt')18 self.assertEqual(document.path, '/tmp/first.txt')19 def test_missing_document(self):20 context = Context()21 context.create_document(1, 'first.txt', 'txt', '/tmp/first.txt')22 with self.assertRaises(ValueError):23 _ = context.get_document(2)24 def test_invalid_document_creation(self):25 context = Context()26 context.create_document(1, 'first.txt', 'txt', '/tmp/first.txt')27 with self.assertRaises(ValueError):28 context.create_document(1, 'second.txt', 'txt', '/tmp/second.txt')29 def test_find_all_documents_from_empty_database(self):30 context = Context()31 documents = context.find_documents([])32 self.assertEqual(documents, [])33 def test_find_all_documents(self):34 context = Context()35 context.create_document(1, 'first.txt', 'txt', '/tmp/first.txt')36 context.create_document(2, 'second.txt', 'txt', '/tmp/second.txt')37 documents = context.find_documents([])38 self.assertEqual(len(documents), 2)39 self.assertEqual(documents[0].id, 1)40 self.assertEqual(documents[0].name, 'first.txt')41 self.assertEqual(documents[0].type, 'txt')42 self.assertEqual(documents[0].path, '/tmp/first.txt')43 self.assertEqual(documents[1].id, 2)44 self.assertEqual(documents[1].name, 'second.txt')45 self.assertEqual(documents[1].type, 'txt')46 self.assertEqual(documents[1].path, '/tmp/second.txt')47 def test_update_document_name(self):48 context = Context()49 context.create_document(1, 'first.txt', 'txt', '/tmp/first.txt')50 context.update_document(1, name='second.txt')51 document = context.get_document(1)52 self.assertEqual(document.id, 1)53 self.assertEqual(document.name, 'second.txt')54 self.assertEqual(document.type, 'txt')55 self.assertEqual(document.path, '/tmp/first.txt')56 def test_update_document_type(self):57 context = Context()58 context.create_document(1, 'first.txt', 'txt', '/tmp/first.txt')59 context.update_document(1, type='csv')60 document = context.get_document(1)61 self.assertEqual(document.id, 1)62 self.assertEqual(document.name, 'first.txt')63 self.assertEqual(document.type, 'csv')64 self.assertEqual(document.path, '/tmp/first.txt')65 def test_update_document_path(self):66 context = Context()67 context.create_document(1, 'first.txt', 'txt', '/tmp/first.txt')68 context.update_document(1, path='/tmp/here/first.txt')69 document = context.get_document(1)70 self.assertEqual(document.id, 1)71 self.assertEqual(document.name, 'first.txt')72 self.assertEqual(document.type, 'txt')73 self.assertEqual(document.path, '/tmp/here/first.txt')74 def test_update_document(self):75 context = Context()76 context.create_document(1, 'first.txt', 'txt', '/tmp/first.txt')77 context.update_document(1, 'second.csv', 'csv', '/tmp/second.csv')78 document = context.get_document(1)79 self.assertEqual(document.id, 1)80 self.assertEqual(document.name, 'second.csv')81 self.assertEqual(document.type, 'csv')82 self.assertEqual(document.path, '/tmp/second.csv')83 def test_update_missing_document(self):84 context = Context()85 context.create_document(1, 'first.txt', 'txt', '/tmp/first.txt')86 with self.assertRaises(ValueError):87 context.update_document(2, path='/tmp/nowhere.txt', type='missing')88 def test_remove_document(self):89 context = Context()90 context.create_document(1, 'first.txt', 'txt', '/tmp/first.txt')91 context.destroy_document(1)92 with self.assertRaises(ValueError):93 _ = context.get_document(1)94 def test_remove_missing_document(self):95 context = Context()96 context.create_document(1, 'first.txt', 'txt', '/tmp/first.txt')97 with self.assertRaises(ValueError):98 context.destroy_document(2)99 def test_reuse_document_identifier(self):100 context = Context()101 context.create_document(1, 'first.txt', 'txt', '/tmp/first.txt')102 context.destroy_document(1)103 context.create_document(1, 'other.dat', 'data', '/tmp/other.dat')104 document = context.get_document(1)105 self.assertEqual(document.id, 1)106 self.assertEqual(document.name, 'other.dat')107 self.assertEqual(document.type, 'data')108 self.assertEqual(document.path, '/tmp/other.dat')109 def test_document_counting(self):110 context = Context()111 self.assertEqual(context.count_documents(), 0)112 context.create_document(1, 'first.txt', 'txt', '/tmp/first.txt')113 self.assertEqual(context.count_documents(), 1)114 context.create_document(2, 'second.csv', 'csv', '/tmp/second.csv')115 self.assertEqual(context.count_documents(), 2)116 context.create_document(3, 'other.dat', 'data', '/tmp/other.dat')117 self.assertEqual(context.count_documents(), 3)118 context.destroy_document(3)119 self.assertEqual(context.count_documents(), 2)120 context.destroy_document(1)121 self.assertEqual(context.count_documents(), 1)122 context.destroy_document(2)123 self.assertEqual(context.count_documents(), 0)124 def test_tag_creation(self):125 context = Context()126 context.create_tag(1, 'python')127 self.assertEqual(context.count_tags(), 1)128 tag = context.get_tag(1)129 self.assertEqual(tag.id, 1)130 self.assertEqual(tag.name, 'python')131 def test_missing_tag(self):132 context = Context()133 context.create_tag(1, 'python')134 with self.assertRaises(ValueError):135 _ = context.get_tag(2)136 def test_invalid_tag_creation(self):137 context = Context()138 context.create_tag(1, 'python')139 with self.assertRaises(ValueError):140 context.create_tag(1, 'rust')141 def test_find_all_tags_from_empty_database(self):142 context = Context()143 tags = context.find_tags([])144 self.assertEqual(tags, [])145 def test_find_all_tags(self):146 context = Context()147 context.create_tag(1, 'python')148 context.create_tag(2, 'rust')149 tags = context.find_tags([])150 self.assertEqual(len(tags), 2)151 self.assertEqual(tags[0].id, 1)152 self.assertEqual(tags[0].name, 'python')153 self.assertEqual(tags[1].id, 2)154 self.assertEqual(tags[1].name, 'rust')155 def test_update_tag(self):156 context = Context()157 context.create_tag(1, 'python')158 context.update_tag(1, 'lua')159 tag = context.get_tag(1)160 self.assertEqual(tag.id, 1)161 self.assertEqual(tag.name, 'lua')162 def test_update_missing_tag(self):163 context = Context()164 context.create_tag(1, 'python')165 with self.assertRaises(ValueError):166 context.update_tag(2, 'lua')167 def test_remove_tag(self):168 context = Context()169 context.create_tag(1, 'python')170 context.destroy_tag(1)171 with self.assertRaises(ValueError):172 _ = context.get_tag(1)173 def test_remove_missing_tag(self):174 context = Context()175 context.create_tag(1, 'python')176 with self.assertRaises(ValueError):177 context.destroy_tag(2)178 def test_reuse_tag_identifier(self):179 context = Context()180 context.create_tag(1, 'python')181 context.destroy_tag(1)182 context.create_tag(1, 'rust')183 tag = context.get_tag(1)184 self.assertEqual(tag.id, 1)185 self.assertEqual(tag.name, 'rust')186 def test_tag_counting(self):187 context = Context()188 self.assertEqual(context.count_tags(), 0)189 context.create_tag(2, 'rust')190 self.assertEqual(context.count_tags(), 1)191 context.create_tag(1, 'python')192 self.assertEqual(context.count_tags(), 2)193 context.create_tag(3, 'lua')194 self.assertEqual(context.count_tags(), 3)195 context.destroy_tag(2)196 self.assertEqual(context.count_tags(), 2)197 context.destroy_tag(3)198 self.assertEqual(context.count_tags(), 1)199 context.destroy_tag(1)200 self.assertEqual(context.count_tags(), 0)201 def test_unique_tag_name_on_creation(self):202 context = Context()203 context.create_tag(1, 'python')204 with self.assertRaises(ValueError):205 context.create_tag(2, 'python')206 def test_unique_tag_name_on_update(self):207 context = Context()208 context.create_tag(1, 'python')209 context.create_tag(2, 'rust')210 with self.assertRaises(ValueError):211 context.update_tag(2, 'python')212 def test_find_tag_id(self):213 context = Context()214 context.create_tag(1, 'python')215 context.create_tag(2, 'rust')216 context.create_tag(3, 'lua')217 self.assertEqual(context.find_tag_id('rust'), 2)218 self.assertEqual(context.find_tag_id('lua'), 3)219 self.assertEqual(context.find_tag_id('python'), 1)220 def test_find_id_of_missing_tag(self):221 context = Context()222 context.create_tag(1, 'python')223 context.create_tag(2, 'rust')224 context.create_tag(3, 'lua')225 with self.assertRaises(ValueError):226 _ = context.find_tag_id('java')227 def test_create_relations(self):228 context = Context()229 context.create_document(1, 'python.pdf', 'pdf', '/tmp/python.pdf')230 context.create_document(2, 'rust.pdf', 'pdf', '/tmp/rust.pdf')231 context.create_document(3, 'lua.pdf', 'pdf', '/tmp/lua.pdf')232 context.create_tag(1, 'book')233 context.create_relation(1, 1)234 context.create_relation(2, 1)235 context.create_relation(3, 1)236 document_ids = context.find_document_ids([1])237 self.assertEqual(document_ids, [1, 2, 3])238 self.assertEqual(context.find_tag_ids([1]), [1])239 self.assertEqual(context.find_tag_ids([2]), [1])240 self.assertEqual(context.find_tag_ids([3]), [1])241 def test_create_relation_with_invalid_document(self):242 context = Context()243 context.create_tag(1, 'book')244 with self.assertRaises(ValueError):245 context.create_relation(1, 1)246 def test_create_relation_with_invalid_tag(self):247 context = Context()248 context.create_document(1, 'python.pdf', 'pdf', '/tmp/python.pdf')249 with self.assertRaises(ValueError):250 context.create_relation(1, 1)251 def test_remove_relations(self):252 context = Context()253 context.create_document(1, 'python.pdf', 'pdf', '/tmp/python.pdf')254 context.create_document(2, 'rust.pdf', 'pdf', '/tmp/rust.pdf')255 context.create_document(3, 'lua.pdf', 'pdf', '/tmp/lua.pdf')256 context.create_tag(1, 'book')257 context.create_relation(1, 1)258 context.create_relation(2, 1)259 context.create_relation(3, 1)260 self.assertEqual(context.count_relations(), 3)261 context.destroy_relation(2, 1)262 self.assertEqual(context.count_relations(), 2)263 context.destroy_relation(1, 1)264 self.assertEqual(context.count_relations(), 1)265 context.destroy_relation(3, 1)266 self.assertEqual(context.count_relations(), 0)267 def test_remove_missing_relation(self):268 context = Context()269 context.create_tag(1, 'book')270 context.create_document(1, 'python.pdf', 'pdf', '/tmp/python.pdf')271 with self.assertRaises(ValueError):272 context.destroy_relation(1, 1)273 def test_remove_relations_with_document(self):274 context = Context()275 context.create_document(1, 'python.pdf', 'pdf', '/tmp/python.pdf')276 context.create_document(2, 'rust.pdf', 'pdf', '/tmp/rust.pdf')277 context.create_document(3, 'lua.pdf', 'pdf', '/tmp/lua.pdf')278 context.create_tag(1, 'book')279 context.create_relation(1, 1)280 context.create_relation(2, 1)281 context.create_relation(3, 1)282 context.destroy_document(1)283 self.assertEqual(context.count_relations(), 2)284 context.destroy_document(3)285 self.assertEqual(context.count_relations(), 1)286 context.destroy_document(2)287 self.assertEqual(context.count_relations(), 0)288 def test_remove_relations_with_tag(self):289 context = Context()290 context.create_document(1, 'python.pdf', 'pdf', '/tmp/python.pdf')291 context.create_document(2, 'rust.pdf', 'pdf', '/tmp/rust.pdf')292 context.create_document(3, 'lua.pdf', 'pdf', '/tmp/lua.pdf')293 context.create_tag(1, 'book')294 context.create_relation(1, 1)295 context.create_relation(2, 1)296 context.create_relation(3, 1)297 context.destroy_tag(1)298 self.assertEqual(context.count_relations(), 0)299 def test_multiple_tags_and_documents(self):300 context = Context()301 context.create_document(1, 'python.pdf', 'pdf', '/tmp/python.pdf')302 context.create_document(2, 'tkinter.pdf', 'pdf', '/tmp/tkinter.pdf')303 context.create_document(3, 'lua.pdf', 'pdf', '/tmp/lua.pdf')304 context.create_document(4, 'index.py', 'py', '/tmp/index.py')305 context.create_tag(5, 'book')306 context.create_tag(6, 'python')307 context.create_relation(1, 5)308 context.create_relation(2, 5)309 context.create_relation(3, 5)310 context.create_relation(1, 6)311 context.create_relation(2, 6)312 context.create_relation(4, 6)313 self.assertEqual(context.count_relations(), 6)314 book_ids = context.find_document_ids([5])315 self.assertEqual(book_ids, [1, 2, 3])316 python_ids = context.find_document_ids([6])317 self.assertEqual(python_ids, [1, 2, 4])318 python_book_ids = context.find_document_ids([5, 6])...

Full Screen

Full Screen

test_document.py

Source:test_document.py Github

copy

Full Screen

1import pytest2from indexclient.client import Document, recursive_sort3def create_document(4 did=None,5 hashes=None,6 size=None,7 file_name=None,8 acl=None,9 authz=None,10 urls=None,11 urls_metadata=None,12):13 return Document(14 None,15 did,16 json={17 "hashes": hashes or {},18 "size": size or 1,19 "file_name": file_name or "file.txt",20 "urls": urls or ["one", "two", "three"],21 "acl": acl or ["1", "2", "3"],22 "authz": authz or "/gen3/programs/1/projects/2/3",23 "urls_metadata": urls_metadata24 or {"one": {"1": "one"}, "two": {"2": "two"}, "three": {"3": "three"}},25 },26 )27def test_equals():28 doc1 = create_document()29 doc2 = create_document()30 assert doc1 == doc231 # Out of order values are still equal because the contents are the same.32 doc1.acl = ["4", "5"]33 doc2.acl = ["5", "4"]34 assert doc1 == doc235def test_not_equals():36 doc1 = create_document(acl=["1", "2"])37 doc2 = create_document(acl=["2", "3"])38 assert doc1 != doc239def test_less_than():40 doc1 = create_document(did="11111111-1111-1111-1111-111111111111")41 doc2 = create_document(did="11111111-1111-1111-1111-111111111112")42 assert doc1 < doc243 # reverse order docs44 docs = [45 create_document(did="11111111-1111-1111-1111-11111111111" + str(suffix))46 for suffix in range(10, 0, -1)47 ]48 # sorted() sorts it in order from lowest to highest did because of __lt__/__gt__49 assert sorted(docs) == docs[::-1]50def test_greater_than():51 doc1 = create_document(did="11111111-1111-1111-1111-111111111111")52 doc2 = create_document(did="11111111-1111-1111-1111-111111111112")53 assert doc2 > doc154 # reverse order docs55 docs = [56 create_document(did="11111111-1111-1111-1111-11111111111" + str(suffix))57 for suffix in range(10, 0, -1)58 ]59 # sorted() sorts it in order from lowest to highest did because of __lt__/__gt__60 assert sorted(docs) == docs[::-1]61@pytest.mark.parametrize(62 "given, expected",63 [64 (1, 1),65 ("one", "one"),66 ([1, 4, 3, 2], [1, 2, 3, 4]),67 ({"dict": [1, 4, 3, 2]}, {"dict": [1, 2, 3, 4]}),68 ({"one": {"two": [1, 4, 3, 2]}}, {"one": {"two": [1, 2, 3, 4]}}),69 ],70)...

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