1
0

test_mysql.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. # Import Salt Testing libs
  5. from tests.support.unit import TestCase, skipIf
  6. from tests.support.mock import NO_MOCK, NO_MOCK_REASON
  7. # Import Salt Libs
  8. import salt.pillar.mysql as mysql
  9. @skipIf(NO_MOCK, NO_MOCK_REASON)
  10. @skipIf(mysql.MySQLdb is None, 'MySQL-python module not installed')
  11. class MysqlPillarTestCase(TestCase):
  12. maxDiff = None
  13. def test_001_extract_queries_legacy(self):
  14. return_data = mysql.MySQLExtPillar()
  15. args, kwargs = ['SELECT blah'], {}
  16. qbuffer = return_data.extract_queries(args, kwargs)
  17. self.assertEqual([
  18. [None, {'query': 'SELECT blah', 'depth': 0, 'as_list': False,
  19. 'with_lists': None, 'ignore_null': False}]
  20. ], qbuffer)
  21. def test_002_extract_queries_list(self):
  22. return_data = mysql.MySQLExtPillar()
  23. args, kwargs = [
  24. 'SELECT blah',
  25. 'SELECT blah2',
  26. ('SELECT blah3',),
  27. ('SELECT blah4', 2),
  28. {'query': 'SELECT blah5'},
  29. {'query': 'SELECT blah6', 'depth': 2},
  30. {'query': 'SELECT blah7', 'as_list': True},
  31. {'query': 'SELECT blah8', 'with_lists': '1'},
  32. {'query': 'SELECT blah9', 'with_lists': '1,2'}
  33. ], {}
  34. qbuffer = return_data.extract_queries(args, kwargs)
  35. self.assertEqual([
  36. [None, {'query': 'SELECT blah', 'depth': 0, 'as_list': False,
  37. 'with_lists': None, 'ignore_null': False}],
  38. [None, {'query': 'SELECT blah2', 'depth': 0, 'as_list': False,
  39. 'with_lists': None, 'ignore_null': False}],
  40. [None, {'query': 'SELECT blah3', 'depth': 0, 'as_list': False,
  41. 'with_lists': None, 'ignore_null': False}],
  42. [None, {'query': 'SELECT blah4', 'depth': 2, 'as_list': False,
  43. 'with_lists': None, 'ignore_null': False}],
  44. [None, {'query': 'SELECT blah5', 'depth': 0, 'as_list': False,
  45. 'with_lists': None, 'ignore_null': False}],
  46. [None, {'query': 'SELECT blah6', 'depth': 2, 'as_list': False,
  47. 'with_lists': None, 'ignore_null': False}],
  48. [None, {'query': 'SELECT blah7', 'depth': 0, 'as_list': True,
  49. 'with_lists': None, 'ignore_null': False}],
  50. [None, {'query': 'SELECT blah8', 'depth': 0, 'as_list': False,
  51. 'with_lists': [1], 'ignore_null': False}],
  52. [None, {'query': 'SELECT blah9', 'depth': 0, 'as_list': False,
  53. 'with_lists': [1, 2], 'ignore_null': False}]
  54. ], qbuffer)
  55. def test_003_extract_queries_kwarg(self):
  56. return_data = mysql.MySQLExtPillar()
  57. args, kwargs = [], {
  58. '1': 'SELECT blah',
  59. '2': 'SELECT blah2',
  60. '3': ('SELECT blah3',),
  61. '4': ('SELECT blah4', 2),
  62. '5': {'query': 'SELECT blah5'},
  63. '6': {'query': 'SELECT blah6', 'depth': 2},
  64. '7': {'query': 'SELECT blah7', 'as_list': True},
  65. }
  66. qbuffer = return_data.extract_queries(args, kwargs)
  67. self.assertEqual([
  68. ['1', {'query': 'SELECT blah', 'depth': 0, 'as_list': False,
  69. 'with_lists': None, 'ignore_null': False}],
  70. ['2', {'query': 'SELECT blah2', 'depth': 0, 'as_list': False,
  71. 'with_lists': None, 'ignore_null': False}],
  72. ['3', {'query': 'SELECT blah3', 'depth': 0, 'as_list': False,
  73. 'with_lists': None, 'ignore_null': False}],
  74. ['4', {'query': 'SELECT blah4', 'depth': 2, 'as_list': False,
  75. 'with_lists': None, 'ignore_null': False}],
  76. ['5', {'query': 'SELECT blah5', 'depth': 0, 'as_list': False,
  77. 'with_lists': None, 'ignore_null': False}],
  78. ['6', {'query': 'SELECT blah6', 'depth': 2, 'as_list': False,
  79. 'with_lists': None, 'ignore_null': False}],
  80. ['7', {'query': 'SELECT blah7', 'depth': 0, 'as_list': True,
  81. 'with_lists': None, 'ignore_null': False}]
  82. ], qbuffer)
  83. def test_004_extract_queries_mixed(self):
  84. return_data = mysql.MySQLExtPillar()
  85. args, kwargs = [
  86. 'SELECT blah1',
  87. ('SELECT blah2', 2),
  88. {'query': 'SELECT blah3', 'as_list': True},
  89. ], {
  90. '1': 'SELECT blah1',
  91. '2': ('SELECT blah2', 2),
  92. '3': {'query': 'SELECT blah3', 'as_list': True},
  93. }
  94. qbuffer = return_data.extract_queries(args, kwargs)
  95. self.assertEqual([
  96. [None, {'query': 'SELECT blah1', 'depth': 0, 'as_list': False,
  97. 'with_lists': None, 'ignore_null': False}],
  98. [None, {'query': 'SELECT blah2', 'depth': 2, 'as_list': False,
  99. 'with_lists': None, 'ignore_null': False}],
  100. [None, {'query': 'SELECT blah3', 'depth': 0, 'as_list': True,
  101. 'with_lists': None, 'ignore_null': False}],
  102. ['1', {'query': 'SELECT blah1', 'depth': 0, 'as_list': False,
  103. 'with_lists': None, 'ignore_null': False}],
  104. ['2', {'query': 'SELECT blah2', 'depth': 2, 'as_list': False,
  105. 'with_lists': None, 'ignore_null': False}],
  106. ['3', {'query': 'SELECT blah3', 'depth': 0, 'as_list': True,
  107. 'with_lists': None, 'ignore_null': False}]
  108. ], qbuffer)
  109. def test_005_extract_queries_bogus_list(self):
  110. # This test is specifically checking that empty queries are dropped
  111. return_data = mysql.MySQLExtPillar()
  112. args, kwargs = [
  113. 'SELECT blah',
  114. '',
  115. 'SELECT blah2',
  116. ('SELECT blah3',),
  117. ('',),
  118. ('SELECT blah4', 2),
  119. tuple(),
  120. ('SELECT blah5',),
  121. {'query': 'SELECT blah6'},
  122. {'query': ''},
  123. {'query': 'SELECT blah7', 'depth': 2},
  124. {'not_a_query': 'in sight!'},
  125. {'query': 'SELECT blah8', 'as_list': True},
  126. ], {}
  127. qbuffer = return_data.extract_queries(args, kwargs)
  128. self.assertEqual([
  129. [None, {'query': 'SELECT blah', 'depth': 0, 'as_list': False,
  130. 'with_lists': None, 'ignore_null': False}],
  131. [None, {'query': 'SELECT blah2', 'depth': 0, 'as_list': False,
  132. 'with_lists': None, 'ignore_null': False}],
  133. [None, {'query': 'SELECT blah3', 'depth': 0, 'as_list': False,
  134. 'with_lists': None, 'ignore_null': False}],
  135. [None, {'query': 'SELECT blah4', 'depth': 2, 'as_list': False,
  136. 'with_lists': None, 'ignore_null': False}],
  137. [None, {'query': 'SELECT blah5', 'depth': 0, 'as_list': False,
  138. 'with_lists': None, 'ignore_null': False}],
  139. [None, {'query': 'SELECT blah6', 'depth': 0, 'as_list': False,
  140. 'with_lists': None, 'ignore_null': False}],
  141. [None, {'query': 'SELECT blah7', 'depth': 2, 'as_list': False,
  142. 'with_lists': None, 'ignore_null': False}],
  143. [None, {'query': 'SELECT blah8', 'depth': 0, 'as_list': True,
  144. 'with_lists': None, 'ignore_null': False}]
  145. ], qbuffer)
  146. def test_006_extract_queries_bogus_kwargs(self):
  147. # this test is cut down as most of the path matches test_*_bogus_list
  148. return_data = mysql.MySQLExtPillar()
  149. args, kwargs = [], {
  150. '1': 'SELECT blah',
  151. '2': '',
  152. '3': 'SELECT blah2'
  153. }
  154. qbuffer = return_data.extract_queries(args, kwargs)
  155. self.assertEqual([
  156. ['1', {'query': 'SELECT blah', 'depth': 0, 'as_list': False,
  157. 'with_lists': None, 'ignore_null': False}],
  158. ['3', {'query': 'SELECT blah2', 'depth': 0, 'as_list': False,
  159. 'with_lists': None, 'ignore_null': False}]
  160. ], qbuffer)
  161. def test_011_enter_root(self):
  162. return_data = mysql.MySQLExtPillar()
  163. return_data.enter_root("test")
  164. self.assertEqual(return_data.result["test"], return_data.focus)
  165. return_data.enter_root(None)
  166. self.assertEqual(return_data.result, return_data.focus)
  167. def test_021_process_fields(self):
  168. return_data = mysql.MySQLExtPillar()
  169. return_data.process_fields(['a', 'b'], 0)
  170. self.assertEqual(return_data.num_fields, 2)
  171. self.assertEqual(return_data.depth, 1)
  172. return_data.process_fields(['a', 'b'], 2)
  173. self.assertEqual(return_data.num_fields, 2)
  174. self.assertEqual(return_data.depth, 1)
  175. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  176. self.assertEqual(return_data.num_fields, 4)
  177. self.assertEqual(return_data.depth, 3)
  178. return_data.process_fields(['a', 'b', 'c', 'd'], 1)
  179. self.assertEqual(return_data.num_fields, 4)
  180. self.assertEqual(return_data.depth, 1)
  181. return_data.process_fields(['a', 'b', 'c', 'd'], 2)
  182. self.assertEqual(return_data.num_fields, 4)
  183. self.assertEqual(return_data.depth, 2)
  184. return_data.process_fields(['a', 'b', 'c', 'd'], 3)
  185. self.assertEqual(return_data.num_fields, 4)
  186. self.assertEqual(return_data.depth, 3)
  187. return_data.process_fields(['a', 'b', 'c', 'd'], 4)
  188. self.assertEqual(return_data.num_fields, 4)
  189. self.assertEqual(return_data.depth, 3)
  190. def test_111_process_results_legacy(self):
  191. return_data = mysql.MySQLExtPillar()
  192. return_data.process_fields(['a', 'b'], 0)
  193. return_data.with_lists = []
  194. return_data.process_results([[1, 2]])
  195. self.assertEqual(
  196. {1: 2},
  197. return_data.result
  198. )
  199. def test_112_process_results_legacy_multiple(self):
  200. return_data = mysql.MySQLExtPillar()
  201. return_data.process_fields(['a', 'b'], 0)
  202. return_data.with_lists = []
  203. return_data.process_results([[1, 2], [3, 4], [5, 6]])
  204. self.assertEqual(
  205. {1: 2, 3: 4, 5: 6},
  206. return_data.result
  207. )
  208. def test_121_process_results_depth_0(self):
  209. return_data = mysql.MySQLExtPillar()
  210. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  211. return_data.with_lists = []
  212. return_data.enter_root(None)
  213. return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])
  214. self.assertEqual(
  215. {1: {2: {3: 4}}, 5: {6: {7: 8}}},
  216. return_data.result
  217. )
  218. def test_122_process_results_depth_1(self):
  219. return_data = mysql.MySQLExtPillar()
  220. return_data.process_fields(['a', 'b', 'c', 'd'], 1)
  221. return_data.with_lists = []
  222. return_data.enter_root(None)
  223. return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])
  224. self.assertEqual(
  225. {1: {'b': 2, 'c': 3, 'd': 4}, 5: {'b': 6, 'c': 7, 'd': 8}},
  226. return_data.result
  227. )
  228. def test_123_process_results_depth_2(self):
  229. return_data = mysql.MySQLExtPillar()
  230. return_data.process_fields(['a', 'b', 'c', 'd'], 2)
  231. return_data.with_lists = []
  232. return_data.enter_root(None)
  233. return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])
  234. self.assertEqual(
  235. {1: {2: {'c': 3, 'd': 4}}, 5: {6: {'c': 7, 'd': 8}}},
  236. return_data.result
  237. )
  238. def test_124_process_results_depth_3(self):
  239. return_data = mysql.MySQLExtPillar()
  240. return_data.process_fields(['a', 'b', 'c', 'd'], 3)
  241. return_data.with_lists = []
  242. return_data.enter_root(None)
  243. return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])
  244. self.assertEqual(
  245. {1: {2: {3: 4}}, 5: {6: {7: 8}}},
  246. return_data.result
  247. )
  248. def test_125_process_results_depth_4(self):
  249. return_data = mysql.MySQLExtPillar()
  250. return_data.process_fields(['a', 'b', 'c', 'd'], 4)
  251. return_data.with_lists = []
  252. return_data.enter_root(None)
  253. return_data.process_results([[1, 2, 3, 4], [5, 6, 7, 8]])
  254. self.assertEqual(
  255. {1: {2: {3: 4}}, 5: {6: {7: 8}}},
  256. return_data.result
  257. )
  258. def test_131_process_results_overwrite_legacy_multiple(self):
  259. return_data = mysql.MySQLExtPillar()
  260. return_data.process_fields(['a', 'b'], 0)
  261. return_data.with_lists = []
  262. return_data.process_results([[1, 2], [3, 4], [1, 6]])
  263. self.assertEqual(
  264. {1: 6, 3: 4},
  265. return_data.result
  266. )
  267. def test_132_process_results_merge_depth_0(self):
  268. return_data = mysql.MySQLExtPillar()
  269. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  270. return_data.with_lists = []
  271. return_data.enter_root(None)
  272. return_data.process_results([[1, 2, 3, 4], [1, 6, 7, 8]])
  273. self.assertEqual(
  274. {1: {2: {3: 4}, 6: {7: 8}}},
  275. return_data.result
  276. )
  277. def test_133_process_results_overwrite_depth_0(self):
  278. return_data = mysql.MySQLExtPillar()
  279. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  280. return_data.with_lists = []
  281. return_data.enter_root(None)
  282. return_data.process_results([[1, 2, 3, 4], [1, 2, 3, 8]])
  283. self.assertEqual(
  284. {1: {2: {3: 8}}},
  285. return_data.result
  286. )
  287. def test_134_process_results_deepmerge_depth_0(self):
  288. return_data = mysql.MySQLExtPillar()
  289. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  290. return_data.with_lists = []
  291. return_data.enter_root(None)
  292. return_data.process_results([[1, 2, 3, 4], [1, 2, 7, 8]])
  293. self.assertEqual(
  294. {1: {2: {3: 4, 7: 8}}},
  295. return_data.result
  296. )
  297. def test_135_process_results_overwrite_depth_1(self):
  298. return_data = mysql.MySQLExtPillar()
  299. return_data.process_fields(['a', 'b', 'c', 'd'], 1)
  300. return_data.with_lists = []
  301. return_data.enter_root(None)
  302. return_data.process_results([[1, 2, 3, 4], [1, 6, 7, 8]])
  303. self.assertEqual(
  304. {1: {'b': 6, 'c': 7, 'd': 8}},
  305. return_data.result
  306. )
  307. def test_136_process_results_merge_depth_2(self):
  308. return_data = mysql.MySQLExtPillar()
  309. return_data.process_fields(['a', 'b', 'c', 'd'], 2)
  310. return_data.with_lists = []
  311. return_data.enter_root(None)
  312. return_data.process_results([[1, 2, 3, 4], [1, 6, 7, 8]])
  313. self.assertEqual(
  314. {1: {2: {'c': 3, 'd': 4}, 6: {'c': 7, 'd': 8}}},
  315. return_data.result
  316. )
  317. def test_137_process_results_overwrite_depth_2(self):
  318. return_data = mysql.MySQLExtPillar()
  319. return_data.process_fields(['a', 'b', 'c', 'd'], 2)
  320. return_data.with_lists = []
  321. return_data.enter_root(None)
  322. return_data.process_results([[1, 2, 3, 4], [1, 2, 7, 8]])
  323. self.assertEqual(
  324. {1: {2: {'c': 7, 'd': 8}}},
  325. return_data.result
  326. )
  327. def test_201_process_results_complexity_multiresults(self):
  328. return_data = mysql.MySQLExtPillar()
  329. return_data.process_fields(['a', 'b', 'c', 'd'], 2)
  330. return_data.with_lists = []
  331. return_data.enter_root(None)
  332. return_data.process_results([[1, 2, 3, 4]])
  333. return_data.process_results([[1, 2, 7, 8]])
  334. self.assertEqual(
  335. {1: {2: {'c': 7, 'd': 8}}},
  336. return_data.result
  337. )
  338. def test_202_process_results_complexity_as_list(self):
  339. return_data = mysql.MySQLExtPillar()
  340. return_data.process_fields(['a', 'b', 'c', 'd'], 2)
  341. return_data.with_lists = []
  342. return_data.enter_root(None)
  343. return_data.as_list = True
  344. return_data.process_results([[1, 2, 3, 4]])
  345. return_data.process_results([[1, 2, 7, 8]])
  346. self.assertEqual(
  347. {1: {2: {'c': [3, 7], 'd': [4, 8]}}},
  348. return_data.result
  349. )
  350. def test_203_process_results_complexity_as_list_deeper(self):
  351. return_data = mysql.MySQLExtPillar()
  352. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  353. return_data.with_lists = []
  354. return_data.enter_root(None)
  355. return_data.as_list = True
  356. return_data.process_results([[1, 2, 3, 4]])
  357. return_data.process_results([[1, 2, 3, 8]])
  358. self.assertEqual(
  359. {1: {2: {3: [4, 8]}}},
  360. return_data.result
  361. )
  362. def test_204_process_results_complexity_as_list_mismatch_depth(self):
  363. return_data = mysql.MySQLExtPillar()
  364. return_data.as_list = True
  365. return_data.with_lists = []
  366. return_data.enter_root(None)
  367. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  368. return_data.process_results([[1, 2, 3, 4]])
  369. return_data.process_results([[1, 2, 3, 5]])
  370. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  371. return_data.process_results([[1, 2, 3, 6, 7]])
  372. self.assertEqual(
  373. {1: {2: {3: [4, 5, {6: 7}]}}},
  374. return_data.result
  375. )
  376. def test_205_process_results_complexity_as_list_mismatch_depth_reversed(self):
  377. return_data = mysql.MySQLExtPillar()
  378. return_data.as_list = True
  379. return_data.with_lists = []
  380. return_data.enter_root(None)
  381. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  382. return_data.process_results([[1, 2, 3, 6, 7]])
  383. return_data.process_results([[1, 2, 3, 8, 9]])
  384. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  385. return_data.process_results([[1, 2, 3, 4]])
  386. return_data.process_results([[1, 2, 3, 5]])
  387. self.assertEqual(
  388. {1: {2: {3: [{6: 7, 8: 9}, 4, 5]}}},
  389. return_data.result
  390. )
  391. def test_206_process_results_complexity_as_list_mismatch_depth_weird_order(self):
  392. return_data = mysql.MySQLExtPillar()
  393. return_data.as_list = True
  394. return_data.with_lists = []
  395. return_data.enter_root(None)
  396. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  397. return_data.process_results([[1, 2, 3, 6, 7]])
  398. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  399. return_data.process_results([[1, 2, 3, 4]])
  400. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  401. return_data.process_results([[1, 2, 3, 8, 9]])
  402. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  403. return_data.process_results([[1, 2, 3, 5]])
  404. self.assertEqual(
  405. {1: {2: {3: [{6: 7, }, 4, {8: 9}, 5]}}},
  406. return_data.result
  407. )
  408. def test_207_process_results_complexity_collision_mismatch_depth(self):
  409. return_data = mysql.MySQLExtPillar()
  410. return_data.as_list = False
  411. return_data.with_lists = []
  412. return_data.enter_root(None)
  413. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  414. return_data.process_results([[1, 2, 3, 4]])
  415. return_data.process_results([[1, 2, 3, 5]])
  416. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  417. return_data.process_results([[1, 2, 3, 6, 7]])
  418. self.assertEqual(
  419. {1: {2: {3: {6: 7}}}},
  420. return_data.result
  421. )
  422. def test_208_process_results_complexity_collision_mismatch_depth_reversed(self):
  423. return_data = mysql.MySQLExtPillar()
  424. return_data.as_list = False
  425. return_data.with_lists = []
  426. return_data.enter_root(None)
  427. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  428. return_data.process_results([[1, 2, 3, 6, 7]])
  429. return_data.process_results([[1, 2, 3, 8, 9]])
  430. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  431. return_data.process_results([[1, 2, 3, 4]])
  432. return_data.process_results([[1, 2, 3, 5]])
  433. self.assertEqual(
  434. {1: {2: {3: 5}}},
  435. return_data.result
  436. )
  437. def test_209_process_results_complexity_collision_mismatch_depth_weird_order(self):
  438. return_data = mysql.MySQLExtPillar()
  439. return_data.as_list = False
  440. return_data.with_lists = []
  441. return_data.enter_root(None)
  442. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  443. return_data.process_results([[1, 2, 3, 6, 7]])
  444. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  445. return_data.process_results([[1, 2, 3, 4]])
  446. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  447. return_data.process_results([[1, 2, 3, 8, 9]])
  448. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  449. return_data.process_results([[1, 2, 3, 5]])
  450. self.assertEqual(
  451. {1: {2: {3: 5}}},
  452. return_data.result
  453. )
  454. def test_20A_process_results_complexity_as_list_vary(self):
  455. return_data = mysql.MySQLExtPillar()
  456. return_data.as_list = True
  457. return_data.with_lists = []
  458. return_data.enter_root(None)
  459. return_data.process_fields(['a', 'b', 'c', 'd', 'e'], 0)
  460. return_data.process_results([[1, 2, 3, 6, 7]])
  461. return_data.process_results([[1, 2, 3, 8, 9]])
  462. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  463. return_data.process_results([[1, 2, 3, 4]])
  464. return_data.as_list = False
  465. return_data.process_results([[1, 2, 3, 5]])
  466. self.assertEqual(
  467. {1: {2: {3: 5}}},
  468. return_data.result
  469. )
  470. def test_207_process_results_complexity_roots_collision(self):
  471. return_data = mysql.MySQLExtPillar()
  472. return_data.as_list = False
  473. return_data.with_lists = []
  474. return_data.enter_root(None)
  475. return_data.process_fields(['a', 'b', 'c', 'd'], 0)
  476. return_data.process_results([[1, 2, 3, 4]])
  477. return_data.enter_root(1)
  478. return_data.process_results([[5, 6, 7, 8]])
  479. self.assertEqual(
  480. {1: {5: {6: {7: 8}}}},
  481. return_data.result
  482. )
  483. def test_301_process_results_with_lists(self):
  484. '''
  485. Validates the following results:
  486. {'a': [
  487. {'c': [
  488. {'e': 1},
  489. {'g': 2}
  490. ]
  491. },
  492. {'h': [
  493. {'j': 3, 'k': 4}
  494. ]
  495. }
  496. ]}
  497. '''
  498. return_data = mysql.MySQLExtPillar()
  499. return_data.as_list = False
  500. return_data.with_lists = [1, 3]
  501. return_data.enter_root(None)
  502. return_data.process_fields(['a', 'b', 'c', 'd', 'e', 'v'], 0)
  503. return_data.process_results([['a', 'b', 'c', 'd', 'e', 1],
  504. ['a', 'b', 'c', 'f', 'g', 2],
  505. ['a', 'z', 'h', 'y', 'j', 3],
  506. ['a', 'z', 'h', 'y', 'k', 4]])
  507. assert 'a' in return_data.result
  508. for x in return_data.result['a']:
  509. if 'c' in x:
  510. assert list(x.keys()) == ['c'], x.keys()
  511. for y in x['c']:
  512. if 'e' in y:
  513. assert list(y.keys()) == ['e']
  514. assert y['e'] == 1
  515. elif 'g' in y:
  516. assert list(y.keys()) == ['g']
  517. assert y['g'] == 2
  518. else:
  519. raise ValueError("Unexpected value {0}".format(y))
  520. elif 'h' in x:
  521. assert len(x['h']) == 1
  522. for y in x['h']:
  523. if 'j' in y:
  524. assert len(y.keys()) == 2
  525. assert y['j'] == 3
  526. elif 'h' in y:
  527. assert len(y.keys()) == 2
  528. assert y['k'] == 4
  529. else:
  530. raise ValueError("Unexpected value {0}".format(y))
  531. else:
  532. raise ValueError("Unexpected value {0}".format(x))
  533. def test_302_process_results_with_lists_consecutive(self):
  534. '''
  535. Validates the following results:
  536. {'a': [
  537. [[
  538. {'e': 1},
  539. {'g': 2}
  540. ]
  541. ],
  542. [[
  543. {'j': 3, 'k': 4}
  544. ]
  545. ]
  546. ]}
  547. '''
  548. return_data = mysql.MySQLExtPillar()
  549. return_data.as_list = False
  550. return_data.with_lists = [1, 2, 3]
  551. return_data.enter_root(None)
  552. return_data.process_fields(['a', 'b', 'c', 'd', 'e', 'v'], 0)
  553. return_data.process_results([['a', 'b', 'c', 'd', 'e', 1],
  554. ['a', 'b', 'c', 'f', 'g', 2],
  555. ['a', 'z', 'h', 'y', 'j', 3],
  556. ['a', 'z', 'h', 'y', 'k', 4]])
  557. assert 'a' in return_data.result
  558. for x in return_data.result['a']:
  559. assert len(x) == 1
  560. if len(x[0][0]) == 1:
  561. for y in x[0]:
  562. if 'e' in y:
  563. assert list(y.keys()) == ['e']
  564. assert y['e'] == 1
  565. elif 'g' in y:
  566. assert list(y.keys()) == ['g']
  567. assert y['g'] == 2
  568. else:
  569. raise ValueError("Unexpected value {0}".format(y))
  570. elif len(x[0][0]) == 2:
  571. for y in x[0]:
  572. if 'j' in y:
  573. assert len(y.keys()) == 2
  574. assert y['j'] == 3
  575. elif 'k' in y:
  576. assert len(y.keys()) == 2
  577. assert y['k'] == 4
  578. else:
  579. raise ValueError(
  580. "Unexpected value {0}".format(len(x[0][0]))
  581. )
  582. else:
  583. raise ValueError("Unexpected value {0}".format(x))