test_info.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. import logging
  2. import pytest
  3. from flexmock import flexmock
  4. from borgmatic.borg import info as module
  5. from ..test_verbosity import insert_logging_mock
  6. def test_display_archives_info_calls_borg_with_parameters():
  7. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  8. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  9. flexmock(module.flags).should_receive('make_flags').and_return(())
  10. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  11. None, None, '2.3.4'
  12. ).and_return(())
  13. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
  14. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  15. flexmock(module.environment).should_receive('make_environment')
  16. flexmock(module).should_receive('execute_command').with_args(
  17. ('borg', 'info', '--repo', 'repo'),
  18. output_log_level=module.borgmatic.logger.ANSWER,
  19. borg_local_path='borg',
  20. extra_environment=None,
  21. )
  22. module.display_archives_info(
  23. repository_path='repo',
  24. config={},
  25. local_borg_version='2.3.4',
  26. global_arguments=flexmock(log_json=False),
  27. info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
  28. )
  29. def test_display_archives_info_with_log_info_calls_borg_with_info_parameter():
  30. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  31. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  32. flexmock(module.flags).should_receive('make_flags').and_return(())
  33. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  34. None, None, '2.3.4'
  35. ).and_return(())
  36. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
  37. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  38. flexmock(module.environment).should_receive('make_environment')
  39. flexmock(module).should_receive('execute_command').with_args(
  40. ('borg', 'info', '--info', '--repo', 'repo'),
  41. output_log_level=module.borgmatic.logger.ANSWER,
  42. borg_local_path='borg',
  43. extra_environment=None,
  44. )
  45. insert_logging_mock(logging.INFO)
  46. module.display_archives_info(
  47. repository_path='repo',
  48. config={},
  49. local_borg_version='2.3.4',
  50. global_arguments=flexmock(log_json=False),
  51. info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
  52. )
  53. def test_display_archives_info_with_log_info_and_json_suppresses_most_borg_output():
  54. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  55. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  56. flexmock(module.flags).should_receive('make_flags').and_return(())
  57. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  58. None, None, '2.3.4'
  59. ).and_return(())
  60. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(('--json',))
  61. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  62. flexmock(module.environment).should_receive('make_environment')
  63. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  64. ('borg', 'info', '--json', '--repo', 'repo'),
  65. extra_environment=None,
  66. borg_local_path='borg',
  67. ).and_return('[]')
  68. insert_logging_mock(logging.INFO)
  69. json_output = module.display_archives_info(
  70. repository_path='repo',
  71. config={},
  72. local_borg_version='2.3.4',
  73. global_arguments=flexmock(log_json=False),
  74. info_arguments=flexmock(archive=None, json=True, prefix=None, match_archives=None),
  75. )
  76. assert json_output == '[]'
  77. def test_display_archives_info_with_log_debug_calls_borg_with_debug_parameter():
  78. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  79. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  80. flexmock(module.flags).should_receive('make_flags').and_return(())
  81. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  82. None, None, '2.3.4'
  83. ).and_return(())
  84. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
  85. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  86. flexmock(module.environment).should_receive('make_environment')
  87. flexmock(module).should_receive('execute_command').with_args(
  88. ('borg', 'info', '--debug', '--show-rc', '--repo', 'repo'),
  89. output_log_level=module.borgmatic.logger.ANSWER,
  90. borg_local_path='borg',
  91. extra_environment=None,
  92. )
  93. insert_logging_mock(logging.DEBUG)
  94. module.display_archives_info(
  95. repository_path='repo',
  96. config={},
  97. local_borg_version='2.3.4',
  98. global_arguments=flexmock(log_json=False),
  99. info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
  100. )
  101. def test_display_archives_info_with_log_debug_and_json_suppresses_most_borg_output():
  102. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  103. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  104. flexmock(module.flags).should_receive('make_flags').and_return(())
  105. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  106. None, None, '2.3.4'
  107. ).and_return(())
  108. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(('--json',))
  109. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  110. flexmock(module.environment).should_receive('make_environment')
  111. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  112. ('borg', 'info', '--json', '--repo', 'repo'),
  113. extra_environment=None,
  114. borg_local_path='borg',
  115. ).and_return('[]')
  116. insert_logging_mock(logging.DEBUG)
  117. json_output = module.display_archives_info(
  118. repository_path='repo',
  119. config={},
  120. local_borg_version='2.3.4',
  121. global_arguments=flexmock(log_json=False),
  122. info_arguments=flexmock(archive=None, json=True, prefix=None, match_archives=None),
  123. )
  124. assert json_output == '[]'
  125. def test_display_archives_info_with_json_calls_borg_with_json_parameter():
  126. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  127. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  128. flexmock(module.flags).should_receive('make_flags').and_return(())
  129. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  130. None, None, '2.3.4'
  131. ).and_return(())
  132. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(('--json',))
  133. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  134. flexmock(module.environment).should_receive('make_environment')
  135. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  136. ('borg', 'info', '--json', '--repo', 'repo'),
  137. extra_environment=None,
  138. borg_local_path='borg',
  139. ).and_return('[]')
  140. json_output = module.display_archives_info(
  141. repository_path='repo',
  142. config={},
  143. local_borg_version='2.3.4',
  144. global_arguments=flexmock(log_json=False),
  145. info_arguments=flexmock(archive=None, json=True, prefix=None, match_archives=None),
  146. )
  147. assert json_output == '[]'
  148. def test_display_archives_info_with_archive_calls_borg_with_match_archives_parameter():
  149. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  150. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  151. flexmock(module.flags).should_receive('make_flags').and_return(())
  152. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  153. 'archive', None, '2.3.4'
  154. ).and_return(('--match-archives', 'archive'))
  155. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
  156. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  157. flexmock(module.environment).should_receive('make_environment')
  158. flexmock(module).should_receive('execute_command').with_args(
  159. ('borg', 'info', '--match-archives', 'archive', '--repo', 'repo'),
  160. output_log_level=module.borgmatic.logger.ANSWER,
  161. borg_local_path='borg',
  162. extra_environment=None,
  163. )
  164. module.display_archives_info(
  165. repository_path='repo',
  166. config={},
  167. local_borg_version='2.3.4',
  168. global_arguments=flexmock(log_json=False),
  169. info_arguments=flexmock(archive='archive', json=False, prefix=None, match_archives=None),
  170. )
  171. def test_display_archives_info_with_local_path_calls_borg_via_local_path():
  172. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  173. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  174. flexmock(module.flags).should_receive('make_flags').and_return(())
  175. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  176. None, None, '2.3.4'
  177. ).and_return(())
  178. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
  179. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  180. flexmock(module.environment).should_receive('make_environment')
  181. flexmock(module).should_receive('execute_command').with_args(
  182. ('borg1', 'info', '--repo', 'repo'),
  183. output_log_level=module.borgmatic.logger.ANSWER,
  184. borg_local_path='borg1',
  185. extra_environment=None,
  186. )
  187. module.display_archives_info(
  188. repository_path='repo',
  189. config={},
  190. local_borg_version='2.3.4',
  191. global_arguments=flexmock(log_json=False),
  192. info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
  193. local_path='borg1',
  194. )
  195. def test_display_archives_info_with_remote_path_calls_borg_with_remote_path_parameters():
  196. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  197. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  198. flexmock(module.flags).should_receive('make_flags').and_return(())
  199. flexmock(module.flags).should_receive('make_flags').with_args(
  200. 'remote-path', 'borg1'
  201. ).and_return(('--remote-path', 'borg1'))
  202. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  203. None, None, '2.3.4'
  204. ).and_return(())
  205. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
  206. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  207. flexmock(module.environment).should_receive('make_environment')
  208. flexmock(module).should_receive('execute_command').with_args(
  209. ('borg', 'info', '--remote-path', 'borg1', '--repo', 'repo'),
  210. output_log_level=module.borgmatic.logger.ANSWER,
  211. borg_local_path='borg',
  212. extra_environment=None,
  213. )
  214. module.display_archives_info(
  215. repository_path='repo',
  216. config={},
  217. local_borg_version='2.3.4',
  218. global_arguments=flexmock(log_json=False),
  219. info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
  220. remote_path='borg1',
  221. )
  222. def test_display_archives_info_with_log_json_calls_borg_with_log_json_parameters():
  223. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  224. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  225. flexmock(module.flags).should_receive('make_flags').and_return(())
  226. flexmock(module.flags).should_receive('make_flags').with_args('log-json', True).and_return(
  227. ('--log-json',)
  228. )
  229. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  230. None, None, '2.3.4'
  231. ).and_return(())
  232. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
  233. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  234. flexmock(module.environment).should_receive('make_environment')
  235. flexmock(module).should_receive('execute_command').with_args(
  236. ('borg', 'info', '--log-json', '--repo', 'repo'),
  237. output_log_level=module.borgmatic.logger.ANSWER,
  238. borg_local_path='borg',
  239. extra_environment=None,
  240. )
  241. module.display_archives_info(
  242. repository_path='repo',
  243. config={},
  244. local_borg_version='2.3.4',
  245. global_arguments=flexmock(log_json=True),
  246. info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
  247. )
  248. def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_parameters():
  249. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  250. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  251. flexmock(module.flags).should_receive('make_flags').and_return(())
  252. flexmock(module.flags).should_receive('make_flags').with_args('lock-wait', 5).and_return(
  253. ('--lock-wait', '5')
  254. )
  255. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  256. None, None, '2.3.4'
  257. ).and_return(())
  258. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
  259. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  260. config = {'lock_wait': 5}
  261. flexmock(module.environment).should_receive('make_environment')
  262. flexmock(module).should_receive('execute_command').with_args(
  263. ('borg', 'info', '--lock-wait', '5', '--repo', 'repo'),
  264. output_log_level=module.borgmatic.logger.ANSWER,
  265. borg_local_path='borg',
  266. extra_environment=None,
  267. )
  268. module.display_archives_info(
  269. repository_path='repo',
  270. config=config,
  271. local_borg_version='2.3.4',
  272. global_arguments=flexmock(log_json=False),
  273. info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
  274. )
  275. def test_display_archives_info_transforms_prefix_into_match_archives_parameters():
  276. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  277. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  278. flexmock(module.flags).should_receive('make_flags').and_return(())
  279. flexmock(module.flags).should_receive('make_flags').with_args(
  280. 'match-archives', 'sh:foo*'
  281. ).and_return(('--match-archives', 'sh:foo*'))
  282. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  283. None, None, '2.3.4'
  284. ).and_return(())
  285. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
  286. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  287. flexmock(module.environment).should_receive('make_environment')
  288. flexmock(module).should_receive('execute_command').with_args(
  289. ('borg', 'info', '--match-archives', 'sh:foo*', '--repo', 'repo'),
  290. output_log_level=module.borgmatic.logger.ANSWER,
  291. borg_local_path='borg',
  292. extra_environment=None,
  293. )
  294. module.display_archives_info(
  295. repository_path='repo',
  296. config={},
  297. local_borg_version='2.3.4',
  298. global_arguments=flexmock(log_json=False),
  299. info_arguments=flexmock(archive=None, json=False, prefix='foo'),
  300. )
  301. def test_display_archives_info_prefers_prefix_over_archive_name_format():
  302. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  303. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  304. flexmock(module.flags).should_receive('make_flags').and_return(())
  305. flexmock(module.flags).should_receive('make_flags').with_args(
  306. 'match-archives', 'sh:foo*'
  307. ).and_return(('--match-archives', 'sh:foo*'))
  308. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  309. None, None, '2.3.4'
  310. ).and_return(())
  311. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
  312. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  313. flexmock(module.environment).should_receive('make_environment')
  314. flexmock(module).should_receive('execute_command').with_args(
  315. ('borg', 'info', '--match-archives', 'sh:foo*', '--repo', 'repo'),
  316. output_log_level=module.borgmatic.logger.ANSWER,
  317. borg_local_path='borg',
  318. extra_environment=None,
  319. )
  320. module.display_archives_info(
  321. repository_path='repo',
  322. config={'archive_name_format': 'bar-{now}'}, # noqa: FS003
  323. local_borg_version='2.3.4',
  324. global_arguments=flexmock(log_json=False),
  325. info_arguments=flexmock(archive=None, json=False, prefix='foo'),
  326. )
  327. def test_display_archives_info_transforms_archive_name_format_into_match_archives_parameters():
  328. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  329. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  330. flexmock(module.flags).should_receive('make_flags').and_return(())
  331. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  332. None, 'bar-{now}', '2.3.4' # noqa: FS003
  333. ).and_return(('--match-archives', 'sh:bar-*'))
  334. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
  335. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  336. flexmock(module.environment).should_receive('make_environment')
  337. flexmock(module).should_receive('execute_command').with_args(
  338. ('borg', 'info', '--match-archives', 'sh:bar-*', '--repo', 'repo'),
  339. output_log_level=module.borgmatic.logger.ANSWER,
  340. borg_local_path='borg',
  341. extra_environment=None,
  342. )
  343. module.display_archives_info(
  344. repository_path='repo',
  345. config={'archive_name_format': 'bar-{now}'}, # noqa: FS003
  346. local_borg_version='2.3.4',
  347. global_arguments=flexmock(log_json=False),
  348. info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
  349. )
  350. def test_display_archives_with_match_archives_option_calls_borg_with_match_archives_parameter():
  351. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  352. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  353. flexmock(module.flags).should_receive('make_flags').and_return(())
  354. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  355. 'sh:foo-*', 'bar-{now}', '2.3.4' # noqa: FS003
  356. ).and_return(('--match-archives', 'sh:foo-*'))
  357. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
  358. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  359. flexmock(module.environment).should_receive('make_environment')
  360. flexmock(module).should_receive('execute_command').with_args(
  361. ('borg', 'info', '--match-archives', 'sh:foo-*', '--repo', 'repo'),
  362. output_log_level=module.borgmatic.logger.ANSWER,
  363. borg_local_path='borg',
  364. extra_environment=None,
  365. )
  366. module.display_archives_info(
  367. repository_path='repo',
  368. config={
  369. 'archive_name_format': 'bar-{now}', # noqa: FS003
  370. 'match_archives': 'sh:foo-*',
  371. },
  372. local_borg_version='2.3.4',
  373. global_arguments=flexmock(log_json=False),
  374. info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
  375. )
  376. def test_display_archives_with_match_archives_flag_calls_borg_with_match_archives_parameter():
  377. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  378. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  379. flexmock(module.flags).should_receive('make_flags').and_return(())
  380. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  381. 'sh:foo-*', 'bar-{now}', '2.3.4' # noqa: FS003
  382. ).and_return(('--match-archives', 'sh:foo-*'))
  383. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
  384. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  385. flexmock(module.environment).should_receive('make_environment')
  386. flexmock(module).should_receive('execute_command').with_args(
  387. ('borg', 'info', '--match-archives', 'sh:foo-*', '--repo', 'repo'),
  388. output_log_level=module.borgmatic.logger.ANSWER,
  389. borg_local_path='borg',
  390. extra_environment=None,
  391. )
  392. module.display_archives_info(
  393. repository_path='repo',
  394. config={'archive_name_format': 'bar-{now}'}, # noqa: FS003
  395. local_borg_version='2.3.4',
  396. global_arguments=flexmock(log_json=False),
  397. info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives='sh:foo-*'),
  398. )
  399. @pytest.mark.parametrize('argument_name', ('sort_by', 'first', 'last'))
  400. def test_display_archives_info_passes_through_arguments_to_borg(argument_name):
  401. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  402. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  403. flag_name = f"--{argument_name.replace('_', ' ')}"
  404. flexmock(module.flags).should_receive('make_flags').and_return(())
  405. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  406. None, None, '2.3.4'
  407. ).and_return(())
  408. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(
  409. (flag_name, 'value')
  410. )
  411. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  412. flexmock(module.environment).should_receive('make_environment')
  413. flexmock(module).should_receive('execute_command').with_args(
  414. ('borg', 'info', flag_name, 'value', '--repo', 'repo'),
  415. output_log_level=module.borgmatic.logger.ANSWER,
  416. borg_local_path='borg',
  417. extra_environment=None,
  418. )
  419. module.display_archives_info(
  420. repository_path='repo',
  421. config={},
  422. local_borg_version='2.3.4',
  423. global_arguments=flexmock(log_json=False),
  424. info_arguments=flexmock(
  425. archive=None, json=False, prefix=None, match_archives=None, **{argument_name: 'value'}
  426. ),
  427. )
  428. def test_display_archives_info_with_date_based_matching_calls_borg_with_date_based_flags():
  429. flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
  430. flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
  431. flexmock(module.flags).should_receive('make_flags').and_return(())
  432. flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
  433. None, None, '2.3.4'
  434. ).and_return(())
  435. flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(
  436. ('--newer', '1d', '--newest', '1y', '--older', '1m', '--oldest', '1w')
  437. )
  438. flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
  439. flexmock(module.environment).should_receive('make_environment')
  440. flexmock(module).should_receive('execute_command').with_args(
  441. (
  442. 'borg',
  443. 'info',
  444. '--newer',
  445. '1d',
  446. '--newest',
  447. '1y',
  448. '--older',
  449. '1m',
  450. '--oldest',
  451. '1w',
  452. '--repo',
  453. 'repo',
  454. ),
  455. output_log_level=module.borgmatic.logger.ANSWER,
  456. borg_local_path='borg',
  457. extra_environment=None,
  458. )
  459. info_arguments = flexmock(
  460. archive=None,
  461. json=False,
  462. prefix=None,
  463. match_archives=None,
  464. newer='1d',
  465. newest='1y',
  466. older='1m',
  467. oldest='1w',
  468. )
  469. module.display_archives_info(
  470. repository_path='repo',
  471. config={},
  472. local_borg_version='2.3.4',
  473. global_arguments=flexmock(log_json=False),
  474. info_arguments=info_arguments,
  475. )