Ejemplo n.º 1
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']
            })
Ejemplo n.º 2
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)
Ejemplo n.º 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']})
Ejemplo n.º 4
0
    def test_new_token(self):
        # POSTing gets a new token.
        storage_mock = mock.Mock()
        self.request.registry['storage'] = storage_mock
        storage_mock.new_token.return_value = 'TOKEN'

        response = views.new_token(self.request)
        eq_(response, {'token': 'TOKEN', 'queue': '/queue/TOKEN/'})
Ejemplo n.º 5
0
    def test_get_queues(self):
        token = views.new_token(Request())['token']
        request = Request(post={'token': token, 'domain': 'domain'})
        queue = views.new_queue(request)['queue']

        request = Request(params={'token': token})
        response = views.get_queues(request)
        eq_(response, {'domain': queue})
Ejemplo n.º 6
0
    def test_new_token(self):
        # POSTing gets a new token.
        storage_mock = mock.Mock()
        self.request.registry['storage'] = storage_mock
        storage_mock.new_token.return_value = 'TOKEN'

        response = views.new_token(self.request)
        eq_(response, {'token': 'TOKEN', 'queue': '/queue/TOKEN/'})
Ejemplo n.º 7
0
    def test_get_queues(self):
        token = views.new_token(Request())['token']
        request = Request(post={'token': token, 'domain': 'domain'})
        queue = views.new_queue(request)['queue']

        request = Request(params={'token': token})
        response = views.get_queues(request)
        eq_(response, {'domain': queue})
Ejemplo n.º 8
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')
Ejemplo n.º 9
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)
Ejemplo n.º 10
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']})
Ejemplo n.º 11
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']
            })
Ejemplo n.º 12
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')