示例#1
0
def test_add_frame_item():
    global has_called_check_method
    has_called_check_method = False

    # assert_called_once_with of Mock Class failes to compare Payload object.
    # So here created custom check method for parameter checking
    def check_add_item_args(token, payload, identifier, expiry, priority):
        default_expiry = int(time.time()) + (60 * 60)

        eq_(token, dummy_token)
        eq_(payload.alert, 'Hey')
        eq_(payload.badge, None)
        eq_(payload.sound, None)
        eq_(payload.custom, {})
        eq_(payload.content_available, False)
        eq_(identifier, 123)
        eq_(priority, 10, 'priority should set default value when skipped')
        eq_(expiry, default_expiry,
            'expiry should set default value when skipped')

        global has_called_check_method
        has_called_check_method = True

    worker = SendWorkerThread(**dummy_setting)
    worker.count = 123
    frame = Frame()
    frame.add_item = check_add_item_args

    worker.add_frame_item(frame, 'myapp', dummy_token, {'alert': 'Hey'})
    ok_(has_called_check_method)
示例#2
0
def test_increment_count():
    q = Queue()
    worker = SendWorkerThread(
        **{
            'task_queue': q,
            'name': 'test_thread',
            'use_sandbox': True,
            'cert_file': 'dummy.cert',
            'key_file': 'dummy.key'
        })
    worker.count = 99
    worker.send = mock.Mock()
    worker.check_error = mock.Mock()
    q.put({
        'appid': 'unittest',
        'token': dummy_token,
        'aps': {
            'alert': 'Hello'
        }
    })
    q.put({
        'appid': 'unittest',
        'token': dummy_token,
        'aps': {
            'alert': 'Woooooooooo'
        }
    })
    worker.main()
    eq_(101, worker.count, 'worker.count should incremented by messages')
示例#3
0
def test_add_frame_item():
    global has_called_check_method
    has_called_check_method = False

    # assert_called_once_with of Mock Class failes to compare Payload object.
    # So here created custom check method for parameter checking
    def check_add_item_args(token, payload, identifier, expiry, priority):
        default_expiry = int(time.time()) + (60 * 60)

        eq_(token, dummy_token)
        eq_(payload.alert, 'Hey')
        eq_(payload.badge, None)
        eq_(payload.sound, None)
        eq_(payload.custom, {})
        eq_(payload.content_available, False)
        eq_(identifier, 123)
        eq_(priority, 10, 'priority should set default value when skipped')
        eq_(expiry, default_expiry, 'expiry should set default value when skipped')

        global has_called_check_method
        has_called_check_method = True

    worker = SendWorkerThread(**dummy_setting)
    worker.count = 123
    frame = Frame()
    frame.add_item = check_add_item_args

    worker.add_frame_item(frame, 'myapp', dummy_token, {'alert': 'Hey'})
    ok_(has_called_check_method)
示例#4
0
def test_add_frame_item_with_full_args():
    global has_called_check_method
    has_called_check_method = False

    # assert_called_once_with of Mock Class failes to compare Payload object.
    # So here created custom check method for parameter checking
    def check_add_item_args(token, payload, identifier, expiry, priority):
        eq_(token, dummy_token)
        eq_(payload.alert, 'Wow')
        eq_(payload.badge, 50)
        eq_(payload.sound, 'bell')
        eq_(payload.custom, {'foo': 'bar'})
        eq_(payload.content_available, True)
        eq_(identifier, 1)
        eq_(priority, 5)
        eq_(expiry, 0)

        global has_called_check_method
        has_called_check_method = True

    worker = SendWorkerThread(**dummy_setting)
    worker.count = 1
    frame = Frame()
    frame.add_item = check_add_item_args

    worker.add_frame_item(frame, 'myapp', dummy_token, {
        'alert': 'Wow',
        'badge': 50,
        'sound': 'bell',
        'custom': {'foo': 'bar'},
        'content_available': True,
    }, expiry=0, priority=5)
    ok_(has_called_check_method)
示例#5
0
def test_add_frame_item_with_full_args():
    global has_called_check_method
    has_called_check_method = False

    # assert_called_once_with of Mock Class failes to compare Payload object.
    # So here created custom check method for parameter checking
    def check_add_item_args(token, payload, identifier, expiry, priority):
        eq_(token, dummy_token)
        eq_(payload.alert, 'Wow')
        eq_(payload.badge, 50)
        eq_(payload.sound, 'bell')
        eq_(payload.custom, {'foo': 'bar'})
        eq_(payload.content_available, True)
        eq_(identifier, 1)
        eq_(priority, 5)
        eq_(expiry, 0)

        global has_called_check_method
        has_called_check_method = True

    worker = SendWorkerThread(**dummy_setting)
    worker.count = 1
    frame = Frame()
    frame.add_item = check_add_item_args

    worker.add_frame_item(frame,
                          'myapp',
                          dummy_token, {
                              'alert': 'Wow',
                              'badge': 50,
                              'sound': 'bell',
                              'custom': {
                                  'foo': 'bar'
                              },
                              'content_available': True,
                          },
                          expiry=0,
                          priority=5)
    ok_(has_called_check_method)
示例#6
0
def test_increment_count():
    q = Queue()
    worker = SendWorkerThread(**{
        'task_queue': q,
        'name': 'test_thread',
        'use_sandbox': True,
        'cert_file': 'dummy.cert',
        'key_file': 'dummy.key'
    })
    worker.count = 99
    worker.send = mock.Mock()
    worker.check_error = mock.Mock()
    q.put({
        'appid': 'unittest',
        'token': dummy_token,
        'aps': {'alert': 'Hello'}
    })
    q.put({
        'appid': 'unittest',
        'token': dummy_token,
        'aps': {'alert': 'Woooooooooo'}
    })
    worker.main()
    eq_(101, worker.count, 'worker.count should incremented by messages')