File: test_project.py

package info (click to toggle)
fabric 1.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,240 kB
  • sloc: python: 7,363; makefile: 10
file content (177 lines) | stat: -rw-r--r-- 5,747 bytes parent folder | download
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import unittest
import os

import fudge
from fudge.inspector import arg

from fabric.contrib import project


class UploadProjectTestCase(unittest.TestCase):
    """Test case for :func: `fabric.contrib.project.upload_project`."""

    fake_tmp = "testtempfolder"


    def setUp(self):
        fudge.clear_expectations()

        # We need to mock out run, local, and put

        self.fake_run = fudge.Fake('project.run', callable=True)
        self.patched_run = fudge.patch_object(
                               project,
                               'run',
                               self.fake_run
                           )

        self.fake_local = fudge.Fake('local', callable=True)
        self.patched_local = fudge.patch_object(
                                 project,
                                 'local',
                                 self.fake_local
                             )

        self.fake_put = fudge.Fake('put', callable=True)
        self.patched_put = fudge.patch_object(
                               project,
                               'put',
                               self.fake_put
                           )

        # We don't want to create temp folders
        self.fake_mkdtemp = fudge.Fake(
                                'mkdtemp',
                                expect_call=True
                            ).returns(self.fake_tmp)
        self.patched_mkdtemp = fudge.patch_object(
                                   project,
                                   'mkdtemp',
                                   self.fake_mkdtemp
                               )


    def tearDown(self):
        self.patched_run.restore()
        self.patched_local.restore()
        self.patched_put.restore()

        fudge.clear_expectations()


    @fudge.with_fakes
    def test_temp_folder_is_used(self):
        """A unique temp folder is used for creating the archive to upload."""

        # Exercise
        project.upload_project()


    @fudge.with_fakes
    def test_project_is_archived_locally(self):
        """The project should be archived locally before being uploaded."""

        # local() is called more than once so we need an extra next_call()
        # otherwise fudge compares the args to the last call to local()
        self.fake_local.with_args(arg.startswith("tar -czf")).next_call()

        # Exercise
        project.upload_project()


    @fudge.with_fakes
    def test_current_directory_is_uploaded_by_default(self):
        """By default the project uploaded is the current working directory."""

        cwd_path, cwd_name = os.path.split(os.getcwd())

        # local() is called more than once so we need an extra next_call()
        # otherwise fudge compares the args to the last call to local()
        self.fake_local.with_args(
            arg.endswith("-C %s %s" % (cwd_path, cwd_name))
        ).next_call()

        # Exercise
        project.upload_project()


    @fudge.with_fakes
    def test_path_to_local_project_can_be_specified(self):
        """It should be possible to specify which local folder to upload."""

        project_path = "path/to/my/project"

        # local() is called more than once so we need an extra next_call()
        # otherwise fudge compares the args to the last call to local()
        self.fake_local.with_args(
            arg.endswith("-C path/to/my project")
        ).next_call()

        # Exercise
        project.upload_project(local_dir=project_path)


    @fudge.with_fakes
    def test_path_to_local_project_no_separator(self):
        """Local folder can have no path separator (in current directory)."""

        project_path = "testpath"

        # local() is called more than once so we need an extra next_call()
        # otherwise fudge compares the args to the last call to local()
        self.fake_local.with_args(
            arg.endswith("-C . testpath")
        ).next_call()

        # Exercise
        project.upload_project(local_dir=project_path)


    @fudge.with_fakes
    def test_path_to_local_project_can_end_in_separator(self):
        """A local path ending in a separator should be handled correctly."""

        project_path = "path/to/my"
        base = "project"

        # local() is called more than once so we need an extra next_call()
        # otherwise fudge compares the args to the last call to local()
        self.fake_local.with_args(
            arg.endswith("-C %s %s" % (project_path, base))
        ).next_call()

        # Exercise
        project.upload_project(local_dir="%s/%s/" % (project_path, base))


    @fudge.with_fakes
    def test_default_remote_folder_is_home(self):
        """Project is uploaded to remote home by default."""

        local_dir = "folder"

        # local() is called more than once so we need an extra next_call()
        # otherwise fudge compares the args to the last call to local()
        self.fake_put.with_args(
            "%s/folder.tar.gz" % self.fake_tmp, "folder.tar.gz", use_sudo=False
        ).next_call()

        # Exercise
        project.upload_project(local_dir=local_dir)

    @fudge.with_fakes
    def test_path_to_remote_folder_can_be_specified(self):
        """It should be possible to specify which local folder to upload to."""

        local_dir = "folder"
        remote_path = "path/to/remote/folder"

        # local() is called more than once so we need an extra next_call()
        # otherwise fudge compares the args to the last call to local()
        self.fake_put.with_args(
            "%s/folder.tar.gz" % self.fake_tmp, "%s/folder.tar.gz" % remote_path, use_sudo=False
        ).next_call()

        # Exercise
        project.upload_project(local_dir=local_dir, remote_dir=remote_path)