Best Python code snippet using autotest_python
test_mysql.py
Source:test_mysql.py
1# -*- coding: utf-8 -*-2# Import python libs3from __future__ import absolute_import, print_function, unicode_literals4# Import Salt Libs5import salt.pillar.mysql as mysql6# Import Salt Testing libs7from tests.support.unit import TestCase, skipIf8@skipIf(mysql.MySQLdb is None, "MySQL-python module not installed")9class MysqlPillarTestCase(TestCase):10 maxDiff = None11 def test_001_extract_queries_legacy(self):12 return_data = mysql.MySQLExtPillar()13 args, kwargs = ["SELECT blah"], {}14 qbuffer = return_data.extract_queries(args, kwargs)15 self.assertEqual(16 [17 [18 None,19 {20 "query": "SELECT blah",21 "depth": 0,22 "as_list": False,23 "with_lists": None,24 "ignore_null": False,25 },26 ]27 ],28 qbuffer,29 )30 def test_002_extract_queries_list(self):31 return_data = mysql.MySQLExtPillar()32 args, kwargs = (33 [34 "SELECT blah",35 "SELECT blah2",36 ("SELECT blah3",),37 ("SELECT blah4", 2),38 {"query": "SELECT blah5"},39 {"query": "SELECT blah6", "depth": 2},40 {"query": "SELECT blah7", "as_list": True},41 {"query": "SELECT blah8", "with_lists": "1"},42 {"query": "SELECT blah9", "with_lists": "1,2"},43 ],44 {},45 )46 qbuffer = return_data.extract_queries(args, kwargs)47 self.assertEqual(48 [49 [50 None,51 {52 "query": "SELECT blah",53 "depth": 0,54 "as_list": False,55 "with_lists": None,56 "ignore_null": False,57 },58 ],59 [60 None,61 {62 "query": "SELECT blah2",63 "depth": 0,64 "as_list": False,65 "with_lists": None,66 "ignore_null": False,67 },68 ],69 [70 None,71 {72 "query": "SELECT blah3",73 "depth": 0,74 "as_list": False,75 "with_lists": None,76 "ignore_null": False,77 },78 ],79 [80 None,81 {82 "query": "SELECT blah4",83 "depth": 2,84 "as_list": False,85 "with_lists": None,86 "ignore_null": False,87 },88 ],89 [90 None,91 {92 "query": "SELECT blah5",93 "depth": 0,94 "as_list": False,95 "with_lists": None,96 "ignore_null": False,97 },98 ],99 [100 None,101 {102 "query": "SELECT blah6",103 "depth": 2,104 "as_list": False,105 "with_lists": None,106 "ignore_null": False,107 },108 ],109 [110 None,111 {112 "query": "SELECT blah7",113 "depth": 0,114 "as_list": True,115 "with_lists": None,116 "ignore_null": False,117 },118 ],119 [120 None,121 {122 "query": "SELECT blah8",123 "depth": 0,124 "as_list": False,125 "with_lists": [1],126 "ignore_null": False,127 },128 ],129 [130 None,131 {132 "query": "SELECT blah9",133 "depth": 0,134 "as_list": False,135 "with_lists": [1, 2],136 "ignore_null": False,137 },138 ],139 ],140 qbuffer,141 )142 def test_003_extract_queries_kwarg(self):143 return_data = mysql.MySQLExtPillar()144 args, kwargs = (145 [],146 {147 "1": "SELECT blah",148 "2": "SELECT blah2",149 "3": ("SELECT blah3",),150 "4": ("SELECT blah4", 2),151 "5": {"query": "SELECT blah5"},152 "6": {"query": "SELECT blah6", "depth": 2},153 "7": {"query": "SELECT blah7", "as_list": True},154 },155 )156 qbuffer = return_data.extract_queries(args, kwargs)157 self.assertEqual(158 [159 [160 "1",161 {162 "query": "SELECT blah",163 "depth": 0,164 "as_list": False,165 "with_lists": None,166 "ignore_null": False,167 },168 ],169 [170 "2",171 {172 "query": "SELECT blah2",173 "depth": 0,174 "as_list": False,175 "with_lists": None,176 "ignore_null": False,177 },178 ],179 [180 "3",181 {182 "query": "SELECT blah3",183 "depth": 0,184 "as_list": False,185 "with_lists": None,186 "ignore_null": False,187 },188 ],189 [190 "4",191 {192 "query": "SELECT blah4",193 "depth": 2,194 "as_list": False,195 "with_lists": None,196 "ignore_null": False,197 },198 ],199 [200 "5",201 {202 "query": "SELECT blah5",203 "depth": 0,204 "as_list": False,205 "with_lists": None,206 "ignore_null": False,207 },208 ],209 [210 "6",211 {212 "query": "SELECT blah6",213 "depth": 2,214 "as_list": False,215 "with_lists": None,216 "ignore_null": False,217 },218 ],219 [220 "7",221 {222 "query": "SELECT blah7",223 "depth": 0,224 "as_list": True,225 "with_lists": None,226 "ignore_null": False,227 },228 ],229 ],230 qbuffer,231 )232 def test_004_extract_queries_mixed(self):233 return_data = mysql.MySQLExtPillar()234 args, kwargs = (235 [236 "SELECT blah1",237 ("SELECT blah2", 2),238 {"query": "SELECT blah3", "as_list": True},239 ],240 {241 "1": "SELECT blah1",242 "2": ("SELECT blah2", 2),243 "3": {"query": "SELECT blah3", "as_list": True},244 },245 )246 qbuffer = return_data.extract_queries(args, kwargs)247 self.assertEqual(248 [249 [250 None,251 {252 "query": "SELECT blah1",253 "depth": 0,254 "as_list": False,255 "with_lists": None,256 "ignore_null": False,257 },258 ],259 [260 None,261 {262 "query": "SELECT blah2",263 "depth": 2,264 "as_list": False,265 "with_lists": None,266 "ignore_null": False,267 },268 ],269 [270 None,271 {272 "query": "SELECT blah3",273 "depth": 0,274 "as_list": True,275 "with_lists": None,276 "ignore_null": False,277 },278 ],279 [280 "1",281 {282 "query": "SELECT blah1",283 "depth": 0,284 "as_list": False,285 "with_lists": None,286 "ignore_null": False,287 },288 ],289 [290 "2",291 {292 "query": "SELECT blah2",293 "depth": 2,294 "as_list": False,295 "with_lists": None,296 "ignore_null": False,297 },298 ],299 [300 "3",301 {302 "query": "SELECT blah3",303 "depth": 0,304 "as_list": True,305 "with_lists": None,306 "ignore_null": False,307 },308 ],309 ],310 qbuffer,311 )312 def test_005_extract_queries_bogus_list(self):313 # This test is specifically checking that empty queries are dropped314 return_data = mysql.MySQLExtPillar()315 args, kwargs = (316 [317 "SELECT blah",318 "",319 "SELECT blah2",320 ("SELECT blah3",),321 ("",),322 ("SELECT blah4", 2),323 tuple(),324 ("SELECT blah5",),325 {"query": "SELECT blah6"},326 {"query": ""},327 {"query": "SELECT blah7", "depth": 2},328 {"not_a_query": "in sight!"},329 {"query": "SELECT blah8", "as_list": True},330 ],331 {},332 )333 qbuffer = return_data.extract_queries(args, kwargs)334 self.assertEqual(335 [336 [337 None,338 {339 "query": "SELECT blah",340 "depth": 0,341 "as_list": False,342 "with_lists": None,343 "ignore_null": False,344 },345 ],346 [347 None,348 {349 "query": "SELECT blah2",350 "depth": 0,351 "as_list": False,352 "with_lists": None,353 "ignore_null": False,354 },355 ],356 [357 None,358 {359 "query": "SELECT blah3",360 "depth": 0,361 "as_list": False,362 "with_lists": None,363 "ignore_null": False,364 },365 ],366 [367 None,368 {369 "query": "SELECT blah4",370 "depth": 2,371 "as_list": False,372 "with_lists": None,373 "ignore_null": False,374 },375 ],376 [377 None,378 {379 "query": "SELECT blah5",380 "depth": 0,381 "as_list": False,382 "with_lists": None,383 "ignore_null": False,384 },385 ],386 [387 None,388 {389 "query": "SELECT blah6",390 "depth": 0,391 "as_list": False,392 "with_lists": None,393 "ignore_null": False,394 },395 ],396 [397 None,398 {399 "query": "SELECT blah7",400 "depth": 2,401 "as_list": False,402 "with_lists": None,403 "ignore_null": False,404 },405 ],406 [407 None,408 {409 "query": "SELECT blah8",410 "depth": 0,411 "as_list": True,412 "with_lists": None,413 "ignore_null": False,414 },415 ],416 ],417 qbuffer,418 )419 def test_006_extract_queries_bogus_kwargs(self):420 # this test is cut down as most of the path matches test_*_bogus_list421 return_data = mysql.MySQLExtPillar()422 args, kwargs = [], {"1": "SELECT blah", "2": "", "3": "SELECT blah2"}423 qbuffer = return_data.extract_queries(args, kwargs)424 self.assertEqual(425 [426 [427 "1",428 {429 "query": "SELECT blah",430 "depth": 0,431 "as_list": False,432 "with_lists": None,433 "ignore_null": False,434 },435 ],436 [437 "3",438 {439 "query": "SELECT blah2",440 "depth": 0,441 "as_list": False,442 "with_lists": None,443 "ignore_null": False,444 },445 ],446 ],447 qbuffer,448 )449 def test_011_enter_root(self):450 return_data = mysql.MySQLExtPillar()451 return_data.enter_root("test")452 self.assertEqual(return_data.result["test"], return_data.focus)453 return_data.enter_root(None)454 self.assertEqual(return_data.result, return_data.focus)455 def test_021_process_fields(self):456 return_data = mysql.MySQLExtPillar()457 return_data.process_fields(["a", "b"], 0)458 self.assertEqual(return_data.num_fields, 2)459 self.assertEqual(return_data.depth, 1)460 return_data.process_fields(["a", "b"], 2)461 self.assertEqual(return_data.num_fields, 2)462 self.assertEqual(return_data.depth, 1)463 return_data.process_fields(["a", "b", "c", "d"], 0)464 self.assertEqual(return_data.num_fields, 4)465 self.assertEqual(return_data.depth, 3)466 return_data.process_fields(["a", "b", "c", "d"], 1)467 self.assertEqual(return_data.num_fields, 4)468 self.assertEqual(return_data.depth, 1)469 return_data.process_fields(["a", "b", "c", "d"], 2)470 self.assertEqual(return_data.num_fields, 4)471 self.assertEqual(return_data.depth, 2)472 return_data.process_fields(["a", "b", "c", "d"], 3)473 self.assertEqual(return_data.num_fields, 4)474 self.assertEqual(return_data.depth, 3)475 return_data.process_fields(["a", "b", "c", "d"], 4)476 self.assertEqual(return_data.num_fields, 4)477 self.assertEqual(return_data.depth, 3)478 def test_111_process_results_legacy(self):479 return_data = mysql.MySQLExtPillar()480 return_data.process_fields(["a", "b"], 0)481 return_data.with_lists = []482 return_data.process_results([[1, 2]])483 self.assertEqual({1: 2}, return_data.result)484 def test_112_process_results_legacy_multiple(self):485 return_data = mysql.MySQLExtPillar()486 return_data.process_fields(["a", "b"], 0)487 return_data.with_lists = []488 return_data.process_results([[1, 2], [3, 4], [5, 6]])489 self.assertEqual({1: 2, 3: 4, 5: 6}, return_data.result)490 def test_121_process_results_depth_0(self):491 return_data = mysql.MySQLExtPillar()492 return_data.process_fields(["a", "b", "c", "d"], 0)493 return_data.with_lists = []494 return_data.enter_root(None)495 return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])496 self.assertEqual({1: {2: {3: 4}}, 5: {6: {7: 8}}}, return_data.result)497 def test_122_process_results_depth_1(self):498 return_data = mysql.MySQLExtPillar()499 return_data.process_fields(["a", "b", "c", "d"], 1)500 return_data.with_lists = []501 return_data.enter_root(None)502 return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])503 self.assertEqual(504 {1: {"b": 2, "c": 3, "d": 4}, 5: {"b": 6, "c": 7, "d": 8}},505 return_data.result,506 )507 def test_123_process_results_depth_2(self):508 return_data = mysql.MySQLExtPillar()509 return_data.process_fields(["a", "b", "c", "d"], 2)510 return_data.with_lists = []511 return_data.enter_root(None)512 return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])513 self.assertEqual(514 {1: {2: {"c": 3, "d": 4}}, 5: {6: {"c": 7, "d": 8}}}, return_data.result515 )516 def test_124_process_results_depth_3(self):517 return_data = mysql.MySQLExtPillar()518 return_data.process_fields(["a", "b", "c", "d"], 3)519 return_data.with_lists = []520 return_data.enter_root(None)521 return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])522 self.assertEqual({1: {2: {3: 4}}, 5: {6: {7: 8}}}, return_data.result)523 def test_125_process_results_depth_4(self):524 return_data = mysql.MySQLExtPillar()525 return_data.process_fields(["a", "b", "c", "d"], 4)526 return_data.with_lists = []527 return_data.enter_root(None)528 return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])529 self.assertEqual({1: {2: {3: 4}}, 5: {6: {7: 8}}}, return_data.result)530 def test_131_process_results_overwrite_legacy_multiple(self):531 return_data = mysql.MySQLExtPillar()532 return_data.process_fields(["a", "b"], 0)533 return_data.with_lists = []534 return_data.process_results([[1, 2], [3, 4], [1, 6]])535 self.assertEqual({1: 6, 3: 4}, return_data.result)536 def test_132_process_results_merge_depth_0(self):537 return_data = mysql.MySQLExtPillar()538 return_data.process_fields(["a", "b", "c", "d"], 0)539 return_data.with_lists = []540 return_data.enter_root(None)541 return_data.process_results([[1, 2, 3, 4], [1, 6, 7, 8]])542 self.assertEqual({1: {2: {3: 4}, 6: {7: 8}}}, return_data.result)543 def test_133_process_results_overwrite_depth_0(self):544 return_data = mysql.MySQLExtPillar()545 return_data.process_fields(["a", "b", "c", "d"], 0)546 return_data.with_lists = []547 return_data.enter_root(None)548 return_data.process_results([[1, 2, 3, 4], [1, 2, 3, 8]])549 self.assertEqual({1: {2: {3: 8}}}, return_data.result)550 def test_134_process_results_deepmerge_depth_0(self):551 return_data = mysql.MySQLExtPillar()552 return_data.process_fields(["a", "b", "c", "d"], 0)553 return_data.with_lists = []554 return_data.enter_root(None)555 return_data.process_results([[1, 2, 3, 4], [1, 2, 7, 8]])556 self.assertEqual({1: {2: {3: 4, 7: 8}}}, return_data.result)557 def test_135_process_results_overwrite_depth_1(self):558 return_data = mysql.MySQLExtPillar()559 return_data.process_fields(["a", "b", "c", "d"], 1)560 return_data.with_lists = []561 return_data.enter_root(None)562 return_data.process_results([[1, 2, 3, 4], [1, 6, 7, 8]])563 self.assertEqual({1: {"b": 6, "c": 7, "d": 8}}, return_data.result)564 def test_136_process_results_merge_depth_2(self):565 return_data = mysql.MySQLExtPillar()566 return_data.process_fields(["a", "b", "c", "d"], 2)567 return_data.with_lists = []568 return_data.enter_root(None)569 return_data.process_results([[1, 2, 3, 4], [1, 6, 7, 8]])570 self.assertEqual(571 {1: {2: {"c": 3, "d": 4}, 6: {"c": 7, "d": 8}}}, return_data.result572 )573 def test_137_process_results_overwrite_depth_2(self):574 return_data = mysql.MySQLExtPillar()575 return_data.process_fields(["a", "b", "c", "d"], 2)576 return_data.with_lists = []577 return_data.enter_root(None)578 return_data.process_results([[1, 2, 3, 4], [1, 2, 7, 8]])579 self.assertEqual({1: {2: {"c": 7, "d": 8}}}, return_data.result)580 def test_201_process_results_complexity_multiresults(self):581 return_data = mysql.MySQLExtPillar()582 return_data.process_fields(["a", "b", "c", "d"], 2)583 return_data.with_lists = []584 return_data.enter_root(None)585 return_data.process_results([[1, 2, 3, 4]])586 return_data.process_results([[1, 2, 7, 8]])587 self.assertEqual({1: {2: {"c": 7, "d": 8}}}, return_data.result)588 def test_202_process_results_complexity_as_list(self):589 return_data = mysql.MySQLExtPillar()590 return_data.process_fields(["a", "b", "c", "d"], 2)591 return_data.with_lists = []592 return_data.enter_root(None)593 return_data.as_list = True594 return_data.process_results([[1, 2, 3, 4]])595 return_data.process_results([[1, 2, 7, 8]])596 self.assertEqual({1: {2: {"c": [3, 7], "d": [4, 8]}}}, return_data.result)597 def test_203_process_results_complexity_as_list_deeper(self):598 return_data = mysql.MySQLExtPillar()599 return_data.process_fields(["a", "b", "c", "d"], 0)600 return_data.with_lists = []601 return_data.enter_root(None)602 return_data.as_list = True603 return_data.process_results([[1, 2, 3, 4]])604 return_data.process_results([[1, 2, 3, 8]])605 self.assertEqual({1: {2: {3: [4, 8]}}}, return_data.result)606 def test_204_process_results_complexity_as_list_mismatch_depth(self):607 return_data = mysql.MySQLExtPillar()608 return_data.as_list = True609 return_data.with_lists = []610 return_data.enter_root(None)611 return_data.process_fields(["a", "b", "c", "d"], 0)612 return_data.process_results([[1, 2, 3, 4]])613 return_data.process_results([[1, 2, 3, 5]])614 return_data.process_fields(["a", "b", "c", "d", "e"], 0)615 return_data.process_results([[1, 2, 3, 6, 7]])616 self.assertEqual({1: {2: {3: [4, 5, {6: 7}]}}}, return_data.result)617 def test_205_process_results_complexity_as_list_mismatch_depth_reversed(self):618 return_data = mysql.MySQLExtPillar()619 return_data.as_list = True620 return_data.with_lists = []621 return_data.enter_root(None)622 return_data.process_fields(["a", "b", "c", "d", "e"], 0)623 return_data.process_results([[1, 2, 3, 6, 7]])624 return_data.process_results([[1, 2, 3, 8, 9]])625 return_data.process_fields(["a", "b", "c", "d"], 0)626 return_data.process_results([[1, 2, 3, 4]])627 return_data.process_results([[1, 2, 3, 5]])628 self.assertEqual({1: {2: {3: [{6: 7, 8: 9}, 4, 5]}}}, return_data.result)629 def test_206_process_results_complexity_as_list_mismatch_depth_weird_order(self):630 return_data = mysql.MySQLExtPillar()631 return_data.as_list = True632 return_data.with_lists = []633 return_data.enter_root(None)634 return_data.process_fields(["a", "b", "c", "d", "e"], 0)635 return_data.process_results([[1, 2, 3, 6, 7]])636 return_data.process_fields(["a", "b", "c", "d"], 0)637 return_data.process_results([[1, 2, 3, 4]])638 return_data.process_fields(["a", "b", "c", "d", "e"], 0)639 return_data.process_results([[1, 2, 3, 8, 9]])640 return_data.process_fields(["a", "b", "c", "d"], 0)641 return_data.process_results([[1, 2, 3, 5]])642 self.assertEqual({1: {2: {3: [{6: 7}, 4, {8: 9}, 5]}}}, return_data.result)643 def test_207_process_results_complexity_collision_mismatch_depth(self):644 return_data = mysql.MySQLExtPillar()645 return_data.as_list = False646 return_data.with_lists = []647 return_data.enter_root(None)648 return_data.process_fields(["a", "b", "c", "d"], 0)649 return_data.process_results([[1, 2, 3, 4]])650 return_data.process_results([[1, 2, 3, 5]])651 return_data.process_fields(["a", "b", "c", "d", "e"], 0)652 return_data.process_results([[1, 2, 3, 6, 7]])653 self.assertEqual({1: {2: {3: {6: 7}}}}, return_data.result)654 def test_208_process_results_complexity_collision_mismatch_depth_reversed(self):655 return_data = mysql.MySQLExtPillar()656 return_data.as_list = False657 return_data.with_lists = []658 return_data.enter_root(None)659 return_data.process_fields(["a", "b", "c", "d", "e"], 0)660 return_data.process_results([[1, 2, 3, 6, 7]])661 return_data.process_results([[1, 2, 3, 8, 9]])662 return_data.process_fields(["a", "b", "c", "d"], 0)663 return_data.process_results([[1, 2, 3, 4]])664 return_data.process_results([[1, 2, 3, 5]])665 self.assertEqual({1: {2: {3: 5}}}, return_data.result)666 def test_209_process_results_complexity_collision_mismatch_depth_weird_order(self):667 return_data = mysql.MySQLExtPillar()668 return_data.as_list = False669 return_data.with_lists = []670 return_data.enter_root(None)671 return_data.process_fields(["a", "b", "c", "d", "e"], 0)672 return_data.process_results([[1, 2, 3, 6, 7]])673 return_data.process_fields(["a", "b", "c", "d"], 0)674 return_data.process_results([[1, 2, 3, 4]])675 return_data.process_fields(["a", "b", "c", "d", "e"], 0)676 return_data.process_results([[1, 2, 3, 8, 9]])677 return_data.process_fields(["a", "b", "c", "d"], 0)678 return_data.process_results([[1, 2, 3, 5]])679 self.assertEqual({1: {2: {3: 5}}}, return_data.result)680 def test_20A_process_results_complexity_as_list_vary(self):681 return_data = mysql.MySQLExtPillar()682 return_data.as_list = True683 return_data.with_lists = []684 return_data.enter_root(None)685 return_data.process_fields(["a", "b", "c", "d", "e"], 0)686 return_data.process_results([[1, 2, 3, 6, 7]])687 return_data.process_results([[1, 2, 3, 8, 9]])688 return_data.process_fields(["a", "b", "c", "d"], 0)689 return_data.process_results([[1, 2, 3, 4]])690 return_data.as_list = False691 return_data.process_results([[1, 2, 3, 5]])692 self.assertEqual({1: {2: {3: 5}}}, return_data.result)693 def test_207_process_results_complexity_roots_collision(self):694 return_data = mysql.MySQLExtPillar()695 return_data.as_list = False696 return_data.with_lists = []697 return_data.enter_root(None)698 return_data.process_fields(["a", "b", "c", "d"], 0)699 return_data.process_results([[1, 2, 3, 4]])700 return_data.enter_root(1)701 return_data.process_results([[5, 6, 7, 8]])702 self.assertEqual({1: {5: {6: {7: 8}}}}, return_data.result)703 def test_301_process_results_with_lists(self):704 """705 Validates the following results:706 {'a': [707 {'c': [708 {'e': 1},709 {'g': 2}710 ]711 },712 {'h': [713 {'j': 3, 'k': 4}714 ]715 }716 ]}717 """718 return_data = mysql.MySQLExtPillar()719 return_data.as_list = False720 return_data.with_lists = [1, 3]721 return_data.enter_root(None)722 return_data.process_fields(["a", "b", "c", "d", "e", "v"], 0)723 return_data.process_results(724 [725 ["a", "b", "c", "d", "e", 1],726 ["a", "b", "c", "f", "g", 2],727 ["a", "z", "h", "y", "j", 3],728 ["a", "z", "h", "y", "k", 4],729 ]730 )731 assert "a" in return_data.result732 for x in return_data.result["a"]:733 if "c" in x:734 assert list(x.keys()) == ["c"], x.keys()735 for y in x["c"]:736 if "e" in y:737 assert list(y.keys()) == ["e"]738 assert y["e"] == 1739 elif "g" in y:740 assert list(y.keys()) == ["g"]741 assert y["g"] == 2742 else:743 raise ValueError("Unexpected value {0}".format(y))744 elif "h" in x:745 assert len(x["h"]) == 1746 for y in x["h"]:747 if "j" in y:748 assert len(y.keys()) == 2749 assert y["j"] == 3750 elif "h" in y:751 assert len(y.keys()) == 2752 assert y["k"] == 4753 else:754 raise ValueError("Unexpected value {0}".format(y))755 else:756 raise ValueError("Unexpected value {0}".format(x))757 def test_302_process_results_with_lists_consecutive(self):758 """759 Validates the following results:760 {'a': [761 [[762 {'e': 1},763 {'g': 2}764 ]765 ],766 [[767 {'j': 3, 'k': 4}768 ]769 ]770 ]}771 """772 return_data = mysql.MySQLExtPillar()773 return_data.as_list = False774 return_data.with_lists = [1, 2, 3]775 return_data.enter_root(None)776 return_data.process_fields(["a", "b", "c", "d", "e", "v"], 0)777 return_data.process_results(778 [779 ["a", "b", "c", "d", "e", 1],780 ["a", "b", "c", "f", "g", 2],781 ["a", "z", "h", "y", "j", 3],782 ["a", "z", "h", "y", "k", 4],783 ]784 )785 assert "a" in return_data.result786 for x in return_data.result["a"]:787 assert len(x) == 1788 if len(x[0][0]) == 1:789 for y in x[0]:790 if "e" in y:791 assert list(y.keys()) == ["e"]792 assert y["e"] == 1793 elif "g" in y:794 assert list(y.keys()) == ["g"]795 assert y["g"] == 2796 else:797 raise ValueError("Unexpected value {0}".format(y))798 elif len(x[0][0]) == 2:799 for y in x[0]:800 if "j" in y:801 assert len(y.keys()) == 2802 assert y["j"] == 3803 elif "k" in y:804 assert len(y.keys()) == 2805 assert y["k"] == 4806 else:807 raise ValueError("Unexpected value {0}".format(len(x[0][0])))808 else:...
test_sqlcipher.py
Source:test_sqlcipher.py
1# -*- coding: utf-8 -*-2# Import python libs3from __future__ import absolute_import, print_function, unicode_literals4# Import Salt Libs5import salt.pillar.sqlcipher as sqlcipher6# Import Salt Testing libs7from tests.support.unit import TestCase8class SQLCipherPillarTestCase(TestCase):9 maxDiff = None10 def test_001_extract_queries_list(self):11 return_data = sqlcipher.SQLCipherExtPillar()12 args, kwargs = (13 [14 "SELECT blah",15 "SELECT blah2",16 ("SELECT blah3",),17 ("SELECT blah4", 2),18 {"query": "SELECT blah5"},19 {"query": "SELECT blah6", "depth": 2},20 {"query": "SELECT blah7", "as_list": True},21 {"query": "SELECT blah8", "with_lists": "1"},22 {"query": "SELECT blah9", "with_lists": "1,2"},23 ],24 {},25 )26 qbuffer = return_data.extract_queries(args, kwargs)27 self.assertEqual(28 [29 [30 None,31 {32 "query": "SELECT blah",33 "depth": 0,34 "as_list": False,35 "with_lists": None,36 "ignore_null": False,37 },38 ],39 [40 None,41 {42 "query": "SELECT blah2",43 "depth": 0,44 "as_list": False,45 "with_lists": None,46 "ignore_null": False,47 },48 ],49 [50 None,51 {52 "query": "SELECT blah3",53 "depth": 0,54 "as_list": False,55 "with_lists": None,56 "ignore_null": False,57 },58 ],59 [60 None,61 {62 "query": "SELECT blah4",63 "depth": 2,64 "as_list": False,65 "with_lists": None,66 "ignore_null": False,67 },68 ],69 [70 None,71 {72 "query": "SELECT blah5",73 "depth": 0,74 "as_list": False,75 "with_lists": None,76 "ignore_null": False,77 },78 ],79 [80 None,81 {82 "query": "SELECT blah6",83 "depth": 2,84 "as_list": False,85 "with_lists": None,86 "ignore_null": False,87 },88 ],89 [90 None,91 {92 "query": "SELECT blah7",93 "depth": 0,94 "as_list": True,95 "with_lists": None,96 "ignore_null": False,97 },98 ],99 [100 None,101 {102 "query": "SELECT blah8",103 "depth": 0,104 "as_list": False,105 "with_lists": [1],106 "ignore_null": False,107 },108 ],109 [110 None,111 {112 "query": "SELECT blah9",113 "depth": 0,114 "as_list": False,115 "with_lists": [1, 2],116 "ignore_null": False,117 },118 ],119 ],120 qbuffer,121 )122 def test_002_extract_queries_kwarg(self):123 return_data = sqlcipher.SQLCipherExtPillar()124 args, kwargs = (125 [],126 {127 "1": "SELECT blah",128 "2": "SELECT blah2",129 "3": ("SELECT blah3",),130 "4": ("SELECT blah4", 2),131 "5": {"query": "SELECT blah5"},132 "6": {"query": "SELECT blah6", "depth": 2},133 "7": {"query": "SELECT blah7", "as_list": True},134 },135 )136 qbuffer = return_data.extract_queries(args, kwargs)137 self.assertEqual(138 [139 [140 "1",141 {142 "query": "SELECT blah",143 "depth": 0,144 "as_list": False,145 "with_lists": None,146 "ignore_null": False,147 },148 ],149 [150 "2",151 {152 "query": "SELECT blah2",153 "depth": 0,154 "as_list": False,155 "with_lists": None,156 "ignore_null": False,157 },158 ],159 [160 "3",161 {162 "query": "SELECT blah3",163 "depth": 0,164 "as_list": False,165 "with_lists": None,166 "ignore_null": False,167 },168 ],169 [170 "4",171 {172 "query": "SELECT blah4",173 "depth": 2,174 "as_list": False,175 "with_lists": None,176 "ignore_null": False,177 },178 ],179 [180 "5",181 {182 "query": "SELECT blah5",183 "depth": 0,184 "as_list": False,185 "with_lists": None,186 "ignore_null": False,187 },188 ],189 [190 "6",191 {192 "query": "SELECT blah6",193 "depth": 2,194 "as_list": False,195 "with_lists": None,196 "ignore_null": False,197 },198 ],199 [200 "7",201 {202 "query": "SELECT blah7",203 "depth": 0,204 "as_list": True,205 "with_lists": None,206 "ignore_null": False,207 },208 ],209 ],210 qbuffer,211 )212 def test_003_extract_queries_mixed(self):213 return_data = sqlcipher.SQLCipherExtPillar()214 args, kwargs = (215 [216 "SELECT blah1",217 ("SELECT blah2", 2),218 {"query": "SELECT blah3", "as_list": True},219 ],220 {221 "1": "SELECT blah1",222 "2": ("SELECT blah2", 2),223 "3": {"query": "SELECT blah3", "as_list": True},224 },225 )226 qbuffer = return_data.extract_queries(args, kwargs)227 self.assertEqual(228 [229 [230 None,231 {232 "query": "SELECT blah1",233 "depth": 0,234 "as_list": False,235 "with_lists": None,236 "ignore_null": False,237 },238 ],239 [240 None,241 {242 "query": "SELECT blah2",243 "depth": 2,244 "as_list": False,245 "with_lists": None,246 "ignore_null": False,247 },248 ],249 [250 None,251 {252 "query": "SELECT blah3",253 "depth": 0,254 "as_list": True,255 "with_lists": None,256 "ignore_null": False,257 },258 ],259 [260 "1",261 {262 "query": "SELECT blah1",263 "depth": 0,264 "as_list": False,265 "with_lists": None,266 "ignore_null": False,267 },268 ],269 [270 "2",271 {272 "query": "SELECT blah2",273 "depth": 2,274 "as_list": False,275 "with_lists": None,276 "ignore_null": False,277 },278 ],279 [280 "3",281 {282 "query": "SELECT blah3",283 "depth": 0,284 "as_list": True,285 "with_lists": None,286 "ignore_null": False,287 },288 ],289 ],290 qbuffer,291 )292 def test_004_extract_queries_bogus_list(self):293 # This test is specifically checking that empty queries are dropped294 return_data = sqlcipher.SQLCipherExtPillar()295 args, kwargs = (296 [297 "SELECT blah",298 "",299 "SELECT blah2",300 ("SELECT blah3",),301 ("",),302 ("SELECT blah4", 2),303 tuple(),304 ("SELECT blah5",),305 {"query": "SELECT blah6"},306 {"query": ""},307 {"query": "SELECT blah7", "depth": 2},308 {"not_a_query": "in sight!"},309 {"query": "SELECT blah8", "as_list": True},310 ],311 {},312 )313 qbuffer = return_data.extract_queries(args, kwargs)314 self.assertEqual(315 [316 [317 None,318 {319 "query": "SELECT blah",320 "depth": 0,321 "as_list": False,322 "with_lists": None,323 "ignore_null": False,324 },325 ],326 [327 None,328 {329 "query": "SELECT blah2",330 "depth": 0,331 "as_list": False,332 "with_lists": None,333 "ignore_null": False,334 },335 ],336 [337 None,338 {339 "query": "SELECT blah3",340 "depth": 0,341 "as_list": False,342 "with_lists": None,343 "ignore_null": False,344 },345 ],346 [347 None,348 {349 "query": "SELECT blah4",350 "depth": 2,351 "as_list": False,352 "with_lists": None,353 "ignore_null": False,354 },355 ],356 [357 None,358 {359 "query": "SELECT blah5",360 "depth": 0,361 "as_list": False,362 "with_lists": None,363 "ignore_null": False,364 },365 ],366 [367 None,368 {369 "query": "SELECT blah6",370 "depth": 0,371 "as_list": False,372 "with_lists": None,373 "ignore_null": False,374 },375 ],376 [377 None,378 {379 "query": "SELECT blah7",380 "depth": 2,381 "as_list": False,382 "with_lists": None,383 "ignore_null": False,384 },385 ],386 [387 None,388 {389 "query": "SELECT blah8",390 "depth": 0,391 "as_list": True,392 "with_lists": None,393 "ignore_null": False,394 },395 ],396 ],397 qbuffer,398 )399 def test_005_extract_queries_bogus_kwargs(self):400 # this test is cut down as most of the path matches test_*_bogus_list401 return_data = sqlcipher.SQLCipherExtPillar()402 args, kwargs = [], {"1": "SELECT blah", "2": "", "3": "SELECT blah2"}403 qbuffer = return_data.extract_queries(args, kwargs)404 self.assertEqual(405 [406 [407 "1",408 {409 "query": "SELECT blah",410 "depth": 0,411 "as_list": False,412 "with_lists": None,413 "ignore_null": False,414 },415 ],416 [417 "3",418 {419 "query": "SELECT blah2",420 "depth": 0,421 "as_list": False,422 "with_lists": None,423 "ignore_null": False,424 },425 ],426 ],427 qbuffer,428 )429 def test_011_enter_root(self):430 return_data = sqlcipher.SQLCipherExtPillar()431 return_data.enter_root("test")432 self.assertEqual(return_data.result["test"], return_data.focus)433 return_data.enter_root(None)434 self.assertEqual(return_data.result, return_data.focus)435 def test_021_process_fields(self):436 return_data = sqlcipher.SQLCipherExtPillar()437 return_data.process_fields(["a", "b"], 0)438 self.assertEqual(return_data.num_fields, 2)439 self.assertEqual(return_data.depth, 1)440 return_data.process_fields(["a", "b"], 2)441 self.assertEqual(return_data.num_fields, 2)442 self.assertEqual(return_data.depth, 1)443 return_data.process_fields(["a", "b", "c", "d"], 0)444 self.assertEqual(return_data.num_fields, 4)445 self.assertEqual(return_data.depth, 3)446 return_data.process_fields(["a", "b", "c", "d"], 1)447 self.assertEqual(return_data.num_fields, 4)448 self.assertEqual(return_data.depth, 1)449 return_data.process_fields(["a", "b", "c", "d"], 2)450 self.assertEqual(return_data.num_fields, 4)451 self.assertEqual(return_data.depth, 2)452 return_data.process_fields(["a", "b", "c", "d"], 3)453 self.assertEqual(return_data.num_fields, 4)454 self.assertEqual(return_data.depth, 3)455 return_data.process_fields(["a", "b", "c", "d"], 4)456 self.assertEqual(return_data.num_fields, 4)457 self.assertEqual(return_data.depth, 3)458 def test_111_process_results_legacy(self):459 return_data = sqlcipher.SQLCipherExtPillar()460 return_data.process_fields(["a", "b"], 0)461 return_data.with_lists = []462 return_data.process_results([[1, 2]])463 self.assertEqual({1: 2}, return_data.result)464 def test_112_process_results_legacy_multiple(self):465 return_data = sqlcipher.SQLCipherExtPillar()466 return_data.process_fields(["a", "b"], 0)467 return_data.with_lists = []468 return_data.process_results([[1, 2], [3, 4], [5, 6]])469 self.assertEqual({1: 2, 3: 4, 5: 6}, return_data.result)470 def test_121_process_results_depth_0(self):471 return_data = sqlcipher.SQLCipherExtPillar()472 return_data.process_fields(["a", "b", "c", "d"], 0)473 return_data.with_lists = []474 return_data.enter_root(None)475 return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])476 self.assertEqual({1: {2: {3: 4}}, 5: {6: {7: 8}}}, return_data.result)477 def test_122_process_results_depth_1(self):478 return_data = sqlcipher.SQLCipherExtPillar()479 return_data.process_fields(["a", "b", "c", "d"], 1)480 return_data.with_lists = []481 return_data.enter_root(None)482 return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])483 self.assertEqual(484 {1: {"b": 2, "c": 3, "d": 4}, 5: {"b": 6, "c": 7, "d": 8}},485 return_data.result,486 )487 def test_123_process_results_depth_2(self):488 return_data = sqlcipher.SQLCipherExtPillar()489 return_data.process_fields(["a", "b", "c", "d"], 2)490 return_data.with_lists = []491 return_data.enter_root(None)492 return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])493 self.assertEqual(494 {1: {2: {"c": 3, "d": 4}}, 5: {6: {"c": 7, "d": 8}}}, return_data.result495 )496 def test_124_process_results_depth_3(self):497 return_data = sqlcipher.SQLCipherExtPillar()498 return_data.process_fields(["a", "b", "c", "d"], 3)499 return_data.with_lists = []500 return_data.enter_root(None)501 return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])502 self.assertEqual({1: {2: {3: 4}}, 5: {6: {7: 8}}}, return_data.result)503 def test_125_process_results_depth_4(self):504 return_data = sqlcipher.SQLCipherExtPillar()505 return_data.process_fields(["a", "b", "c", "d"], 4)506 return_data.with_lists = []507 return_data.enter_root(None)508 return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])509 self.assertEqual({1: {2: {3: 4}}, 5: {6: {7: 8}}}, return_data.result)510 def test_131_process_results_overwrite_legacy_multiple(self):511 return_data = sqlcipher.SQLCipherExtPillar()512 return_data.process_fields(["a", "b"], 0)513 return_data.with_lists = []514 return_data.process_results([[1, 2], [3, 4], [1, 6]])515 self.assertEqual({1: 6, 3: 4}, return_data.result)516 def test_132_process_results_merge_depth_0(self):517 return_data = sqlcipher.SQLCipherExtPillar()518 return_data.process_fields(["a", "b", "c", "d"], 0)519 return_data.with_lists = []520 return_data.enter_root(None)521 return_data.process_results([[1, 2, 3, 4], [1, 6, 7, 8]])522 self.assertEqual({1: {2: {3: 4}, 6: {7: 8}}}, return_data.result)523 def test_133_process_results_overwrite_depth_0(self):524 return_data = sqlcipher.SQLCipherExtPillar()525 return_data.process_fields(["a", "b", "c", "d"], 0)526 return_data.with_lists = []527 return_data.enter_root(None)528 return_data.process_results([[1, 2, 3, 4], [1, 2, 3, 8]])529 self.assertEqual({1: {2: {3: 8}}}, return_data.result)530 def test_134_process_results_deepmerge_depth_0(self):531 return_data = sqlcipher.SQLCipherExtPillar()532 return_data.process_fields(["a", "b", "c", "d"], 0)533 return_data.with_lists = []534 return_data.enter_root(None)535 return_data.process_results([[1, 2, 3, 4], [1, 2, 7, 8]])536 self.assertEqual({1: {2: {3: 4, 7: 8}}}, return_data.result)537 def test_135_process_results_overwrite_depth_1(self):538 return_data = sqlcipher.SQLCipherExtPillar()539 return_data.process_fields(["a", "b", "c", "d"], 1)540 return_data.with_lists = []541 return_data.enter_root(None)542 return_data.process_results([[1, 2, 3, 4], [1, 6, 7, 8]])543 self.assertEqual({1: {"b": 6, "c": 7, "d": 8}}, return_data.result)544 def test_136_process_results_merge_depth_2(self):545 return_data = sqlcipher.SQLCipherExtPillar()546 return_data.process_fields(["a", "b", "c", "d"], 2)547 return_data.with_lists = []548 return_data.enter_root(None)549 return_data.process_results([[1, 2, 3, 4], [1, 6, 7, 8]])550 self.assertEqual(551 {1: {2: {"c": 3, "d": 4}, 6: {"c": 7, "d": 8}}}, return_data.result552 )553 def test_137_process_results_overwrite_depth_2(self):554 return_data = sqlcipher.SQLCipherExtPillar()555 return_data.process_fields(["a", "b", "c", "d"], 2)556 return_data.with_lists = []557 return_data.enter_root(None)558 return_data.process_results([[1, 2, 3, 4], [1, 2, 7, 8]])559 self.assertEqual({1: {2: {"c": 7, "d": 8}}}, return_data.result)560 def test_201_process_results_complexity_multiresults(self):561 return_data = sqlcipher.SQLCipherExtPillar()562 return_data.process_fields(["a", "b", "c", "d"], 2)563 return_data.with_lists = []564 return_data.enter_root(None)565 return_data.process_results([[1, 2, 3, 4]])566 return_data.process_results([[1, 2, 7, 8]])567 self.assertEqual({1: {2: {"c": 7, "d": 8}}}, return_data.result)568 def test_202_process_results_complexity_as_list(self):569 return_data = sqlcipher.SQLCipherExtPillar()570 return_data.process_fields(["a", "b", "c", "d"], 2)571 return_data.with_lists = []572 return_data.enter_root(None)573 return_data.as_list = True574 return_data.process_results([[1, 2, 3, 4]])575 return_data.process_results([[1, 2, 7, 8]])576 self.assertEqual({1: {2: {"c": [3, 7], "d": [4, 8]}}}, return_data.result)577 def test_203_process_results_complexity_as_list_deeper(self):578 return_data = sqlcipher.SQLCipherExtPillar()579 return_data.process_fields(["a", "b", "c", "d"], 0)580 return_data.with_lists = []581 return_data.enter_root(None)582 return_data.as_list = True583 return_data.process_results([[1, 2, 3, 4]])584 return_data.process_results([[1, 2, 3, 8]])585 self.assertEqual({1: {2: {3: [4, 8]}}}, return_data.result)586 def test_204_process_results_complexity_as_list_mismatch_depth(self):587 return_data = sqlcipher.SQLCipherExtPillar()588 return_data.as_list = True589 return_data.with_lists = []590 return_data.enter_root(None)591 return_data.process_fields(["a", "b", "c", "d"], 0)592 return_data.process_results([[1, 2, 3, 4]])593 return_data.process_results([[1, 2, 3, 5]])594 return_data.process_fields(["a", "b", "c", "d", "e"], 0)595 return_data.process_results([[1, 2, 3, 6, 7]])596 self.assertEqual({1: {2: {3: [4, 5, {6: 7}]}}}, return_data.result)597 def test_205_process_results_complexity_as_list_mismatch_depth_reversed(self):598 return_data = sqlcipher.SQLCipherExtPillar()599 return_data.as_list = True600 return_data.with_lists = []601 return_data.enter_root(None)602 return_data.process_fields(["a", "b", "c", "d", "e"], 0)603 return_data.process_results([[1, 2, 3, 6, 7]])604 return_data.process_results([[1, 2, 3, 8, 9]])605 return_data.process_fields(["a", "b", "c", "d"], 0)606 return_data.process_results([[1, 2, 3, 4]])607 return_data.process_results([[1, 2, 3, 5]])608 self.assertEqual({1: {2: {3: [{6: 7, 8: 9}, 4, 5]}}}, return_data.result)609 def test_206_process_results_complexity_as_list_mismatch_depth_weird_order(self):610 return_data = sqlcipher.SQLCipherExtPillar()611 return_data.as_list = True612 return_data.with_lists = []613 return_data.enter_root(None)614 return_data.process_fields(["a", "b", "c", "d", "e"], 0)615 return_data.process_results([[1, 2, 3, 6, 7]])616 return_data.process_fields(["a", "b", "c", "d"], 0)617 return_data.process_results([[1, 2, 3, 4]])618 return_data.process_fields(["a", "b", "c", "d", "e"], 0)619 return_data.process_results([[1, 2, 3, 8, 9]])620 return_data.process_fields(["a", "b", "c", "d"], 0)621 return_data.process_results([[1, 2, 3, 5]])622 self.assertEqual({1: {2: {3: [{6: 7}, 4, {8: 9}, 5]}}}, return_data.result)623 def test_207_process_results_complexity_collision_mismatch_depth(self):624 return_data = sqlcipher.SQLCipherExtPillar()625 return_data.as_list = False626 return_data.with_lists = []627 return_data.enter_root(None)628 return_data.process_fields(["a", "b", "c", "d"], 0)629 return_data.process_results([[1, 2, 3, 4]])630 return_data.process_results([[1, 2, 3, 5]])631 return_data.process_fields(["a", "b", "c", "d", "e"], 0)632 return_data.process_results([[1, 2, 3, 6, 7]])633 self.assertEqual({1: {2: {3: {6: 7}}}}, return_data.result)634 def test_208_process_results_complexity_collision_mismatch_depth_reversed(self):635 return_data = sqlcipher.SQLCipherExtPillar()636 return_data.as_list = False637 return_data.with_lists = []638 return_data.enter_root(None)639 return_data.process_fields(["a", "b", "c", "d", "e"], 0)640 return_data.process_results([[1, 2, 3, 6, 7]])641 return_data.process_results([[1, 2, 3, 8, 9]])642 return_data.process_fields(["a", "b", "c", "d"], 0)643 return_data.process_results([[1, 2, 3, 4]])644 return_data.process_results([[1, 2, 3, 5]])645 self.assertEqual({1: {2: {3: 5}}}, return_data.result)646 def test_209_process_results_complexity_collision_mismatch_depth_weird_order(self):647 return_data = sqlcipher.SQLCipherExtPillar()648 return_data.as_list = False649 return_data.with_lists = []650 return_data.enter_root(None)651 return_data.process_fields(["a", "b", "c", "d", "e"], 0)652 return_data.process_results([[1, 2, 3, 6, 7]])653 return_data.process_fields(["a", "b", "c", "d"], 0)654 return_data.process_results([[1, 2, 3, 4]])655 return_data.process_fields(["a", "b", "c", "d", "e"], 0)656 return_data.process_results([[1, 2, 3, 8, 9]])657 return_data.process_fields(["a", "b", "c", "d"], 0)658 return_data.process_results([[1, 2, 3, 5]])659 self.assertEqual({1: {2: {3: 5}}}, return_data.result)660 def test_20A_process_results_complexity_as_list_vary(self):661 return_data = sqlcipher.SQLCipherExtPillar()662 return_data.as_list = True663 return_data.with_lists = []664 return_data.enter_root(None)665 return_data.process_fields(["a", "b", "c", "d", "e"], 0)666 return_data.process_results([[1, 2, 3, 6, 7]])667 return_data.process_results([[1, 2, 3, 8, 9]])668 return_data.process_fields(["a", "b", "c", "d"], 0)669 return_data.process_results([[1, 2, 3, 4]])670 return_data.as_list = False671 return_data.process_results([[1, 2, 3, 5]])672 self.assertEqual({1: {2: {3: 5}}}, return_data.result)673 def test_207_process_results_complexity_roots_collision(self):674 return_data = sqlcipher.SQLCipherExtPillar()675 return_data.as_list = False676 return_data.with_lists = []677 return_data.enter_root(None)678 return_data.process_fields(["a", "b", "c", "d"], 0)679 return_data.process_results([[1, 2, 3, 4]])680 return_data.enter_root(1)681 return_data.process_results([[5, 6, 7, 8]])682 self.assertEqual({1: {5: {6: {7: 8}}}}, return_data.result)683 def test_301_process_results_with_lists(self):684 return_data = sqlcipher.SQLCipherExtPillar()685 return_data.as_list = False686 return_data.with_lists = [1, 3]687 return_data.enter_root(None)688 return_data.process_fields(["a", "b", "c", "d", "e", "v"], 0)689 return_data.process_results(690 [691 ["a", "b", "c", "d", "e", 1],692 ["a", "b", "c", "f", "g", 2],693 ["a", "z", "h", "y", "j", 3],694 ["a", "z", "h", "y", "k", 4],695 ]696 )697 self.assertEqual(698 sorted({"a": [{"c": [{"e": 1}, {"g": 2}]}, {"h": [{"j": 3, "k": 4}]}]}),699 sorted(return_data.result),700 )701 def test_302_process_results_with_lists_consecutive(self):702 return_data = sqlcipher.SQLCipherExtPillar()703 return_data.as_list = False704 return_data.with_lists = [1, 2, 3]705 return_data.enter_root(None)706 return_data.process_fields(["a", "b", "c", "d", "e", "v"], 0)707 return_data.process_results(708 [709 ["a", "b", "c", "d", "e", 1],710 ["a", "b", "c", "f", "g", 2],711 ["a", "z", "h", "y", "j", 3],712 ["a", "z", "h", "y", "k", 4],713 ]714 )715 self.assertEqual(716 sorted({"a": [[[{"e": 1}, {"g": 2}]], [[{"j": 3, "k": 4}]]]}),717 sorted(return_data.result),...
test_sqlite3.py
Source:test_sqlite3.py
1# -*- coding: utf-8 -*-2# Import python libs3from __future__ import absolute_import, print_function, unicode_literals4# Import Salt Libs5import salt.pillar.sqlite3 as sqlite36# Import Salt Testing libs7from tests.support.unit import TestCase8class SQLite3PillarTestCase(TestCase):9 maxDiff = None10 def test_001_extract_queries_list(self):11 return_data = sqlite3.SQLite3ExtPillar()12 args, kwargs = (13 [14 "SELECT blah",15 "SELECT blah2",16 ("SELECT blah3",),17 ("SELECT blah4", 2),18 {"query": "SELECT blah5"},19 {"query": "SELECT blah6", "depth": 2},20 {"query": "SELECT blah7", "as_list": True},21 {"query": "SELECT blah8", "with_lists": "1"},22 {"query": "SELECT blah9", "with_lists": "1,2"},23 ],24 {},25 )26 qbuffer = return_data.extract_queries(args, kwargs)27 self.assertEqual(28 [29 [30 None,31 {32 "query": "SELECT blah",33 "depth": 0,34 "as_list": False,35 "with_lists": None,36 "ignore_null": False,37 },38 ],39 [40 None,41 {42 "query": "SELECT blah2",43 "depth": 0,44 "as_list": False,45 "with_lists": None,46 "ignore_null": False,47 },48 ],49 [50 None,51 {52 "query": "SELECT blah3",53 "depth": 0,54 "as_list": False,55 "with_lists": None,56 "ignore_null": False,57 },58 ],59 [60 None,61 {62 "query": "SELECT blah4",63 "depth": 2,64 "as_list": False,65 "with_lists": None,66 "ignore_null": False,67 },68 ],69 [70 None,71 {72 "query": "SELECT blah5",73 "depth": 0,74 "as_list": False,75 "with_lists": None,76 "ignore_null": False,77 },78 ],79 [80 None,81 {82 "query": "SELECT blah6",83 "depth": 2,84 "as_list": False,85 "with_lists": None,86 "ignore_null": False,87 },88 ],89 [90 None,91 {92 "query": "SELECT blah7",93 "depth": 0,94 "as_list": True,95 "with_lists": None,96 "ignore_null": False,97 },98 ],99 [100 None,101 {102 "query": "SELECT blah8",103 "depth": 0,104 "as_list": False,105 "with_lists": [1],106 "ignore_null": False,107 },108 ],109 [110 None,111 {112 "query": "SELECT blah9",113 "depth": 0,114 "as_list": False,115 "with_lists": [1, 2],116 "ignore_null": False,117 },118 ],119 ],120 qbuffer,121 )122 def test_002_extract_queries_kwarg(self):123 return_data = sqlite3.SQLite3ExtPillar()124 args, kwargs = (125 [],126 {127 "1": "SELECT blah",128 "2": "SELECT blah2",129 "3": ("SELECT blah3",),130 "4": ("SELECT blah4", 2),131 "5": {"query": "SELECT blah5"},132 "6": {"query": "SELECT blah6", "depth": 2},133 "7": {"query": "SELECT blah7", "as_list": True},134 },135 )136 qbuffer = return_data.extract_queries(args, kwargs)137 self.assertEqual(138 [139 [140 "1",141 {142 "query": "SELECT blah",143 "depth": 0,144 "as_list": False,145 "with_lists": None,146 "ignore_null": False,147 },148 ],149 [150 "2",151 {152 "query": "SELECT blah2",153 "depth": 0,154 "as_list": False,155 "with_lists": None,156 "ignore_null": False,157 },158 ],159 [160 "3",161 {162 "query": "SELECT blah3",163 "depth": 0,164 "as_list": False,165 "with_lists": None,166 "ignore_null": False,167 },168 ],169 [170 "4",171 {172 "query": "SELECT blah4",173 "depth": 2,174 "as_list": False,175 "with_lists": None,176 "ignore_null": False,177 },178 ],179 [180 "5",181 {182 "query": "SELECT blah5",183 "depth": 0,184 "as_list": False,185 "with_lists": None,186 "ignore_null": False,187 },188 ],189 [190 "6",191 {192 "query": "SELECT blah6",193 "depth": 2,194 "as_list": False,195 "with_lists": None,196 "ignore_null": False,197 },198 ],199 [200 "7",201 {202 "query": "SELECT blah7",203 "depth": 0,204 "as_list": True,205 "with_lists": None,206 "ignore_null": False,207 },208 ],209 ],210 qbuffer,211 )212 def test_003_extract_queries_mixed(self):213 return_data = sqlite3.SQLite3ExtPillar()214 args, kwargs = (215 [216 "SELECT blah1",217 ("SELECT blah2", 2),218 {"query": "SELECT blah3", "as_list": True},219 ],220 {221 "1": "SELECT blah1",222 "2": ("SELECT blah2", 2),223 "3": {"query": "SELECT blah3", "as_list": True},224 },225 )226 qbuffer = return_data.extract_queries(args, kwargs)227 self.assertEqual(228 [229 [230 None,231 {232 "query": "SELECT blah1",233 "depth": 0,234 "as_list": False,235 "with_lists": None,236 "ignore_null": False,237 },238 ],239 [240 None,241 {242 "query": "SELECT blah2",243 "depth": 2,244 "as_list": False,245 "with_lists": None,246 "ignore_null": False,247 },248 ],249 [250 None,251 {252 "query": "SELECT blah3",253 "depth": 0,254 "as_list": True,255 "with_lists": None,256 "ignore_null": False,257 },258 ],259 [260 "1",261 {262 "query": "SELECT blah1",263 "depth": 0,264 "as_list": False,265 "with_lists": None,266 "ignore_null": False,267 },268 ],269 [270 "2",271 {272 "query": "SELECT blah2",273 "depth": 2,274 "as_list": False,275 "with_lists": None,276 "ignore_null": False,277 },278 ],279 [280 "3",281 {282 "query": "SELECT blah3",283 "depth": 0,284 "as_list": True,285 "with_lists": None,286 "ignore_null": False,287 },288 ],289 ],290 qbuffer,291 )292 def test_004_extract_queries_bogus_list(self):293 # This test is specifically checking that empty queries are dropped294 return_data = sqlite3.SQLite3ExtPillar()295 args, kwargs = (296 [297 "SELECT blah",298 "",299 "SELECT blah2",300 ("SELECT blah3",),301 ("",),302 ("SELECT blah4", 2),303 tuple(),304 ("SELECT blah5",),305 {"query": "SELECT blah6"},306 {"query": ""},307 {"query": "SELECT blah7", "depth": 2},308 {"not_a_query": "in sight!"},309 {"query": "SELECT blah8", "as_list": True},310 ],311 {},312 )313 qbuffer = return_data.extract_queries(args, kwargs)314 self.assertEqual(315 [316 [317 None,318 {319 "query": "SELECT blah",320 "depth": 0,321 "as_list": False,322 "with_lists": None,323 "ignore_null": False,324 },325 ],326 [327 None,328 {329 "query": "SELECT blah2",330 "depth": 0,331 "as_list": False,332 "with_lists": None,333 "ignore_null": False,334 },335 ],336 [337 None,338 {339 "query": "SELECT blah3",340 "depth": 0,341 "as_list": False,342 "with_lists": None,343 "ignore_null": False,344 },345 ],346 [347 None,348 {349 "query": "SELECT blah4",350 "depth": 2,351 "as_list": False,352 "with_lists": None,353 "ignore_null": False,354 },355 ],356 [357 None,358 {359 "query": "SELECT blah5",360 "depth": 0,361 "as_list": False,362 "with_lists": None,363 "ignore_null": False,364 },365 ],366 [367 None,368 {369 "query": "SELECT blah6",370 "depth": 0,371 "as_list": False,372 "with_lists": None,373 "ignore_null": False,374 },375 ],376 [377 None,378 {379 "query": "SELECT blah7",380 "depth": 2,381 "as_list": False,382 "with_lists": None,383 "ignore_null": False,384 },385 ],386 [387 None,388 {389 "query": "SELECT blah8",390 "depth": 0,391 "as_list": True,392 "with_lists": None,393 "ignore_null": False,394 },395 ],396 ],397 qbuffer,398 )399 def test_005_extract_queries_bogus_kwargs(self):400 # this test is cut down as most of the path matches test_*_bogus_list401 return_data = sqlite3.SQLite3ExtPillar()402 args, kwargs = [], {"1": "SELECT blah", "2": "", "3": "SELECT blah2"}403 qbuffer = return_data.extract_queries(args, kwargs)404 self.assertEqual(405 [406 [407 "1",408 {409 "query": "SELECT blah",410 "depth": 0,411 "as_list": False,412 "with_lists": None,413 "ignore_null": False,414 },415 ],416 [417 "3",418 {419 "query": "SELECT blah2",420 "depth": 0,421 "as_list": False,422 "with_lists": None,423 "ignore_null": False,424 },425 ],426 ],427 qbuffer,428 )429 def test_011_enter_root(self):430 return_data = sqlite3.SQLite3ExtPillar()431 return_data.enter_root("test")432 self.assertEqual(return_data.result["test"], return_data.focus)433 return_data.enter_root(None)434 self.assertEqual(return_data.result, return_data.focus)435 def test_021_process_fields(self):436 return_data = sqlite3.SQLite3ExtPillar()437 return_data.process_fields(["a", "b"], 0)438 self.assertEqual(return_data.num_fields, 2)439 self.assertEqual(return_data.depth, 1)440 return_data.process_fields(["a", "b"], 2)441 self.assertEqual(return_data.num_fields, 2)442 self.assertEqual(return_data.depth, 1)443 return_data.process_fields(["a", "b", "c", "d"], 0)444 self.assertEqual(return_data.num_fields, 4)445 self.assertEqual(return_data.depth, 3)446 return_data.process_fields(["a", "b", "c", "d"], 1)447 self.assertEqual(return_data.num_fields, 4)448 self.assertEqual(return_data.depth, 1)449 return_data.process_fields(["a", "b", "c", "d"], 2)450 self.assertEqual(return_data.num_fields, 4)451 self.assertEqual(return_data.depth, 2)452 return_data.process_fields(["a", "b", "c", "d"], 3)453 self.assertEqual(return_data.num_fields, 4)454 self.assertEqual(return_data.depth, 3)455 return_data.process_fields(["a", "b", "c", "d"], 4)456 self.assertEqual(return_data.num_fields, 4)457 self.assertEqual(return_data.depth, 3)458 def test_111_process_results_legacy(self):459 return_data = sqlite3.SQLite3ExtPillar()460 return_data.process_fields(["a", "b"], 0)461 return_data.with_lists = []462 return_data.process_results([[1, 2]])463 self.assertEqual({1: 2}, return_data.result)464 def test_112_process_results_legacy_multiple(self):465 return_data = sqlite3.SQLite3ExtPillar()466 return_data.process_fields(["a", "b"], 0)467 return_data.with_lists = []468 return_data.process_results([[1, 2], [3, 4], [5, 6]])469 self.assertEqual({1: 2, 3: 4, 5: 6}, return_data.result)470 def test_121_process_results_depth_0(self):471 return_data = sqlite3.SQLite3ExtPillar()472 return_data.process_fields(["a", "b", "c", "d"], 0)473 return_data.with_lists = []474 return_data.enter_root(None)475 return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])476 self.assertEqual({1: {2: {3: 4}}, 5: {6: {7: 8}}}, return_data.result)477 def test_122_process_results_depth_1(self):478 return_data = sqlite3.SQLite3ExtPillar()479 return_data.process_fields(["a", "b", "c", "d"], 1)480 return_data.with_lists = []481 return_data.enter_root(None)482 return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])483 self.assertEqual(484 {1: {"b": 2, "c": 3, "d": 4}, 5: {"b": 6, "c": 7, "d": 8}},485 return_data.result,486 )487 def test_123_process_results_depth_2(self):488 return_data = sqlite3.SQLite3ExtPillar()489 return_data.process_fields(["a", "b", "c", "d"], 2)490 return_data.with_lists = []491 return_data.enter_root(None)492 return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])493 self.assertEqual(494 {1: {2: {"c": 3, "d": 4}}, 5: {6: {"c": 7, "d": 8}}}, return_data.result495 )496 def test_124_process_results_depth_3(self):497 return_data = sqlite3.SQLite3ExtPillar()498 return_data.process_fields(["a", "b", "c", "d"], 3)499 return_data.with_lists = []500 return_data.enter_root(None)501 return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])502 self.assertEqual({1: {2: {3: 4}}, 5: {6: {7: 8}}}, return_data.result)503 def test_125_process_results_depth_4(self):504 return_data = sqlite3.SQLite3ExtPillar()505 return_data.process_fields(["a", "b", "c", "d"], 4)506 return_data.with_lists = []507 return_data.enter_root(None)508 return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])509 self.assertEqual({1: {2: {3: 4}}, 5: {6: {7: 8}}}, return_data.result)510 def test_131_process_results_overwrite_legacy_multiple(self):511 return_data = sqlite3.SQLite3ExtPillar()512 return_data.process_fields(["a", "b"], 0)513 return_data.with_lists = []514 return_data.process_results([[1, 2], [3, 4], [1, 6]])515 self.assertEqual({1: 6, 3: 4}, return_data.result)516 def test_132_process_results_merge_depth_0(self):517 return_data = sqlite3.SQLite3ExtPillar()518 return_data.process_fields(["a", "b", "c", "d"], 0)519 return_data.with_lists = []520 return_data.enter_root(None)521 return_data.process_results([[1, 2, 3, 4], [1, 6, 7, 8]])522 self.assertEqual({1: {2: {3: 4}, 6: {7: 8}}}, return_data.result)523 def test_133_process_results_overwrite_depth_0(self):524 return_data = sqlite3.SQLite3ExtPillar()525 return_data.process_fields(["a", "b", "c", "d"], 0)526 return_data.with_lists = []527 return_data.enter_root(None)528 return_data.process_results([[1, 2, 3, 4], [1, 2, 3, 8]])529 self.assertEqual({1: {2: {3: 8}}}, return_data.result)530 def test_134_process_results_deepmerge_depth_0(self):531 return_data = sqlite3.SQLite3ExtPillar()532 return_data.process_fields(["a", "b", "c", "d"], 0)533 return_data.with_lists = []534 return_data.enter_root(None)535 return_data.process_results([[1, 2, 3, 4], [1, 2, 7, 8]])536 self.assertEqual({1: {2: {3: 4, 7: 8}}}, return_data.result)537 def test_135_process_results_overwrite_depth_1(self):538 return_data = sqlite3.SQLite3ExtPillar()539 return_data.process_fields(["a", "b", "c", "d"], 1)540 return_data.with_lists = []541 return_data.enter_root(None)542 return_data.process_results([[1, 2, 3, 4], [1, 6, 7, 8]])543 self.assertEqual({1: {"b": 6, "c": 7, "d": 8}}, return_data.result)544 def test_136_process_results_merge_depth_2(self):545 return_data = sqlite3.SQLite3ExtPillar()546 return_data.process_fields(["a", "b", "c", "d"], 2)547 return_data.with_lists = []548 return_data.enter_root(None)549 return_data.process_results([[1, 2, 3, 4], [1, 6, 7, 8]])550 self.assertEqual(551 {1: {2: {"c": 3, "d": 4}, 6: {"c": 7, "d": 8}}}, return_data.result552 )553 def test_137_process_results_overwrite_depth_2(self):554 return_data = sqlite3.SQLite3ExtPillar()555 return_data.process_fields(["a", "b", "c", "d"], 2)556 return_data.with_lists = []557 return_data.enter_root(None)558 return_data.process_results([[1, 2, 3, 4], [1, 2, 7, 8]])559 self.assertEqual({1: {2: {"c": 7, "d": 8}}}, return_data.result)560 def test_201_process_results_complexity_multiresults(self):561 return_data = sqlite3.SQLite3ExtPillar()562 return_data.process_fields(["a", "b", "c", "d"], 2)563 return_data.with_lists = []564 return_data.enter_root(None)565 return_data.process_results([[1, 2, 3, 4]])566 return_data.process_results([[1, 2, 7, 8]])567 self.assertEqual({1: {2: {"c": 7, "d": 8}}}, return_data.result)568 def test_202_process_results_complexity_as_list(self):569 return_data = sqlite3.SQLite3ExtPillar()570 return_data.process_fields(["a", "b", "c", "d"], 2)571 return_data.with_lists = []572 return_data.enter_root(None)573 return_data.as_list = True574 return_data.process_results([[1, 2, 3, 4]])575 return_data.process_results([[1, 2, 7, 8]])576 self.assertEqual({1: {2: {"c": [3, 7], "d": [4, 8]}}}, return_data.result)577 def test_203_process_results_complexity_as_list_deeper(self):578 return_data = sqlite3.SQLite3ExtPillar()579 return_data.process_fields(["a", "b", "c", "d"], 0)580 return_data.with_lists = []581 return_data.enter_root(None)582 return_data.as_list = True583 return_data.process_results([[1, 2, 3, 4]])584 return_data.process_results([[1, 2, 3, 8]])585 self.assertEqual({1: {2: {3: [4, 8]}}}, return_data.result)586 def test_204_process_results_complexity_as_list_mismatch_depth(self):587 return_data = sqlite3.SQLite3ExtPillar()588 return_data.as_list = True589 return_data.with_lists = []590 return_data.enter_root(None)591 return_data.process_fields(["a", "b", "c", "d"], 0)592 return_data.process_results([[1, 2, 3, 4]])593 return_data.process_results([[1, 2, 3, 5]])594 return_data.process_fields(["a", "b", "c", "d", "e"], 0)595 return_data.process_results([[1, 2, 3, 6, 7]])596 self.assertEqual({1: {2: {3: [4, 5, {6: 7}]}}}, return_data.result)597 def test_205_process_results_complexity_as_list_mismatch_depth_reversed(self):598 return_data = sqlite3.SQLite3ExtPillar()599 return_data.as_list = True600 return_data.with_lists = []601 return_data.enter_root(None)602 return_data.process_fields(["a", "b", "c", "d", "e"], 0)603 return_data.process_results([[1, 2, 3, 6, 7]])604 return_data.process_results([[1, 2, 3, 8, 9]])605 return_data.process_fields(["a", "b", "c", "d"], 0)606 return_data.process_results([[1, 2, 3, 4]])607 return_data.process_results([[1, 2, 3, 5]])608 self.assertEqual({1: {2: {3: [{6: 7, 8: 9}, 4, 5]}}}, return_data.result)609 def test_206_process_results_complexity_as_list_mismatch_depth_weird_order(self):610 return_data = sqlite3.SQLite3ExtPillar()611 return_data.as_list = True612 return_data.with_lists = []613 return_data.enter_root(None)614 return_data.process_fields(["a", "b", "c", "d", "e"], 0)615 return_data.process_results([[1, 2, 3, 6, 7]])616 return_data.process_fields(["a", "b", "c", "d"], 0)617 return_data.process_results([[1, 2, 3, 4]])618 return_data.process_fields(["a", "b", "c", "d", "e"], 0)619 return_data.process_results([[1, 2, 3, 8, 9]])620 return_data.process_fields(["a", "b", "c", "d"], 0)621 return_data.process_results([[1, 2, 3, 5]])622 self.assertEqual({1: {2: {3: [{6: 7}, 4, {8: 9}, 5]}}}, return_data.result)623 def test_207_process_results_complexity_collision_mismatch_depth(self):624 return_data = sqlite3.SQLite3ExtPillar()625 return_data.as_list = False626 return_data.with_lists = []627 return_data.enter_root(None)628 return_data.process_fields(["a", "b", "c", "d"], 0)629 return_data.process_results([[1, 2, 3, 4]])630 return_data.process_results([[1, 2, 3, 5]])631 return_data.process_fields(["a", "b", "c", "d", "e"], 0)632 return_data.process_results([[1, 2, 3, 6, 7]])633 self.assertEqual({1: {2: {3: {6: 7}}}}, return_data.result)634 def test_208_process_results_complexity_collision_mismatch_depth_reversed(self):635 return_data = sqlite3.SQLite3ExtPillar()636 return_data.as_list = False637 return_data.with_lists = []638 return_data.enter_root(None)639 return_data.process_fields(["a", "b", "c", "d", "e"], 0)640 return_data.process_results([[1, 2, 3, 6, 7]])641 return_data.process_results([[1, 2, 3, 8, 9]])642 return_data.process_fields(["a", "b", "c", "d"], 0)643 return_data.process_results([[1, 2, 3, 4]])644 return_data.process_results([[1, 2, 3, 5]])645 self.assertEqual({1: {2: {3: 5}}}, return_data.result)646 def test_209_process_results_complexity_collision_mismatch_depth_weird_order(self):647 return_data = sqlite3.SQLite3ExtPillar()648 return_data.as_list = False649 return_data.with_lists = []650 return_data.enter_root(None)651 return_data.process_fields(["a", "b", "c", "d", "e"], 0)652 return_data.process_results([[1, 2, 3, 6, 7]])653 return_data.process_fields(["a", "b", "c", "d"], 0)654 return_data.process_results([[1, 2, 3, 4]])655 return_data.process_fields(["a", "b", "c", "d", "e"], 0)656 return_data.process_results([[1, 2, 3, 8, 9]])657 return_data.process_fields(["a", "b", "c", "d"], 0)658 return_data.process_results([[1, 2, 3, 5]])659 self.assertEqual({1: {2: {3: 5}}}, return_data.result)660 def test_20A_process_results_complexity_as_list_vary(self):661 return_data = sqlite3.SQLite3ExtPillar()662 return_data.as_list = True663 return_data.with_lists = []664 return_data.enter_root(None)665 return_data.process_fields(["a", "b", "c", "d", "e"], 0)666 return_data.process_results([[1, 2, 3, 6, 7]])667 return_data.process_results([[1, 2, 3, 8, 9]])668 return_data.process_fields(["a", "b", "c", "d"], 0)669 return_data.process_results([[1, 2, 3, 4]])670 return_data.as_list = False671 return_data.process_results([[1, 2, 3, 5]])672 self.assertEqual({1: {2: {3: 5}}}, return_data.result)673 def test_207_process_results_complexity_roots_collision(self):674 return_data = sqlite3.SQLite3ExtPillar()675 return_data.as_list = False676 return_data.with_lists = []677 return_data.enter_root(None)678 return_data.process_fields(["a", "b", "c", "d"], 0)679 return_data.process_results([[1, 2, 3, 4]])680 return_data.enter_root(1)681 return_data.process_results([[5, 6, 7, 8]])682 self.assertEqual({1: {5: {6: {7: 8}}}}, return_data.result)683 def test_301_process_results_with_lists(self):684 return_data = sqlite3.SQLite3ExtPillar()685 return_data.as_list = False686 return_data.with_lists = [1, 3]687 return_data.enter_root(None)688 return_data.process_fields(["a", "b", "c", "d", "e", "v"], 0)689 return_data.process_results(690 [691 ["a", "b", "c", "d", "e", 1],692 ["a", "b", "c", "f", "g", 2],693 ["a", "z", "h", "y", "j", 3],694 ["a", "z", "h", "y", "k", 4],695 ]696 )697 self.assertEqual(698 sorted({"a": [{"c": [{"e": 1}, {"g": 2}]}, {"h": [{"j": 3, "k": 4}]}]}),699 sorted(return_data.result),700 )701 def test_302_process_results_with_lists_consecutive(self):702 return_data = sqlite3.SQLite3ExtPillar()703 return_data.as_list = False704 return_data.with_lists = [1, 2, 3]705 return_data.enter_root(None)706 return_data.process_fields(["a", "b", "c", "d", "e", "v"], 0)707 return_data.process_results(708 [709 ["a", "b", "c", "d", "e", 1],710 ["a", "b", "c", "f", "g", 2],711 ["a", "z", "h", "y", "j", 3],712 ["a", "z", "h", "y", "k", 4],713 ]714 )715 self.assertEqual(716 sorted({"a": [[[{"e": 1}, {"g": 2}]], [[{"j": 3, "k": 4}]]]}),717 sorted(return_data.result),...
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!!