Ejemplo n.º 1
0
    def should_fail_to_get_headers(self):
        my_frame = Frame()
        my_frame._getline = Dingus()
        my_frame._getline.return_value = \
                'RECEIPTreceipt-id:ID:nose-receipt123'

        nose_tools.assert_raises(UnknownBrokerResponseError,
            my_frame.parse_frame)
Ejemplo n.º 2
0
    def should_fail_to_get_headers(self):
        my_frame = Frame()
        my_frame._getline = Dingus()
        my_frame._getline.return_value = \
                'RECEIPTreceipt-id:ID:nose-receipt123'

        nose_tools.assert_raises(UnknownBrokerResponseError,
                                 my_frame.parse_frame)
Ejemplo n.º 3
0
 def should_not_get_message(self):
     my_frame = Frame()
     my_frame._getline = Dingus()
     my_frame._getline.return_value = None
     my_frame.iqueue.get = Dingus()
     my_frame.iqueue.get.return_value = None
     ret_frame = my_frame.get_message(nb=True)
     assert ret_frame is None
Ejemplo n.º 4
0
 def should_not_get_message(self):
     my_frame = Frame()
     my_frame._getline = Dingus()
     my_frame._getline.return_value = None
     my_frame.iqueue.get = Dingus()
     my_frame.iqueue.get.return_value = None
     ret_frame = my_frame.get_message(nb=True)
     assert ret_frame is None
Ejemplo n.º 5
0
    def should_set_bytes_message(self):
        my_frame = Frame()
        my_frame._getline = Dingus()
        body = 'Test 1'
        my_frame._getline.return_value = (
                'MESSAGE\nsession:ID:nose-session123'
                '\ncontent-length:%d\n\n%s\x00\n' % (len(body), body))
        this_frame = my_frame.parse_frame()

        assert 'bytes_message' in this_frame.headers
Ejemplo n.º 6
0
    def should_set_bytes_message(self):
        my_frame = Frame()
        my_frame._getline = Dingus()
        body = 'Test 1'
        my_frame._getline.return_value = ('MESSAGE\nsession:ID:nose-session123'
                                          '\ncontent-length:%d\n\n%s\x00\n' %
                                          (len(body), body))
        this_frame = my_frame.parse_frame()

        assert 'bytes_message' in this_frame.headers
Ejemplo n.º 7
0
    def should_get_error_from_broker(self):
        my_frame = Frame()
        my_frame._getline = Dingus()
        command = 'ERROR'
        header = 'message:Illegal command'
        body = 'Error Message'
        my_frame._getline.return_value = \
            '%s\n%s\ncontent-length:%d\n\n%s\n\x00' % (command,
                                                       header,
                                                       len(body),
                                                       body)

        nose_tools.assert_raises(BrokerErrorResponse, my_frame.parse_frame)
Ejemplo n.º 8
0
    def should_get_error_from_broker(self):
        my_frame = Frame()
        my_frame._getline = Dingus()
        command = 'ERROR'
        header = 'message:Illegal command'
        body = 'Error Message'
        my_frame._getline.return_value = \
            '%s\n%s\ncontent-length:%d\n\n%s\n\x00' % (command,
                                                       header,
                                                       len(body),
                                                       body)

        nose_tools.assert_raises(BrokerErrorResponse, my_frame.parse_frame)
Ejemplo n.º 9
0
 def should_get_message_and_return_frame(self):
     my_frame = Frame()
     my_frame._getline = Dingus()
     command = 'MESSAGE'
     body = 'Test 1'
     headers = {'session': 'ID:nose-session123',
                'content-length': '%d' %len(body)}
     my_frame.parse_frame = Dingus()
     this_frame = my_frame.build_frame({'command': command,
                                        'headers': headers,
                                        'body': body})
     my_frame.parse_frame.return_value = this_frame
     ret_frame = my_frame.get_message(nb=True)
     assert isinstance(ret_frame, Frame)
