test_svn.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, unicode_literals, print_function
  7. # Import Salt Testing Libs
  8. from tests.support.mixins import LoaderModuleMockMixin
  9. from tests.support.unit import TestCase
  10. from tests.support.mock import (
  11. MagicMock,
  12. patch)
  13. # Import Salt Libs
  14. import salt.modules.svn as svn
  15. class SvnTestCase(TestCase, LoaderModuleMockMixin):
  16. '''
  17. Test cases for salt.modules.svn
  18. '''
  19. def setup_loader_modules(self):
  20. return {svn: {}}
  21. def test_info(self):
  22. '''
  23. Test to display the Subversion information from the checkout.
  24. '''
  25. mock = MagicMock(side_effect=[{'retcode': 0, 'stdout': True},
  26. {'retcode': 0, 'stdout': 'A\n\nB'},
  27. {'retcode': 0, 'stdout': 'A\n\nB'}])
  28. with patch.dict(svn.__salt__, {'cmd.run_all': mock}):
  29. self.assertTrue(svn.info('cwd', fmt='xml'))
  30. self.assertListEqual(svn.info('cwd', fmt='list'), [[], []])
  31. self.assertListEqual(svn.info('cwd', fmt='dict'), [{}, {}])
  32. def test_checkout(self):
  33. '''
  34. Test to download a working copy of the remote Subversion repository
  35. directory or file
  36. '''
  37. mock = MagicMock(return_value={'retcode': 0, 'stdout': True})
  38. with patch.dict(svn.__salt__, {'cmd.run_all': mock}):
  39. self.assertTrue(svn.checkout('cwd', 'remote'))
  40. def test_switch(self):
  41. '''
  42. Test to switch a working copy of a remote Subversion repository
  43. directory
  44. '''
  45. mock = MagicMock(return_value={'retcode': 0, 'stdout': True})
  46. with patch.dict(svn.__salt__, {'cmd.run_all': mock}):
  47. self.assertTrue(svn.switch('cwd', 'remote'))
  48. def test_update(self):
  49. '''
  50. Test to update the current directory, files, or directories from
  51. the remote Subversion repository
  52. '''
  53. mock = MagicMock(return_value={'retcode': 0, 'stdout': True})
  54. with patch.dict(svn.__salt__, {'cmd.run_all': mock}):
  55. self.assertTrue(svn.update('cwd'))
  56. def test_diff(self):
  57. '''
  58. Test to return the diff of the current directory, files, or
  59. directories from the remote Subversion repository
  60. '''
  61. mock = MagicMock(return_value={'retcode': 0, 'stdout': True})
  62. with patch.dict(svn.__salt__, {'cmd.run_all': mock}):
  63. self.assertTrue(svn.diff('cwd'))
  64. def test_commit(self):
  65. '''
  66. Test to commit the current directory, files, or directories to
  67. the remote Subversion repository
  68. '''
  69. mock = MagicMock(return_value={'retcode': 0, 'stdout': True})
  70. with patch.dict(svn.__salt__, {'cmd.run_all': mock}):
  71. self.assertTrue(svn.commit('cwd'))
  72. def test_add(self):
  73. '''
  74. Test to add files to be tracked by the Subversion working-copy
  75. checkout
  76. '''
  77. mock = MagicMock(return_value={'retcode': 0, 'stdout': True})
  78. with patch.dict(svn.__salt__, {'cmd.run_all': mock}):
  79. self.assertTrue(svn.add('cwd', False))
  80. def test_remove(self):
  81. '''
  82. Test to remove files and directories from the Subversion repository
  83. '''
  84. mock = MagicMock(return_value={'retcode': 0, 'stdout': True})
  85. with patch.dict(svn.__salt__, {'cmd.run_all': mock}):
  86. self.assertTrue(svn.remove('cwd', False))
  87. def test_status(self):
  88. '''
  89. Test to display the status of the current directory, files, or
  90. directories in the Subversion repository
  91. '''
  92. mock = MagicMock(return_value={'retcode': 0, 'stdout': True})
  93. with patch.dict(svn.__salt__, {'cmd.run_all': mock}):
  94. self.assertTrue(svn.status('cwd'))
  95. def test_export(self):
  96. '''
  97. Test to create an unversioned copy of a tree.
  98. '''
  99. mock = MagicMock(return_value={'retcode': 0, 'stdout': True})
  100. with patch.dict(svn.__salt__, {'cmd.run_all': mock}):
  101. self.assertTrue(svn.export('cwd', 'remote'))