Exemplo n.º 1
0
 def mock_add(self, mark, path):
     return mock_main(params={
         'mark': mark,
         'path': path,
         'sdirs': self.sdirs
     },
                      check_mode=False)
Exemplo n.º 2
0
 def test_delete_duplicates_true_check_mode_false(self):
     sdirs = self.create_sdirs_file()
     mock_objects = mock_main(
         params={'delete_duplicates': True, 'sdirs': sdirs},
         check_mode=False
     )
     self.assertEqual(mock_objects['entries'].entries[0].mark, 'dir1')
     self.assertEqual(mock_objects['entries'].entries[0].path, DIR1)
     self.assertEqual(mock_objects['entries'].entries[1].mark, 'dir2')
     self.assertEqual(mock_objects['entries'].entries[1].path, DIR2)
     self.assertEqual(len(mock_objects['entries'].entries), 3)
     mock_objects['module'].exit_json.assert_called_with(
         changed=True,
         changes=[
             {
                 'action': 'delete',
                 'mark': 'dir2',
                 'path': DIR1
             },
             {
                 'action': 'delete_duplicates',
                 'count': 1
             }
         ]
     )
Exemplo n.º 3
0
    def test_delete_all_options_true(self):
        mock_objects = mock_main(
            {
                'sdirs': self.sdirs,
                'state': 'absent',
                'delete_duplicates': True,
                'path': DIR1,
                'mark': 'tmp1',
                'sorted': True,
                'cleanup': True,
            },
            check_mode=False)

        self.assertEqual(len(mock_objects['entries'].entries), 2)
        mock_objects['module'].exit_json.assert_called_with(changed=True,
                                                            changes=[{
                                                                'action':
                                                                'delete',
                                                                'mark':
                                                                'tmp1',
                                                                'path':
                                                                DIR1,
                                                            }, {
                                                                'action':
                                                                'sort',
                                                                'sort_by':
                                                                'mark',
                                                                'reverse':
                                                                False,
                                                            }])
Exemplo n.º 4
0
 def test_delete_on_empty_sdirs_by_path(self):
     mock_objects = mock_main({
         'sdirs': tmp_file(),
         'path': '/dir1',
         'state': 'absent'
     })
     mock_objects['module'].exit_json.assert_called_with(changed=False)
Exemplo n.º 5
0
 def test_delete_casesensitivity(self):
     mock_objects = mock_main({
         'sdirs': self.sdirs,
         'mark': 'TMP1',
         'state': 'absent'
     })
     self.assertEqual(len(mock_objects['entries'].entries), 3)
     mock_objects['module'].exit_json.assert_called_with(changed=False)
Exemplo n.º 6
0
 def mock_add(self, mark, path, sdirs=False):
     if not sdirs:
         sdirs = tmp_file()
     return mock_main(params={
         'mark': mark,
         'path': path,
         'sdirs': sdirs
     },
                      check_mode=False)
Exemplo n.º 7
0
 def test_delete_nonexistent(self):
     non_existent = '/tmp/tmp34723423643646346etfjf34gegf623646'
     mock_objects = mock_main({
         'sdirs': self.sdirs,
         'path': non_existent,
         'state': 'absent'
     })
     self.assertEqual(len(mock_objects['entries'].entries), 3)
     mock_objects['module'].exit_json.assert_called_with(changed=False)
Exemplo n.º 8
0
 def test_sorted_false_check_mode_false(self):
     sdirs = self.create_sdirs_file()
     mock_objects = mock_main(params={'sorted': False, 'sdirs': sdirs},
                              check_mode=False)
     self.assertEqual(mock_objects['entries'].entries[0].mark, 'dirB')
     self.assertEqual(mock_objects['entries'].entries[1].mark, 'dirC')
     self.assertEqual(mock_objects['entries'].entries[2].mark, 'dirA')
     mock_objects['module'].exit_json.assert_called_with(
         changed=False
     )
Exemplo n.º 9
0
 def test_present(self):
     mock_objects = mock_main(params={
         'state': 'present',
         'path': DIR1,
         'mark': 'tmp'
     })
     self.assertEqual(len(mock_objects['entries'].entries), 1)
     entry = mock_objects['entries'].get_entry_by_index(0)
     self.assertEqual(entry.mark, 'tmp')
     self.assertEqual(entry.path, DIR1)
