How to use assert_object method in localstack

Best Python code snippet using localstack_python

test_cvrf_full.py

Source:test_cvrf_full.py Github

copy

Full Screen

...3from contextlib import suppress4with open('./test_cvrf_full.json', encoding='utf-8') as f:5 csaf = json.loads(f.read())6# pylint: disable=missing-function-docstring7def assert_object(path, length=None):8 parts = path.split('/')9 try:10 next_ = csaf11 for part in parts:12 with suppress(ValueError):13 part = int(part)14 next_ = next_[part]15 except KeyError as err:16 print(f'FAILED. Missing CSAF path: /{path}')17 raise AssertionError from err18 else:19 if length:20 assert len(next_) == length21# pylint: disable=too-many-statements22def test_full_input_cvrf():23 """24 Tests that all expected objects are present in the input.25 Full input means that all possible (mandatory and optional) CVRF elements are26 present in the input and are asserted in the output.27 """28 assert_object('document')29 assert_object('document/title')30 assert_object('document/publisher')31 assert_object('document/publisher/contact_details')32 assert_object('document/publisher/issuing_authority')33 assert_object('document/tracking')34 assert_object('document/tracking/id')35 assert_object('document/tracking/aliases', 2)36 assert_object('document/tracking/status')37 assert_object('document/tracking/version')38 assert_object('document/tracking/revision_history', 2)39 assert_object('document/tracking/revision_history/0/date')40 assert_object('document/tracking/revision_history/0/number')41 assert_object('document/tracking/revision_history/0/summary')42 assert_object('document/tracking/revision_history/1/date')43 assert_object('document/tracking/revision_history/1/number')44 assert_object('document/tracking/revision_history/1/summary')45 assert_object('document/tracking/initial_release_date')46 assert_object('document/tracking/current_release_date')47 assert_object('document/tracking/generator')48 assert_object('document/tracking/generator/date')49 assert_object('document/tracking/generator/engine')50 assert_object('document/tracking/generator/engine/name')51 assert_object('document/tracking/generator/engine/version')52 assert_object('document/notes', 2)53 assert_object('document/notes/0/text')54 assert_object('document/notes/0/category')55 assert_object('document/notes/0/audience')56 assert_object('document/notes/0/title')57 assert_object('document/notes/1/text')58 assert_object('document/notes/1/category')59 assert_object('document/notes/1/audience')60 assert_object('document/notes/1/title')61 assert_object('document/distribution')62 assert_object('document/distribution/text')63 assert_object('document/aggregate_severity')64 assert_object('document/aggregate_severity/text')65 assert_object('document/aggregate_severity/namespace')66 assert_object('document/references', 2)67 assert_object('document/references/0/summary')68 assert_object('document/references/0/category')69 assert_object('document/references/0/url')70 assert_object('document/references/1/summary')71 assert_object('document/references/1/category')72 assert_object('document/references/1/url')73 assert_object('document/acknowledgments', 2)74 assert_object('document/acknowledgments/0/summary')75 assert_object('document/acknowledgments/0/organization')76 assert_object('document/acknowledgments/0/names')77 assert_object('document/acknowledgments/0/urls')78 assert_object('document/acknowledgments/1/names', 2)79 assert_object('product_tree')80 assert_object('product_tree/full_product_names', 2)81 assert_object('product_tree/full_product_names/0/product_id')82 assert_object('product_tree/full_product_names/0/name')83 assert_object('product_tree/full_product_names/0/product_identification_helper')84 assert_object('product_tree/full_product_names/0/product_identification_helper/cpe')85 assert_object('product_tree/full_product_names/1/product_id')86 assert_object('product_tree/full_product_names/1/name')87 assert_object('product_tree/relationships', 2)88 assert_object('product_tree/relationships/0/category')89 assert_object('product_tree/relationships/0/product_reference')90 assert_object('product_tree/relationships/0/relates_to_product_reference')91 assert_object('product_tree/relationships/0/full_product_name')92 assert_object('product_tree/relationships/0/full_product_name/product_id')93 assert_object('product_tree/relationships/0/full_product_name/name')94 assert_object('product_tree/relationships/1/category')95 assert_object('product_tree/relationships/1/product_reference')96 assert_object('product_tree/relationships/1/relates_to_product_reference')97 assert_object('product_tree/relationships/1/full_product_name')98 assert_object('product_tree/relationships/1/full_product_name/product_id')99 assert_object('product_tree/relationships/1/full_product_name/name')100 assert_object('product_tree/product_groups', 1)101 assert_object('product_tree/product_groups/0/group_id')102 assert_object('product_tree/product_groups/0/product_ids', 2)103 assert_object('product_tree/branches', 2)104 assert_object('product_tree/branches/0/name')105 assert_object('product_tree/branches/0/category')106 assert_object('product_tree/branches/0/branches', 1)107 assert_object('product_tree/branches/0/branches/0/name')108 assert_object('product_tree/branches/0/branches/0/category')109 assert_object('product_tree/branches/0/branches/0/branches', 2)110 assert_object('product_tree/branches/0/branches/0/branches/0/name')111 assert_object('product_tree/branches/0/branches/0/branches/0/category')112 assert_object('product_tree/branches/0/branches/0/branches/0/product')113 assert_object('product_tree/branches/0/branches/0/branches/0/product/product_id')114 assert_object('product_tree/branches/0/branches/0/branches/0/product/name')115 assert_object('product_tree/branches/0/branches/0/branches/1/name')116 assert_object('product_tree/branches/0/branches/0/branches/1/category')117 assert_object('product_tree/branches/0/branches/0/branches/1/product')118 assert_object('product_tree/branches/0/branches/0/branches/1/product/product_id')119 assert_object('product_tree/branches/0/branches/0/branches/1/product/name')120 assert_object('product_tree/branches/1/name')121 assert_object('product_tree/branches/1/category')122 assert_object('product_tree/branches/1/product')123 assert_object('product_tree/branches/1/product/product_id')124 assert_object('product_tree/branches/1/product/name')125 assert_object('product_tree/branches/1/product/product_identification_helper')126 assert_object('product_tree/branches/1/product/product_identification_helper/cpe')127 assert_object('vulnerabilities', 2)128 assert_object('vulnerabilities/0/cve')129 assert_object('vulnerabilities/0/id')130 assert_object('vulnerabilities/0/id/system_name')131 assert_object('vulnerabilities/0/id/text')132 assert_object('vulnerabilities/0/notes', 2)133 assert_object('vulnerabilities/0/notes/0/text')134 assert_object('vulnerabilities/0/notes/0/category')135 assert_object('vulnerabilities/0/notes/0/title')136 assert_object('vulnerabilities/0/notes/1/text')137 assert_object('vulnerabilities/0/notes/1/category')138 assert_object('vulnerabilities/0/notes/1/title')139 assert_object('vulnerabilities/0/product_status')140 assert_object('vulnerabilities/0/product_status/known_affected', 4)141 assert_object('vulnerabilities/0/references', 1)142 assert_object('vulnerabilities/0/references/0/summary')143 assert_object('vulnerabilities/0/references/0/url')144 assert_object('vulnerabilities/0/references/0/category')145 assert_object('vulnerabilities/0/remediations', 1)146 assert_object('vulnerabilities/0/remediations/0/category')147 assert_object('vulnerabilities/0/remediations/0/details')148 assert_object('vulnerabilities/0/scores', 1)149 assert_object('vulnerabilities/0/scores/0/cvss_v3')150 assert_object('vulnerabilities/0/scores/0/cvss_v3/baseScore')151 assert_object('vulnerabilities/0/scores/0/cvss_v3/vectorString')152 assert_object('vulnerabilities/0/scores/0/cvss_v3/baseSeverity')153 assert_object('vulnerabilities/0/scores/0/cvss_v3/version')154 assert_object('vulnerabilities/0/scores/0/products', 4)155 assert_object('vulnerabilities/0/title')156 assert_object('vulnerabilities/1/acknowledgments', 1)157 assert_object('vulnerabilities/1/acknowledgments/0/names', 1)158 assert_object('vulnerabilities/1/cve')159 assert_object('vulnerabilities/1/cwe')160 assert_object('vulnerabilities/1/cwe/id')161 assert_object('vulnerabilities/1/cwe/name')162 assert_object('vulnerabilities/1/discovery_date')163 assert_object('vulnerabilities/1/id')164 assert_object('vulnerabilities/1/id/system_name')165 assert_object('vulnerabilities/1/id/text')166 assert_object('vulnerabilities/1/involvements', 2)167 assert_object('vulnerabilities/1/involvements/0/party')168 assert_object('vulnerabilities/1/involvements/0/status')169 assert_object('vulnerabilities/1/involvements/0/summary')170 assert_object('vulnerabilities/1/involvements/1/party')171 assert_object('vulnerabilities/1/involvements/1/status')172 assert_object('vulnerabilities/1/notes', 2)173 assert_object('vulnerabilities/1/notes/0/text')174 assert_object('vulnerabilities/1/notes/0/category')175 assert_object('vulnerabilities/1/notes/0/audience')176 assert_object('vulnerabilities/1/notes/0/title')177 assert_object('vulnerabilities/1/notes/1/text')178 assert_object('vulnerabilities/1/notes/1/category')179 assert_object('vulnerabilities/1/notes/1/audience')180 assert_object('vulnerabilities/1/notes/1/title')181 assert_object('vulnerabilities/1/product_status', 2)182 assert_object('vulnerabilities/1/product_status/first_fixed', 2)183 assert_object('vulnerabilities/1/product_status/known_affected', 1)184 assert_object('vulnerabilities/1/references', 1)185 assert_object('vulnerabilities/1/references/0/summary')186 assert_object('vulnerabilities/1/references/0/url')187 assert_object('vulnerabilities/1/references/0/category')188 assert_object('vulnerabilities/1/release_date')189 assert_object('vulnerabilities/1/remediations', 2)190 assert_object('vulnerabilities/1/remediations/0/category')191 assert_object('vulnerabilities/1/remediations/0/details')192 assert_object('vulnerabilities/1/remediations/1/category')193 assert_object('vulnerabilities/1/remediations/1/details')194 assert_object('vulnerabilities/1/remediations/1/entitlements', 1)195 assert_object('vulnerabilities/1/remediations/1/url')196 assert_object('vulnerabilities/1/remediations/1/product_ids', 1)197 assert_object('vulnerabilities/1/remediations/1/group_ids', 1)198 assert_object('vulnerabilities/1/remediations/1/date')199 assert_object('vulnerabilities/1/scores', 3)200 assert_object('vulnerabilities/1/scores/0/cvss_v2/baseScore')201 assert_object('vulnerabilities/1/scores/0/cvss_v2/environmentalScore')202 assert_object('vulnerabilities/1/scores/0/cvss_v2/vectorString')203 assert_object('vulnerabilities/1/scores/0/cvss_v2/version')204 assert_object('vulnerabilities/1/scores/0/products', 1)205 assert_object('vulnerabilities/1/scores/1/cvss_v3/baseScore')206 assert_object('vulnerabilities/1/scores/1/cvss_v3/temporalScore')207 assert_object('vulnerabilities/1/scores/1/cvss_v3/vectorString')208 assert_object('vulnerabilities/1/scores/1/cvss_v3/version')209 assert_object('vulnerabilities/1/scores/1/cvss_v3/baseSeverity')210 assert_object('vulnerabilities/1/scores/1/products', 1)211 assert_object('vulnerabilities/1/scores/2/cvss_v3/baseScore')212 assert_object('vulnerabilities/1/scores/2/cvss_v3/vectorString')213 assert_object('vulnerabilities/1/scores/2/cvss_v3/version')214 assert_object('vulnerabilities/1/scores/2/cvss_v3/baseSeverity')215 assert_object('vulnerabilities/1/scores/2/products', 1)216 assert_object('vulnerabilities/1/threats', 2)217 assert_object('vulnerabilities/1/threats/0/details')218 assert_object('vulnerabilities/1/threats/0/category')219 assert_object('vulnerabilities/1/threats/0/product_ids', 1)220 assert_object('vulnerabilities/1/threats/0/date')221 assert_object('vulnerabilities/1/threats/1/details')222 assert_object('vulnerabilities/1/threats/1/category')223 assert_object('vulnerabilities/1/threats/1/group_ids', 1)...