Ejemplo n.º 10
0
    def should_send_frame_and_return_frame(self):
        my_frame = Frame()
        my_frame._getline = Dingus()
        headers = {'destination': '/queue/nose_test',
                   'persistent': 'true'}
        body = {'body': 'Testing'}
        my_frame._getline.return_value = \
                'CONNECTED\nsession:ID:nose-session123\n\n\x00\n'
        my_frame.connect(self.sockobj.connect('localhost', 99999))
        this_frame = my_frame.build_frame({'command': 'SEND',
                                           'headers': headers,
                                           'body': body},
                                           want_receipt=True)
        my_frame._getline.return_value = \
                'RECEIPT\nreceipt-id:ID:nose-receipt123\n\n\x00\n'
        send_frame = my_frame.send_frame(this_frame.as_string())

        assert isinstance(my_frame, Frame)
Ejemplo n.º 11
0
 def should_get_message_and_return_frame(self):
     my_frame = Frame()
     my_frame._getline = Dingus()
     command = 'MESSAGE'
     body = 'Test 1'
     headers = {
         'session': 'ID:nose-session123',
         'content-length': '%d' % len(body)
     }
     my_frame.parse_frame = Dingus()
     this_frame = my_frame.build_frame({
         'command': command,
         'headers': headers,
         'body': body
     })
     my_frame.parse_frame.return_value = this_frame
     ret_frame = my_frame.get_message(nb=True)
     assert isinstance(ret_frame, Frame)
Ejemplo n.º 12
0
    def should_send_frame_and_return_frame(self):
        my_frame = Frame()
        my_frame._getline = Dingus()
        headers = {'destination': '/queue/nose_test', 'persistent': 'true'}
        body = {'body': 'Testing'}
        my_frame._getline.return_value = \
                'CONNECTED\nsession:ID:nose-session123\n\n\x00\n'
        my_frame.connect(self.sockobj.connect('localhost', 99999))
        this_frame = my_frame.build_frame(
            {
                'command': 'SEND',
                'headers': headers,
                'body': body
            },
            want_receipt=True)
        my_frame._getline.return_value = \
                'RECEIPT\nreceipt-id:ID:nose-receipt123\n\n\x00\n'
        send_frame = my_frame.send_frame(this_frame.as_string())

        assert isinstance(my_frame, Frame)
Ejemplo n.º 13
0
 def should_not_get_line(self):
     my_frame = Frame()
     my_frame._getline = Dingus()
     my_frame._getline.return_value = None
     ret_value = my_frame.parse_frame()
     assert ret_value is None
Ejemplo n.º 14
0
class WhenParsingFrames(DingusTestCase(Frame,
        exclude=["UnknownBrokerResponseError", "BrokerErrorResponse"])):

    def setup(self):
        super(WhenParsingFrames, self).setup()
        self.frame = Frame()
        self.sockobj = frame.socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    def should_parse_headers(self):
        header = 'destination:/queue/nose_test'
        parsed = self.frame.parse_headers(header)

        assert isinstance(parsed, type({}))

    def should_parse_command(self):
        command_str = 'CONNECT\nsession:ID:nose-session123'
        command = self.frame.parse_command(command_str)

        assert isinstance(command, type(''))

    def should_set_bytes_message(self):
        my_frame = Frame()
        my_frame._getline = Dingus()
        body = 'Test 1'
        my_frame._getline.return_value = (
                'MESSAGE\nsession:ID:nose-session123'
                '\ncontent-length:%d\n\n%s\x00\n' % (len(body), body))
        this_frame = my_frame.parse_frame()

        assert 'bytes_message' in this_frame.headers

    def should_get_line(self):
        command = 'CONNECTED'
        headers = {'session': 'ID:nose-session123'}
        body = '\x00'
        my_frame = Frame()
        self.frame.parse_frame = Dingus()
        this_frame = my_frame.build_frame({'command': command,
                                           'headers': headers,
                                           'body': body})
        self.frame.parse_frame.return_value = this_frame
        self.frame.connect(self.sockobj.connect(('localhost', 99999)))
        header = "session:%(session)s\n" % headers
        ret = '\n'.join([command, header, body])
        self.frame.sock.recv.return_value = ret
        self.frame._getline()

        assert self.frame.sock.calls('recv', 1)

    def should_not_get_line(self):
        my_frame = Frame()
        my_frame._getline = Dingus()
        my_frame._getline.return_value = None
        ret_value = my_frame.parse_frame()
        assert ret_value is None

    def should_fail_to_get_headers(self):
        my_frame = Frame()
        my_frame._getline = Dingus()
        my_frame._getline.return_value = \
                'RECEIPTreceipt-id:ID:nose-receipt123'

        nose_tools.assert_raises(UnknownBrokerResponseError,
            my_frame.parse_frame)

    def should_get_error_from_broker(self):
        my_frame = Frame()
        my_frame._getline = Dingus()
        command = 'ERROR'
        header = 'message:Illegal command'
        body = 'Error Message'
        my_frame._getline.return_value = \
            '%s\n%s\ncontent-length:%d\n\n%s\n\x00' % (command,
                                                       header,
                                                       len(body),
                                                       body)

        nose_tools.assert_raises(BrokerErrorResponse, my_frame.parse_frame)

    def should_return_frame_repr(self):
        my_frame = Frame()
        assert isinstance(repr(my_frame), type(''))
