Example #1
0
    def test_get_use_sudo(self):
        """
        get(use_sudo=True) works by copying to a temporary path, downloading it and then removing it at the end
        """
        fake_run = Fake(
            '_run_command', callable=True,
            expect_call=True).with_matching_args(
                fudge_arg.startswith('cp -p "/etc/apache2/apache2.conf" "'),
                True, True, None).next_call().with_matching_args(
                    fudge_arg.startswith('chown username "'),
                    True,
                    True,
                    None,
                ).next_call().with_matching_args(
                    fudge_arg.startswith('chmod 400 "'),
                    True,
                    True,
                    None,
                ).next_call().with_matching_args(
                    fudge_arg.startswith('rm -f "'),
                    True,
                    True,
                    None,
                )
        fake_get = Fake('get', callable=True, expect_call=True)

        with hide('everything'):
            with patched_context('fabric.operations', '_run_command',
                                 fake_run):
                with patched_context(SFTPClient, 'get', fake_get):
                    retval = get('/etc/apache2/apache2.conf',
                                 self.path(),
                                 use_sudo=True)
                    # check that the downloaded file has the same name as the one requested
                    assert retval[0].endswith('apache2.conf')
Example #2
0
    def test_put_use_sudo_temp_dir(self):
        """
        put(use_sudo=True, temp_dir='/tmp/') works by uploading a file to /tmp/ and then moving it to a `remote_path`
        """
        # the sha1 hash is the unique filename of the file being downloaded. sha1(<filename>)
        fake_run = Fake('_run_command', callable=True,
                        expect_call=True).with_matching_args(
                            fudge_arg.startswith('mv "'),
                            True,
                            True,
                            None,
                        )
        fake_put = Fake('put', callable=True, expect_call=True)

        local_path = self.mkfile('foobar.txt', "baz")
        with hide('everything'):
            with patched_context('fabric.operations', '_run_command',
                                 fake_run):
                with patched_context(SFTPClient, 'put', fake_put):
                    retval = put(local_path,
                                 "/",
                                 use_sudo=True,
                                 temp_dir='/tmp/')
                    # check that the downloaded file has the same name as the one requested
                    assert retval[0].endswith('foobar.txt')
Example #3
0
    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()
Example #4
0
    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()
Example #5
0
    def test_get_use_sudo(self):
        """
        get(use_sudo=True) works by copying to a temporary path, downloading it and then removing it at the end
        """
        fake_run = Fake('_run_command', callable=True, expect_call=True).with_matching_args(
            fudge_arg.startswith('cp -p "/etc/apache2/apache2.conf" "'), True, True, None
        ).next_call().with_matching_args(
            fudge_arg.startswith('chown username "'), True, True, None,
        ).next_call().with_matching_args(
            fudge_arg.startswith('chmod 400 "'), True, True, None,
        ).next_call().with_matching_args(
            fudge_arg.startswith('rm -f "'), True, True, None,
        )
        fake_get = Fake('get', callable=True, expect_call=True)

        with hide('everything'):
            with patched_context('fabric.operations', '_run_command', fake_run):
                with patched_context(SFTPClient, 'get', fake_get):
                    retval = get('/etc/apache2/apache2.conf', self.path(), use_sudo=True)
                    # check that the downloaded file has the same name as the one requested
                    assert retval[0].endswith('apache2.conf')
Example #6
0
    def test_put_use_sudo(self):
        """
        put(use_sudo=True) works by uploading a the `local_path` to a temporary path and then moving it to a `remote_path`
        """
        fake_run = Fake('_run_command', callable=True, expect_call=True).with_matching_args(
            fudge_arg.startswith('mv "'), True, True, None,
        )
        fake_put = Fake('put', callable=True, expect_call=True)

        local_path = self.mkfile('foobar.txt', "baz")
        with hide('everything'):
            with patched_context('fabric.operations', '_run_command', fake_run):
                with patched_context(SFTPClient, 'put', fake_put):
                    retval = put(local_path, "/", use_sudo=True)
                    # check that the downloaded file has the same name as the one requested
                    assert retval[0].endswith('foobar.txt')
Example #7
0
 def test_startswith_ok_uni(self):
     db = Fake("db").expects("execute").with_args(arg.startswith(u"Ivan_Krsti\u0107"))
     db.execute(u"Ivan_Krsti\u0107(); foo();")
Example #8
0
 def test_startswith_fail(self):
     db = Fake("db").expects("execute").with_args(arg.startswith("insert into"))
     db.execute("select from")
Example #9
0
 def test_startswith_ok(self):
     db = Fake("db").expects("execute").with_args(arg.startswith("insert into"))
     db.execute("insert into foo values (1,2,3,4)")
Example #10
0
 def test_startswith_ok_uni(self):
     db = Fake("db").expects("execute").with_args(arg.startswith("Ivan_Krsti\u0107"))
     db.execute("Ivan_Krsti\u0107(); foo();")
Example #11
0
 def test_startswith_fail(self):
     db = Fake("db").expects("execute").with_args(arg.startswith("insert into"))
     db.execute("select from")
Example #12
0
 def test_startswith_ok(self):
     db = Fake("db").expects("execute").with_args(arg.startswith("insert into"))
     db.execute("insert into foo values (1,2,3,4)")