示例#1
0
    def test_scan_worldwritable_files_starting_with_dot(self, mock_os):
        # Prepare data and mocks
        test_subject = WorldWritable(None)
        mock_os.walk.return_value = [
            ('/dir1', ('/dir1/subdir1',), ('world_writable_starting_with_dot', 'not_world_writable_starting_with_dot')),
            ('/dir2', (), ()),
            ('/dir3', ('/dir3/subdir3',), ('world_writable_not_starting_with_dot',)),
        ]
        test_subject.is_world_writable = MagicMock(side_effect=[True, False, True])
        test_subject.is_starts_with_dot = MagicMock(side_effect=[True, False])

        # Run test scenario
        result = test_subject.scan_worldwritable_files_starting_with_dot()

        # Assertions
        self.assertEqual(result, ['world_writable_starting_with_dot'])
        mock_os.walk.assert_called_once_with('/')
        test_subject.is_world_writable.assert_has_calls(
            [
                call('world_writable_starting_with_dot'),
                call('not_world_writable_starting_with_dot'),
                call('world_writable_not_starting_with_dot'),
            ]
        )
        test_subject.is_starts_with_dot.assert_has_calls(
            [
                call('world_writable_starting_with_dot'),
                call('world_writable_not_starting_with_dot'),
            ]
        )
示例#2
0
    def test_scan_worldwritable_files_starting_with_dot(self, mock_os):
        # Prepare data and mocks
        test_subject = WorldWritable(None)
        mock_os.walk.return_value = [
            ('/dir1', ('/dir1/subdir1', ),
             ('world_writable_starting_with_dot',
              'not_world_writable_starting_with_dot')),
            ('/dir2', (), ()),
            ('/dir3', ('/dir3/subdir3', ),
             ('world_writable_not_starting_with_dot', )),
        ]
        test_subject.is_world_writable = MagicMock(
            side_effect=[True, False, True])
        test_subject.is_starts_with_dot = MagicMock(side_effect=[True, False])

        # Run test scenario
        result = test_subject.scan_worldwritable_files_starting_with_dot()

        # Assertions
        self.assertEqual(result, ['world_writable_starting_with_dot'])
        mock_os.walk.assert_called_once_with('/')
        test_subject.is_world_writable.assert_has_calls([
            call('world_writable_starting_with_dot'),
            call('not_world_writable_starting_with_dot'),
            call('world_writable_not_starting_with_dot'),
        ])
        test_subject.is_starts_with_dot.assert_has_calls([
            call('world_writable_starting_with_dot'),
            call('world_writable_not_starting_with_dot'),
        ])
示例#3
0
    def test_is_starts_with_dot_when_empty_string(self):
        # Prepare data and mocks
        test_subject = WorldWritable(None)
        path = ''

        # Run test scenario
        result = test_subject.is_starts_with_dot(path)

        # Assertions
        self.assertFalse(result)
示例#4
0
    def test_is_starts_with_dot_when_does_not(self):
        # Prepare data and mocks
        test_subject = WorldWritable(None)
        path = '/does/not/start/with/dot'

        # Run test scenario
        result = test_subject.is_starts_with_dot(path)

        # Assertions
        self.assertFalse(result)
示例#5
0
    def test_is_starts_with_dot_when_empty_string(self):
        # Prepare data and mocks
        test_subject = WorldWritable(None)
        path = ''

        # Run test scenario
        result = test_subject.is_starts_with_dot(path)

        # Assertions
        self.assertFalse(result)
示例#6
0
    def test_is_starts_with_dot_when_does_not(self):
        # Prepare data and mocks
        test_subject = WorldWritable(None)
        path = '/does/not/start/with/dot'

        # Run test scenario
        result = test_subject.is_starts_with_dot(path)

        # Assertions
        self.assertFalse(result)