Ejemplo n.º 15
0
 def should_not_get_line(self):
     my_frame = Frame()
     my_frame._getline = Dingus()
     my_frame._getline.return_value = None
     ret_value = my_frame.parse_frame()
     assert ret_value is None
Ejemplo n.º 16
0
class WhenParsingFrames(
        DingusTestCase(
            Frame,
            exclude=["UnknownBrokerResponseError", "BrokerErrorResponse"])):
    def setup(self):
        super(WhenParsingFrames, self).setup()
        self.frame = Frame()
        self.sockobj = frame.socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    def should_parse_headers(self):
        header = 'destination:/queue/nose_test'
        parsed = self.frame.parse_headers(header)

        assert isinstance(parsed, type({}))

    def should_parse_command(self):
        command_str = 'CONNECT\nsession:ID:nose-session123'
        command = self.frame.parse_command(command_str)

        assert isinstance(command, type(''))

    def should_set_bytes_message(self):
        my_frame = Frame()
        my_frame._getline = Dingus()
        body = 'Test 1'
        my_frame._getline.return_value = ('MESSAGE\nsession:ID:nose-session123'
                                          '\ncontent-length:%d\n\n%s\x00\n' %
                                          (len(body), body))
        this_frame = my_frame.parse_frame()

        assert 'bytes_message' in this_frame.headers

    def should_get_line(self):
        command = 'CONNECTED'
        headers = {'session': 'ID:nose-session123'}
        body = '\x00'
        my_frame = Frame()
        self.frame.parse_frame = Dingus()
        this_frame = my_frame.build_frame({
            'command': command,
            'headers': headers,
            'body': body
        })
        self.frame.parse_frame.return_value = this_frame
        self.frame.connect(self.sockobj.connect(('localhost', 99999)))
        header = "session:%(session)s\n" % headers
        ret = '\n'.join([command, header, body])
        self.frame.sock.recv.return_value = ret
        self.frame._getline()

        assert self.frame.sock.calls('recv', 1)

    def should_not_get_line(self):
        my_frame = Frame()
        my_frame._getline = Dingus()
        my_frame._getline.return_value = None
        ret_value = my_frame.parse_frame()
        assert ret_value is None

    def should_fail_to_get_headers(self):
        my_frame = Frame()
        my_frame._getline = Dingus()
        my_frame._getline.return_value = \
                'RECEIPTreceipt-id:ID:nose-receipt123'

        nose_tools.assert_raises(UnknownBrokerResponseError,
                                 my_frame.parse_frame)

    def should_get_error_from_broker(self):
        my_frame = Frame()
        my_frame._getline = Dingus()
        command = 'ERROR'
        header = 'message:Illegal command'
        body = 'Error Message'
        my_frame._getline.return_value = \
            '%s\n%s\ncontent-length:%d\n\n%s\n\x00' % (command,
                                                       header,
                                                       len(body),
                                                       body)

        nose_tools.assert_raises(BrokerErrorResponse, my_frame.parse_frame)

    def should_return_frame_repr(self):
        my_frame = Frame()
        assert isinstance(repr(my_frame), type(''))