Full Screen

Full Screen

test_identifier.py

Source:test_identifier.py Github

copy

Full Screen

...58 interface_version=159 )60 self.assert_namespace(interface, ("a", "b", "c", "d"))61 self.assert_interface(interface, "a.b.c.d1")62 def assert_object(self, obj, object_path):63 """Check the DBus object."""64 self.assertEqual(obj.object_path, object_path)65 def test_object(self):66 """Test the DBus object."""67 obj = DBusObjectIdentifier(68 namespace=("a", "b", "c")69 )70 self.assert_namespace(obj, ("a", "b", "c"))71 self.assert_interface(obj, "a.b.c")72 self.assert_object(obj, "/a/b/c")73 obj = DBusObjectIdentifier(74 namespace=("a", "b", "c"),75 object_version=2,76 interface_version=477 )78 self.assert_namespace(obj, ("a", "b", "c"))79 self.assert_interface(obj, "a.b.c4")80 self.assert_object(obj, "/a/b/c2")81 obj = DBusObjectIdentifier(82 basename="d",83 namespace=("a", "b", "c"),84 object_version=2,85 interface_version=486 )87 self.assert_namespace(obj, ("a", "b", "c", "d"))88 self.assert_interface(obj, "a.b.c.d4")89 self.assert_object(obj, "/a/b/c/d2")90 def assert_bus(self, obj, message_bus):91 """Check the DBus service object."""92 self.assertEqual(obj.message_bus, message_bus)93 def assert_service(self, obj, service_name):94 """Check the DBus service object."""95 self.assertEqual(obj.service_name, service_name)96 def test_service(self):97 """Test the DBus service object."""98 bus = Mock()99 service = DBusServiceIdentifier(100 namespace=("a", "b", "c"),101 message_bus=bus102 )103 self.assert_namespace(service, ("a", "b", "c"))104 self.assert_interface(service, "a.b.c")105 self.assert_object(service, "/a/b/c")106 self.assert_service(service, "a.b.c")107 self.assert_bus(service, bus)108 service = DBusServiceIdentifier(109 namespace=("a", "b", "c"),110 service_version=3,111 interface_version=5,112 object_version=7,113 message_bus=bus114 )115 self.assert_namespace(service, ("a", "b", "c"))116 self.assert_interface(service, "a.b.c5")117 self.assert_object(service, "/a/b/c7")118 self.assert_service(service, "a.b.c3")119 self.assert_bus(service, bus)120 service = DBusServiceIdentifier(121 basename="d",122 namespace=("a", "b", "c"),123 service_version=3,124 interface_version=5,125 object_version=7,126 message_bus=bus127 )128 self.assert_namespace(service, ("a", "b", "c", "d"))129 self.assert_interface(service, "a.b.c.d5")130 self.assert_object(service, "/a/b/c/d7")131 self.assert_service(service, "a.b.c.d3")132 self.assert_bus(service, bus)133class DBusServiceIdentifierTestCase(unittest.TestCase):134 """Test DBus service identifiers."""135 def test_get_proxy(self):136 """Test getting a proxy."""137 bus = Mock()138 namespace = ("a", "b", "c")139 service = DBusServiceIdentifier(140 namespace=namespace,141 message_bus=bus142 )143 obj = DBusObjectIdentifier(144 basename="object",...

Full Screen

Full Screen

test_thread_safety.py

Source:test_thread_safety.py Github

copy

Full Screen

1from promise import Promise2from promise.dataloader import DataLoader3import threading4def test_promise_thread_safety():5 """6 Promise tasks should never be executed in a different thread from the one they are scheduled from,7 unless the ThreadPoolExecutor is used.8 Here we assert that the pending promise tasks on thread 1 are not executed on thread 2 as thread 2 9 resolves its own promise tasks.10 """11 event_1 = threading.Event()12 event_2 = threading.Event()13 assert_object = {'is_same_thread': True}14 def task_1():15 thread_name = threading.current_thread().getName()16 def then_1(value): 17 # Enqueue tasks to run later. 18 # This relies on the fact that `then` does not execute the function synchronously when called from19 # within another `then` callback function.20 promise = Promise.resolve(None).then(then_2)21 assert promise.is_pending22 event_1.set() # Unblock main thread23 event_2.wait() # Wait for thread 2 24 25 def then_2(value):26 assert_object['is_same_thread'] = (thread_name == threading.current_thread().getName())27 promise = Promise.resolve(None).then(then_1)28 def task_2():29 promise = Promise.resolve(None).then(lambda v: None)30 promise.get() # Drain task queue31 event_2.set() # Unblock thread 132 thread_1 = threading.Thread(target=task_1)33 thread_1.start()34 event_1.wait() # Wait for Thread 1 to enqueue promise tasks35 thread_2 = threading.Thread(target=task_2) 36 thread_2.start()37 for thread in (thread_1, thread_2):38 thread.join()39 assert assert_object['is_same_thread']40def test_dataloader_thread_safety():41 """42 Dataloader should only batch `load` calls that happened on the same thread.43 44 Here we assert that `load` calls on thread 2 are not batched on thread 1 as45 thread 1 batches its own `load` calls.46 """47 def load_many(keys):48 thead_name = threading.current_thread().getName()49 return Promise.resolve([thead_name for key in keys])50 thread_name_loader = DataLoader(load_many)51 event_1 = threading.Event()52 event_2 = threading.Event()53 event_3 = threading.Event()54 assert_object = {55 'is_same_thread_1': True,56 'is_same_thread_2': True,57 }58 def task_1():59 @Promise.safe60 def do():61 promise = thread_name_loader.load(1)62 event_1.set()63 event_2.wait() # Wait for thread 2 to call `load`64 assert_object['is_same_thread_1'] = (65 promise.get() == threading.current_thread().getName()66 )67 event_3.set() # Unblock thread 268 do().get()69 def task_2():70 @Promise.safe71 def do():72 promise = thread_name_loader.load(2)73 event_2.set()74 event_3.wait() # Wait for thread 1 to run `dispatch_queue_batch`75 assert_object['is_same_thread_2'] = (76 promise.get() == threading.current_thread().getName()77 )78 79 do().get()80 thread_1 = threading.Thread(target=task_1)81 thread_1.start()82 event_1.wait() # Wait for thread 1 to call `load`83 thread_2 = threading.Thread(target=task_2) 84 thread_2.start()85 for thread in (thread_1, thread_2):86 thread.join()87 assert assert_object['is_same_thread_1']...

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