File: test_file_cd.py

package info (click to toggle)
weevely 4.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,336 kB
  • sloc: python: 7,732; php: 1,035; sh: 53; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 2,246 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from testfixtures import log_capture
from tests.base_test import BaseTest
from tests import config
from core.sessions import SessionURL
from core import modules
import utils
from core import messages
import subprocess
import os

def setUpModule():
    subprocess.check_output("""
BASE_FOLDER="{config.base_folder}/test_file_cd/"
rm -rf "$BASE_FOLDER"
mkdir -p "$BASE_FOLDER/dir1/dir2/dir3/dir4"
chmod 0 "$BASE_FOLDER/dir1/dir2/dir3/dir4"
""".format(
config = config
), shell=True)

class FileCd(BaseTest):

    folders = [ os.path.join(config.base_folder, f) for f in (
        'test_file_cd/dir1',
        'test_file_cd/dir1/dir2',
        'test_file_cd/dir1/dir2/dir3',
        'test_file_cd/dir1/dir2/dir3/dir4',
    ) ] 

    def setUp(self):
        self.session = SessionURL(
            self.url,
            self.password,
            volatile = True
        )

        modules.load_modules(self.session)

        self.run_argv = modules.loaded['file_cd'].run_argv

    @log_capture()
    def test_cwd(self, log_captured):

        # cd [0]
        new = self.folders[0]
        self.run_argv([ new ])
        self.assertEqual(new, self.session['file_cd']['results']['cwd'])

        # cd [-1]
        new = self.folders[-1]
        self.run_argv([ new ])
        self.assertEqual(self.folders[0], self.session['file_cd']['results']['cwd'])
        self.assertEqual(
            messages.module_file_cd.failed_directory_change_to_s % new,
            log_captured.records[-1].msg
        )

        # new [1]/.././[1]/./
        new = self.folders[1]
        self.run_argv([ '%s/.././%s/./' % (new, os.path.split(new)[-1]) ])
        self.assertEqual(new, self.session['file_cd']['results']['cwd'])

        # new bogus
        new = 'bogus'
        self.run_argv([ new ])
        self.assertEqual(self.folders[1], self.session['file_cd']['results']['cwd'])
        self.assertEqual(
            messages.module_file_cd.failed_directory_change_to_s % new,
            log_captured.records[-1].msg
        )

        # new [2]/.././[2]/../
        new = self.folders[2]
        self.run_argv([ '%s/.././////////%s/../' % (new, os.path.split(new)[-1]) ])
        self.assertEqual(self.folders[1], self.session['file_cd']['results']['cwd'])