1
0

test_sqlcipher.py 23 KB

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