Beispiel #1
0
def test_unregistered_device(setup_database):
    login = database.upsert_login(12345, 7)
    device = database.upsert_device(login_id=login.id, platform_id=1, device_token='123', application_version=1001)
    assert len(database.get_device_tokens(12345)) == 1

    database.update_unregistered_devices([{'login_id': device.login_id, 'device_token': device.device_token}])
    assert len(database.get_device_tokens(12345)) == 0
Beispiel #2
0
def test_login_clears_unregistered(setup_database):
    '''Test that login clears unregistered flag.'''
    login = database.upsert_login(1, 7)
    device = database.upsert_device(login_id=login.id,
                                    platform_id=1,
                                    device_token='100',
                                    application_version=1001)

    # unregister
    database.update_unregistered_devices([{
        'login_id': login.id,
        'device_token': device.device_token
    }])
    for users_device in database.get_devices(login):
        assert users_device.unregistered_ts is not None

    # reregister user with device token
    database.process_user_login(login_id=login.id,
                                language_id=login.language_id,
                                platform_id=device.platform_id,
                                device_token=device.device_token,
                                application_version=device.application_version)

    # reregistered user's device should clear unregistered flag
    for users_device in database.get_devices(login):
        assert users_device.unregistered_ts is None
Beispiel #3
0
def test_unregistered_device(setup_database):
    login = database.upsert_login(12345, 7)
    device = database.upsert_device(login_id=login.id, platform_id=1, device_token='123', application_version=1001)
    assert len(database.get_device_tokens(12345)) == 1

    database.update_unregistered_devices([{'login_id': device.login_id, 'device_token': device.device_token}])
    assert len(database.get_device_tokens(12345)) == 0
Beispiel #4
0
def test_login_clears_unregistered_new_device_token(setup_database):
    '''Test that login clears unregistered flag with new device token set.'''
    login = database.upsert_login(1, 7)
    device = database.upsert_device(login_id=login.id, platform_id=1, device_token='100', application_version=1001)
    # set new device token
    canonical_data = [{'login_id': login.id, 'old_token': device.device_token, 'new_token': '100a'}]
    database.update_canonicals(canonical_data)

    # unregister
    database.update_unregistered_devices([{'login_id': login.id, 'device_token': '100a'}])
    for users_device in database.get_devices(login):
        assert users_device.unregistered_ts is not None
    # reregister user with old device token
    database.process_user_login(login_id=login.id, language_id=login.language_id,
                                platform_id=device.platform_id,
                                device_token=device.device_token,
                                application_version=device.application_version)
    # reregistered user's device should clear unregistered flag
    for users_device in database.get_devices(login):
        assert users_device.unregistered_ts is None

    # unregister
    database.update_unregistered_devices([{'login_id': login.id, 'device_token': '100a'}])
    for users_device in database.get_devices(login):
        assert users_device.unregistered_ts is not None
    # reregister user with device token new
    database.process_user_login(login_id=login.id, language_id=login.language_id,
                                platform_id=device.platform_id,
                                device_token='100a',
                                application_version=device.application_version)
    # reregistered user's device should clear unregistered flag
    for users_device in database.get_devices(login):
        assert users_device.unregistered_ts is None
Beispiel #5
0
 def process(self):
     main_logger = logging.getLogger(config.main_logger_name)
     while True:
         notification = self.task_queue.get()
         try:
             sender = GCMPushSender(config.config, main_logger)
             sender.send_in_batch(notification)
             canonical_ids = sender.get_canonical_ids()
             if len(canonical_ids) > 0:
                 database.update_canonicals(canonical_ids)
             unregistered_devices = sender.get_unregistered_devices()
             if len(unregistered_devices) > 0:
                 database.update_unregistered_devices(unregistered_devices)
         except Exception:
             main_logger.exception("GcmNotificationProcessor failed to send notifications")
         finally:
             self.log_notifications([notification])
