示例#1
0
    def test_init_workerdest_old_api_warns(self):
        with assertProducesWarning(
                DeprecatedWorkerNameWarning,
                message_pattern="'slavedest' keyword argument is deprecated"):
            step = transfer.JSONStringDownload('srcfile', slavedest='dstfile')

        self.assertEqual(step.workerdest, 'dstfile')
示例#2
0
    def testBasic(self):
        msg = dict(message="Hello World")
        self.setupStep(transfer.JSONStringDownload(msg, "hello.json"))

        self.step.worker = Mock()
        self.step.remote = Mock()

        # A place to store what gets read
        read = []

        self.expectCommands(
            Expect(
                'downloadFile',
                dict(workerdest="hello.json",
                     workdir='wkdir',
                     blocksize=16384,
                     maxsize=None,
                     mode=None,
                     reader=ExpectRemoteRef(remotetransfer.StringFileReader)))
            + Expect.behavior(downloadString(read.append)) + 0)

        self.expectOutcome(result=SUCCESS,
                           state_string="downloading to hello.json")
        d = self.runStep()

        @d.addCallback
        def checkCalls(res):
            self.assertEqual(''.join(read), '{"message": "Hello World"}')

        return d
示例#3
0
    def testBasic(self):
        msg = dict(message="Hello World")
        s = transfer.JSONStringDownload(msg, "hello.json")
        s.build = Mock()
        s.build.getProperties.return_value = Properties()
        s.build.getSlaveCommandVersion.return_value = 1

        s.step_status = Mock()
        s.buildslave = Mock()
        s.remote = Mock()

        s.start()

        for c in s.remote.method_calls:
            name, command, args = c
            commandName = command[3]
            kwargs = command[-1]
            if commandName == 'downloadFile':
                self.assertEquals(kwargs['slavedest'], 'hello.json')
                reader = kwargs['reader']
                data = reader.remote_read(100)
                self.assertEquals(data, json.dumps(msg))
                break
        else:
            self.assert_(False, "No downloadFile command found")
示例#4
0
    def test_basic_with_renderable(self):
        msg = dict(message=Interpolate("Hello World"))
        self.setup_step(transfer.JSONStringDownload(msg, "hello.json"))

        self.step.worker = Mock()
        self.step.remote = Mock()

        # A place to store what gets read
        read = []

        self.expect_commands(
            ExpectDownloadFile(
                workerdest="hello.json",
                workdir='wkdir',
                blocksize=16384,
                maxsize=None,
                mode=None,
                reader=ExpectRemoteRef(
                    remotetransfer.StringFileReader)).download_string(
                        read.append).exit(0))

        self.expect_outcome(result=SUCCESS,
                            state_string="downloading to hello.json")
        yield self.run_step()

        self.assertEqual(b''.join(read), b'{"message": "Hello World"}')
示例#5
0
    def test_workerdest_old_api(self):
        step = transfer.JSONStringDownload('srcfile', workerdest='dstfile')

        with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
            new = step.workerdest

        with assertProducesWarning(
                DeprecatedWorkerNameWarning,
                message_pattern="'slavedest' attribute is deprecated"):
            old = step.slavedest

        self.assertIdentical(new, old)
示例#6
0
    def testFailure(self):
        msg = dict(message="Hello World")
        self.setupStep(transfer.JSONStringDownload(msg, "hello.json"))

        self.expectCommands(
            Expect('downloadFile', dict(
                slavedest="hello.json", workdir='wkdir',
                blocksize=16384, maxsize=None, mode=None,
                reader=ExpectRemoteRef(remotetransfer.StringFileReader)))
            + 1)

        self.expectOutcome(result=FAILURE, state_string="downloading to hello.json (failure)")
        return self.runStep()
示例#7
0
 def test_init_positional_args(self):
     self.assertRaises(TypeError, lambda: transfer.JSONStringDownload())
     self.assertRaises(TypeError,
                       lambda: transfer.JSONStringDownload('srcfile'))
示例#8
0
    def test_init_workerdest_positional(self):
        with assertNotProducesWarnings(DeprecatedWorkerAPIWarning):
            step = transfer.JSONStringDownload('srcfile', 'dstfile')

        self.assertEqual(step.workerdest, 'dstfile')
示例#9
0
 def test_init_positional_args(self):
     with self.assertRaises(TypeError):
         transfer.JSONStringDownload()
     with self.assertRaises(TypeError):
         transfer.JSONStringDownload('srcfile')
示例#10
0
    def test_init_workerdest_positional(self):
        step = transfer.JSONStringDownload('srcfile', 'dstfile')

        self.assertEqual(step.workerdest, 'dstfile')