test_info.py 24 KB

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