Beispiel #1
0
    def test_get_message_read(self, publish_mock):
        # Check the format of the read message marker.
        token = views.new_token(Request(post={}))['token']
        request = Request(post={
            'action': 'read',
            'key': 'key'
        },
                          matchdict={'queue': token})
        response = views.new_message(request)['messages'][0]

        req = Request(matchdict={'queue': token})
        self.assertListEqual(
            views.get_messages(req)['messages'],
            [{
                'body': {
                    'read': 'key'
                },
                'queue': '/queue/%s/' % token,
                'key': response['key'],
                'timestamp': str(response['timestamp'])
            }])

        # The format should match the pubsub'd message.
        expected = views.get_messages(req)['messages'][0]
        publish_mock.assert_called_with(request, token, expected)
Beispiel #2
0
    def test_new_message(self, time_mock, publish_mock):
        # New messages should be in queuey and pubsub.
        token = views.new_token(Request(post={}))['token']
        time_mock.time.return_value = 1
        queue = self.queuey.new_queue()
        self.storage.new_queue(queue, token, 'domain')

        body = {'title': 'title', 'body': 'body'}
        request = Request(matchdict={'queue': queue}, post=body)
        views.message_validator(request)
        response = views.new_message(request)

        # The body is in JSON since queuey just deals with strings.
        self.assertDictEqual(
            self.queuey.get_messages(token)[0],
            {u'body': json.dumps({'queue': queue, 'body': body}),
             u'timestamp': '1',
             u'partition': 1,
             u'message_id': response['messages'][0]['key']})

        publish_mock.assert_called_with(
            request, token, {'queue': '/queue/%s/' % queue,
                             'timestamp': '1',
                             'body': body,
                             'key': response['messages'][0]['key']})
Beispiel #3
0
    def test_new_message(self, time_mock, publish_mock):
        # New messages should be in queuey and pubsub.
        token = views.new_token(Request(post={}))['token']
        time_mock.time.return_value = 1
        queue = self.queuey.new_queue()
        self.storage.new_queue(queue, token, 'domain')

        body = {'title': 'title', 'body': 'body'}
        request = Request(matchdict={'queue': queue}, post=body)
        views.message_validator(request)
        response = views.new_message(request)

        # The body is in JSON since queuey just deals with strings.
        self.assertDictEqual(
            self.queuey.get_messages(token)[0], {
                u'body': json.dumps({
                    'queue': queue,
                    'body': body
                }),
                u'timestamp': '1',
                u'partition': 1,
                u'message_id': response['messages'][0]['key']
            })

        publish_mock.assert_called_with(
            request, token, {
                'queue': '/queue/%s/' % queue,
                'timestamp': '1',
                'body': body,
                'key': response['messages'][0]['key']
            })
Beispiel #4
0
 def test_mark_message_read(self, publish_mock):
     # Check that we can mark a message as read.
     token = views.new_token(Request(post={}))['token']
     request = Request(post={
         'action': 'read',
         'key': 'key'
     },
                       matchdict={'queue': token})
     eq_(views.new_message(request)['status'], 'ok')
Beispiel #5
0
    def test_get_message_read(self, publish_mock):
        # Check the format of the read message marker.
        token = views.new_token(Request(post={}))['token']
        request = Request(post={'action': 'read', 'key': 'key'},
                          matchdict={'queue': token})
        response = views.new_message(request)['messages'][0]

        req = Request(matchdict={'queue': token})
        self.assertListEqual(views.get_messages(req)['messages'],
                             [{'body': {'read': 'key'},
                               'queue': '/queue/%s/' % token,
                               'key': response['key'],
                               'timestamp': str(response['timestamp'])}])

        # The format should match the pubsub'd message.
        expected = views.get_messages(req)['messages'][0]
        publish_mock.assert_called_with(request, token, expected)
Beispiel #6
0
    def test_new_message_json(self, publish_mock):
        # A new message coming through as JSON works fine.
        token = views.new_token(Request(post={}))['token']
        queue = self.storage.new_token()
        self.storage.new_queue(queue, token, 'domain')

        body = {'title': 'title', 'body': 'body'}
        request = Request(matchdict={'queue': queue},
                          body=json.dumps(body))

        views.message_validator(request)
        response = views.new_message(request)
        message = response['messages'][0]
        publish_mock.assert_called_with(
            request, token, {'queue': '/queue/%s/' % queue,
                             'timestamp': message['timestamp'],
                             'body': body,
                             'key': message['key']})
Beispiel #7
0
    def test_new_message_json(self, publish_mock):
        # A new message coming through as JSON works fine.
        token = views.new_token(Request(post={}))['token']
        queue = self.storage.new_token()
        self.storage.new_queue(queue, token, 'domain')

        body = {'title': 'title', 'body': 'body'}
        request = Request(matchdict={'queue': queue}, body=json.dumps(body))

        views.message_validator(request)
        response = views.new_message(request)
        message = response['messages'][0]
        publish_mock.assert_called_with(
            request, token, {
                'queue': '/queue/%s/' % queue,
                'timestamp': message['timestamp'],
                'body': body,
                'key': message['key']
            })
Beispiel #8
0
 def test_mark_message_read_no_key(self):
     request = Request(post={'action': 'read'})
     eq_(views.new_message(request).code, 404)
Beispiel #9
0
 def test_new_message_404(self):
     # POSTing to a queue without an associated token returns a 404.
     request = Request(post={}, matchdict={'queue': 'queue'})
     eq_(views.new_message(request).code, 404)
Beispiel #10
0
 def test_mark_message_read_no_key(self):
     request = Request(post={'action': 'read'})
     eq_(views.new_message(request).code, 404)
Beispiel #11
0
 def test_mark_message_read(self, publish_mock):
     # Check that we can mark a message as read.
     token = views.new_token(Request(post={}))['token']
     request = Request(post={'action': 'read', 'key': 'key'},
                       matchdict={'queue': token})
     eq_(views.new_message(request)['status'], 'ok')
Beispiel #12
0
 def test_new_message_404(self):
     # POSTing to a queue without an associated token returns a 404.
     request = Request(post={}, matchdict={'queue': 'queue'})
     eq_(views.new_message(request).code, 404)