Opened 11 years ago

Closed 11 years ago

#4064 defect closed invalid (invalid)

amp responder changes int to string

Reported by: hagna Owned by:
Priority: normal Milestone:
Component: core Keywords:
Cc: Branch:
Author:

Description

Steps to duplicate

from twisted.trial.unittest import TestCase
from twisted.internet.defer import Deferred
from twisted.protocols import amp

class BugCMD(amp.Command):
    arguments = [('identifier', amp.String())]

    response = [('error', amp.Integer())]



class NetworkController(amp.AMP):
    def startBug2(self, identifier):
        return {'error':0}
    BugCMD.responder(startBug2)



class ControllerTests(TestCase):

    def setUp(self):
        self.controller = NetworkController()
        self.identifier = 123


    def test_BugCMD(self):

        responder = self.controller.lookupFunction(BugCMD.commandName)
        d = responder({
                'identifier': self.identifier,
                })

        def gotBugCMD(box):
            self.assertEqual(box, amp.AmpBox({'error':0}))
        d.addCallback(gotBugCMD)
        return d

Change History (2)

comment:1 Changed 11 years ago by Glyph

Resolution: invalid
Status: newclosed

AmpBoxes are always mappings of string to string, and the results of the return of lookupFunction will also be mapping only string to string. The fact that this doesn't completely blow up and fail is an accident, which happens mostly because it would be too expensive to check the argument type of everything passed into an AmpBox.

In other words, you're passing bad arguments, but this is otherwise working as expected. If you want to get an integer out, you're going to need to de-serialize your AMP results, using (in this case) BugCMD.parseArguments(box, self.controller).

comment:2 Changed 10 years ago by <automation>

Owner: Glyph deleted
Note: See TracTickets for help on using tickets.