Beispiel #6
0
def test_device_overflow(setup_database):
    login_id = 12345
    database.process_user_login(login_id=login_id, language_id=7, platform_id=1, device_token='123', application_version=1007)
    assert list(database.get_device_tokens(login_id=login_id)) == [(1, '123')]
    database.update_canonicals([{'login_id': login_id, 'old_token': '123', 'new_token': '124'}])
    assert list(database.get_device_tokens(login_id=login_id)) == [(1, '124')]
    database.process_user_login(login_id=login_id, language_id=7, platform_id=1, device_token='125', application_version=1007)
    assert list(database.get_device_tokens(login_id=login_id)) == [(1, '124'), (1, '125')]
    database.process_user_login(login_id=login_id, language_id=7, platform_id=1, device_token='126', application_version=1007)
    assert list(database.get_device_tokens(login_id=login_id)) == [(1, '124'), (1, '125'), (1, '126')]
    database.process_user_login(login_id=login_id, language_id=7, platform_id=1, device_token='127', application_version=1007)
    assert list(database.get_device_tokens(login_id=login_id)) == [(1, '125'), (1, '126'), (1, '127')]
    database.update_unregistered_devices([{'login_id': login_id, 'device_token': '126'}])
    assert list(database.get_device_tokens(login_id=login_id)) == [(1, '125'), (1, '127')]
    database.process_user_login(login_id=login_id, language_id=7, platform_id=1, device_token='128', application_version=1007)
    assert list(database.get_device_tokens(login_id=login_id)) == [(1, '125'), (1, '127'), (1, '128')]
    database.process_user_login(login_id=login_id, language_id=7, platform_id=1, device_token='129', application_version=1007)
    assert list(database.get_device_tokens(login_id=login_id)) == [(1, '127'), (1, '128'), (1, '129')]
Beispiel #7
0
 def process(self):
     main_logger = logging.getLogger(config.main_logger_name)
     while True:
         notification = self.task_queue.get()
         try:
             sender = GCMPushSender(config.config, main_logger)
             sender.send_in_batch(notification)
             canonical_ids = sender.get_canonical_ids()
             if len(canonical_ids) > 0:
                 database.update_canonicals(canonical_ids)
             unregistered_devices = sender.get_unregistered_devices()
             if len(unregistered_devices) > 0:
                 database.update_unregistered_devices(unregistered_devices)
         except Exception:
             main_logger.exception(
                 "GcmNotificationProcessor failed to send notifications")
         finally:
             self.log_notifications([notification])
Beispiel #8
0
def test_device_overflow(setup_database):
    login_id = 12345
    database.process_user_login(login_id=login_id, language_id=7, platform_id=1, device_token='123', application_version=1007)
    assert list(database.get_device_tokens(login_id=login_id)) == [(1, '123')]
    database.update_canonicals([{'login_id': login_id, 'old_token': '123', 'new_token': '124'}])
    assert list(database.get_device_tokens(login_id=login_id)) == [(1, '124')]
    database.process_user_login(login_id=login_id, language_id=7, platform_id=1, device_token='125', application_version=1007)
    assert sorted(list(database.get_device_tokens(login_id=login_id))) == [(1, '124'), (1, '125')]
    database.process_user_login(login_id=login_id, language_id=7, platform_id=1, device_token='126', application_version=1007)
    assert sorted(list(database.get_device_tokens(login_id=login_id))) == [(1, '124'), (1, '125'), (1, '126')]
    database.process_user_login(login_id=login_id, language_id=7, platform_id=1, device_token='127', application_version=1007)
    assert sorted(list(database.get_device_tokens(login_id=login_id))) == [(1, '125'), (1, '126'), (1, '127')]
    database.update_unregistered_devices([{'login_id': login_id, 'device_token': '126'}])
    assert sorted(list(database.get_device_tokens(login_id=login_id))) == [(1, '125'), (1, '127')]
    database.process_user_login(login_id=login_id, language_id=7, platform_id=1, device_token='128', application_version=1007)
    assert sorted(list(database.get_device_tokens(login_id=login_id))) == [(1, '125'), (1, '127'), (1, '128')]
    database.process_user_login(login_id=login_id, language_id=7, platform_id=1, device_token='129', application_version=1007)
    assert sorted(list(database.get_device_tokens(login_id=login_id))) == [(1, '127'), (1, '128'), (1, '129')]
Beispiel #9
0
 def update_unregistered_devices(self, unregistered_devices):
     database.update_unregistered_devices(unregistered_devices)
Beispiel #10
0
 def update_unregistered_devices(self, unregistered_devices):
     database.update_unregistered_devices(unregistered_devices)