Exemplo n.º 10
0
    def test_replace_home_false_check_mode_false(self):
        sdirs = self.create_sdirs_file()
        mock_objects = mock_main(params={
            'replace_home': False,
            'sdirs': sdirs
        },
                                 check_mode=False)

        lines = read(sdirs)
        self.assertNotIn('$HOME', lines[0])
        mock_objects['module'].exit_json.assert_called_with(changed=False)
Exemplo n.º 11
0
    def test_nothing_to_do(self):
        entries = ShellmarkEntries(path=tmp_file())
        entries.add_entry(mark='dir1', path=DIR1)
        entries.add_entry(mark='dir2', path=DIR2)
        entries.add_entry(mark='dir3', path=DIR3)
        entries.write()

        mock_objects = mock_main({'cleanup': True, 'sdirs': entries.path})

        entries = ShellmarkEntries(path=mock_objects['module'].params['sdirs'])
        self.assertEqual(len(mock_objects['entries'].entries), 3)
        self.assertEqual(mock_objects['entries'].entries[0].path, DIR1)

        mock_objects['module'].exit_json.assert_called_with(changed=False)
Exemplo n.º 12
0
 def test_delete_duplicates_false_check_mode_false(self):
     sdirs = self.create_sdirs_file()
     mock_objects = mock_main(
         params={'delete_duplicates': False, 'sdirs': sdirs},
         check_mode=False
     )
     self.assertEqual(mock_objects['entries'].entries[0].mark, 'dir1')
     self.assertEqual(mock_objects['entries'].entries[0].path, DIR1)
     self.assertEqual(mock_objects['entries'].entries[1].mark, 'dir2')
     self.assertEqual(mock_objects['entries'].entries[1].path, DIR1)
     self.assertEqual(len(mock_objects['entries'].entries), 4)
     mock_objects['module'].exit_json.assert_called_with(
         changed=False
     )
Exemplo n.º 13
0
 def test_sorted_true_check_mode_true(self):
     sdirs = self.create_sdirs_file()
     mock_objects = mock_main(params={'sorted': True, 'sdirs': sdirs},
                              check_mode=True)
     self.assertEqual(mock_objects['entries'].entries[0].mark, 'dirB')
     mock_objects['module'].exit_json.assert_called_with(
         changed=True,
         changes=[
             {
                 'action': 'sort',
                 'sort_by': 'mark',
                 'reverse': False,
             },
         ]
     )
Exemplo n.º 14
0
    def test_cleanup(self):
        path = tmp_dir()
        no = 'export DIR_tmpb="/tmpXDR34723df4WER/d4REd4RE64er64erb"\n'
        content = no + no + no + \
            'export DIR_exists="' + path + '"\n' + no + no + no
        sdirs = create_tmp_text_file_with_content(content)

        mock_objects = mock_main({'cleanup': True, 'sdirs': sdirs})
        self.assertEqual(len(mock_objects['entries'].entries), 1)
        self.assertEqual(mock_objects['entries'].entries[0].path, path)

        mock_objects['module'].exit_json.assert_called_with(changed=True,
                                                            changes=[{
                                                                'action':
                                                                'cleanup',
                                                                'count': 6
                                                            }])
Exemplo n.º 15
0
 def test_delete_by_path(self):
     mock_objects = mock_main({
         'sdirs': self.sdirs,
         'path': DIR1,
         'state': 'absent'
     })
     self.assertEqual(len(mock_objects['entries'].entries), 2)
     mock_objects['module'].exit_json.assert_called_with(changed=True,
                                                         changes=[
                                                             {
                                                                 'action':
                                                                 'delete',
                                                                 'mark':
                                                                 'tmp1',
                                                                 'path':
                                                                 DIR1
                                                             },
                                                         ])
Exemplo n.º 16
0
    def test_replace_home_true_state_present_check_mode_true(self):
        sdirs = self.create_sdirs_file()
        mock_objects = mock_main(params={
            'replace_home': True,
            'sdirs': sdirs,
            'path': DIR1,
            'mark': 'dir1',
        },
                                 check_mode=True)

        lines = read(sdirs)
        self.assertNotIn('$HOME', lines[0])
        mock_objects['module'].exit_json.assert_called_with(changed=True,
                                                            changes=[
                                                                {
                                                                    'action':
                                                                    'add',
                                                                    'mark':
                                                                    'dir1',
                                                                    'path':
                                                                    DIR1,
                                                                },
                                                            ])