test_mysql.py 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. # Import Salt Libs
  5. import salt.pillar.mysql as mysql
  6. # Import Salt Testing libs
  7. from tests.support.unit import TestCase, skipIf
  8. @skipIf(mysql.MySQLdb is None, "MySQL-python module not installed")
  9. class MysqlPillarTestCase(TestCase):
  10. maxDiff = None
  11. 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 dropped
  314. 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_list
  421. 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.result
  515. )
  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.result
  572. )
  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 = True
  594. 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 = True
  603. 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 = True
  609. 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 = True
  620. 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 = True
  632. 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 = False
  646. 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 = False
  657. 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 = False
  669. 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 = True
  683. 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 = False
  691. 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 = False
  696. 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 = False
  720. 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.result
  732. 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"] == 1
  739. elif "g" in y:
  740. assert list(y.keys()) == ["g"]
  741. assert y["g"] == 2
  742. else:
  743. raise ValueError("Unexpected value {0}".format(y))
  744. elif "h" in x:
  745. assert len(x["h"]) == 1
  746. for y in x["h"]:
  747. if "j" in y:
  748. assert len(y.keys()) == 2
  749. assert y["j"] == 3
  750. elif "h" in y:
  751. assert len(y.keys()) == 2
  752. assert y["k"] == 4
  753. 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 = False
  774. 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.result
  786. for x in return_data.result["a"]:
  787. assert len(x) == 1
  788. 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"] == 1
  793. elif "g" in y:
  794. assert list(y.keys()) == ["g"]
  795. assert y["g"] == 2
  796. 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()) == 2
  802. assert y["j"] == 3
  803. elif "k" in y:
  804. assert len(y.keys()) == 2
  805. assert y["k"] == 4
  806. else:
  807. raise ValueError("Unexpected value {0}".format(len(x[0][0])))
  808. else:
  809. raise ValueError("Unexpected value {0}".format(x))