예제 #1
0
파일: test_views.py 프로젝트: jbalogh/push
 def test_message_validator_no_body(self):
     # A message with no body is invalid.
     request = Request(post={})
     views.message_validator(request)
     assert 'message' not in request.validated
     eq_(len(request.errors), 1)
     eq_(request.errors[0][:-1], ('body', 'body'))
예제 #2
0
파일: test_views.py 프로젝트: jbalogh/push
    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']
            })
예제 #3
0
파일: test_views.py 프로젝트: jbalogh/push
 def test_message_validator_no_body(self):
     # A message with no body is invalid.
     request = Request(post={})
     views.message_validator(request)
     assert 'message' not in request.validated
     eq_(len(request.errors), 1)
     eq_(request.errors[0][:-1], ('body', 'body'))
예제 #4
0
파일: test_views.py 프로젝트: jbalogh/push
    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']})
예제 #5
0
파일: test_views.py 프로젝트: jbalogh/push
    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']})
예제 #6
0
파일: test_views.py 프로젝트: jbalogh/push
    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']
            })
예제 #7
0
파일: test_views.py 프로젝트: jbalogh/push
    def test_message_validator_invalid_key(self):
        # Only valid keys are passed to the view.
        valid = {'title': 'title',
                 'body': 'body',
                 'actionUrl': 'actionUrl',
                 'replaceId': 'replaceId'}

        # All our valid keys make it through.
        request = Request(post=valid)
        views.message_validator(request)
        eq_(request.validated['message'], valid)
        eq_(request.errors, [])

        # Invalid keys are silently discarded.
        invalid = dict(valid)
        invalid['bad'] = 'bad'
        request = Request(post=invalid)
        views.message_validator(request)
        eq_(request.validated['message'], valid)
        eq_(request.errors, [])
예제 #8
0
파일: test_views.py 프로젝트: jbalogh/push
    def test_message_validator_invalid_key(self):
        # Only valid keys are passed to the view.
        valid = {
            'title': 'title',
            'body': 'body',
            'actionUrl': 'actionUrl',
            'replaceId': 'replaceId'
        }

        # All our valid keys make it through.
        request = Request(post=valid)
        views.message_validator(request)
        eq_(request.validated['message'], valid)
        eq_(request.errors, [])

        # Invalid keys are silently discarded.
        invalid = dict(valid)
        invalid['bad'] = 'bad'
        request = Request(post=invalid)
        views.message_validator(request)
        eq_(request.validated['message'], valid)
        eq_(request.errors, [])
예제 #9
0
파일: test_views.py 프로젝트: jbalogh/push
 def test_message_validator_action_read(self):
     # No validation happens if action=read.
     request = Request(post={'action': 'read', 'key': 'k'})
     views.message_validator(request)
     assert 'message' not in request.validated
     eq_(request.errors, [])
예제 #10
0
파일: test_views.py 프로젝트: jbalogh/push
 def test_message_validator_json(self):
     # Messages can be JSON.
     request = Request(body=json.dumps({'title': 'hi'}))
     views.message_validator(request)
     eq_(request.validated['message'], {'title': 'hi'})
     eq_(request.errors, [])
예제 #11
0
파일: test_views.py 프로젝트: jbalogh/push
 def test_message_validator_urlencoded(self):
     # Messages can be form-urlencoded.
     request = Request(post={'title': 'hi'})
     views.message_validator(request)
     eq_(request.validated['message'], {'title': 'hi'})
     eq_(request.errors, [])
예제 #12
0
파일: test_views.py 프로젝트: jbalogh/push
 def test_message_validator_action_read(self):
     # No validation happens if action=read.
     request = Request(post={'action': 'read', 'key': 'k'})
     views.message_validator(request)
     assert 'message' not in request.validated
     eq_(request.errors, [])
예제 #13
0
파일: test_views.py 프로젝트: jbalogh/push
 def test_message_validator_json(self):
     # Messages can be JSON.
     request = Request(body=json.dumps({'title': 'hi'}))
     views.message_validator(request)
     eq_(request.validated['message'], {'title': 'hi'})
     eq_(request.errors, [])
예제 #14
0
파일: test_views.py 프로젝트: jbalogh/push
 def test_message_validator_urlencoded(self):
     # Messages can be form-urlencoded.
     request = Request(post={'title': 'hi'})
     views.message_validator(request)
     eq_(request.validated['message'], {'title': 'hi'})
     eq_(request.errors, [])