Пример #1
0
def test_priority(setup_database):
    user_id = 12345
    event_ts_bigint = int(round(time.time() * 1000))
    expiry_millis = 60000
    login = database.upsert_login(user_id, 1)
    device = database.upsert_device(login_id=login.id, platform_id=1, device_token='123', application_version=1001)
    localized_message = database.add_message(message_name='test', language_id=1, message_title='title en',
                                      message_text='text en', priority=GCM2.PRIORITY_NORMAL)
    raw_messages = database.get_raw_messages(
                                login_id=user_id, title=localized_message.message_title,
                                content=localized_message.message_text.format,
                                screen=localized_message.message.screen, game='game', world_id=1,
                                dry_run=True, message_id=localized_message.message_id, event_ts_bigint=event_ts_bigint,
                                priority=localized_message.message.priority
    )
    assert raw_messages[0]['priority'] == GCM2.PRIORITY_NORMAL

    localized_message = database.add_message(message_name='test', language_id=1, message_title='title en',
                                      message_text='text en', priority=GCM2.PRIORITY_HIGH)
    raw_messages = database.get_raw_messages(
                                login_id=user_id, title=localized_message.message_title,
                                content=localized_message.message_text.format,
                                screen=localized_message.message.screen, game='game', world_id=1,
                                dry_run=True, message_id=localized_message.message_id, event_ts_bigint=event_ts_bigint,
                                priority=localized_message.message.priority
    )
    assert raw_messages[0]['priority'] == GCM2.PRIORITY_HIGH
Пример #2
0
def test_priority(setup_database):
    user_id = 12345
    event_ts_bigint = int(round(time.time() * 1000))
    expiry_millis = 60000
    login = database.upsert_login(user_id, 1)
    device = database.upsert_device(login_id=login.id, platform_id=1, device_token='123', application_version=1001)
    localized_message = database.add_message(message_name='test', language_id=1, message_title='title en',
                                      message_text='text en', priority=GCM2.PRIORITY_NORMAL)
    raw_messages = database.get_raw_messages(
                                login_id=user_id, title=localized_message.message_title,
                                content=localized_message.message_text.format,
                                screen=localized_message.message.screen, game='game', world_id=1,
                                dry_run=True, message_id=localized_message.message_id, event_ts_bigint=event_ts_bigint,
                                priority=localized_message.message.priority
    )
    assert raw_messages[0]['priority'] == GCM2.PRIORITY_NORMAL

    localized_message = database.add_message(message_name='test', language_id=1, message_title='title en',
                                      message_text='text en', priority=GCM2.PRIORITY_HIGH)
    raw_messages = database.get_raw_messages(
                                login_id=user_id, title=localized_message.message_title,
                                content=localized_message.message_text.format,
                                screen=localized_message.message.screen, game='game', world_id=1,
                                dry_run=True, message_id=localized_message.message_id, event_ts_bigint=event_ts_bigint,
                                priority=localized_message.message.priority
    )
    assert raw_messages[0]['priority'] == GCM2.PRIORITY_HIGH
Пример #3
0
def test_device_filter(setup_database):
    '''Test that device from device filter is used if specified in event.'''
    user_id = 12345
    event_ts_bigint = int(round(time.time() * 1000))
    login = database.upsert_login(user_id, 1)
    database.upsert_device(login_id=login.id,
                           platform_id=1,
                           device_token='123',
                           application_version=1001)
    database.upsert_device(login_id=login.id,
                           platform_id=2,
                           device_token='456',
                           application_version=1001)
    localized_message = database.add_message(message_name='test',
                                             language_id=1,
                                             message_title='title en',
                                             message_text='text en',
                                             priority=GCM2.PRIORITY_NORMAL)

    raw_messages = database.get_raw_messages(
        login_id=user_id,
        title=localized_message.message_title,
        content=localized_message.message_text.format,
        screen=localized_message.message.screen,
        game='game',
        world_id=1,
        dry_run=True,
        message_id=localized_message.message_id,
        event_ts_bigint=event_ts_bigint,
        priority=localized_message.message.priority,
        filter_platform_id=6,
        filter_device_token='789')
    assert len(raw_messages) == 1
    assert raw_messages[0]['platform'] == 6
    assert raw_messages[0]['receiver_id'] == '789'
Пример #4
0
def test_message(setup_database):
    # user using serbian language
    database.process_user_login(login_id=12345, language_id=7, platform_id=1, device_token='123',
                                application_version=1007)

    # message with english only translation
    message_1 = database.add_message(message_name='test', language_id=1, message_title='title en',
                                      message_text='text en')
    assert message_1.message_id == 1
    localized_message = database.get_localized_message(login_id=12345, message_id=message_1.message_id)
    assert localized_message.message_title == 'title en'
    assert localized_message.message_text == 'text en'
    assert localized_message.language_id == 1
    assert localized_message.message.screen == ''

    # adding other translation different from serbian
    message_2 = database.add_message(message_name='test', language_id=0, message_title='title other',
                                      message_text='text other')
    localized_message = database.get_localized_message(login_id=12345, message_id=message_2.message_id)
    assert localized_message.message_title == 'title en'
    assert localized_message.message_text == 'text en'
    assert localized_message.language_id == 1
    assert localized_message.message.screen == ''

    # adding serbian translation
    message_3 = database.add_message(message_name='test', language_id=7, message_title='title sr',
                                      message_text='text sr')
    localized_message = database.get_localized_message(login_id=12345, message_id=message_3.message_id)
    assert localized_message.message_title == 'title sr'
    assert localized_message.message_text == 'text sr'
    assert localized_message.language_id == 7
    assert localized_message.message.screen == ''

    # message with no english neither serbian translation
    bad_message = database.add_message(message_name='test_bad', language_id=0, message_title='title bad',
                                      message_text='text bad')
    localized_message = database.get_localized_message(login_id=12345, message_id=bad_message.message_id)
    assert localized_message is None

    # user doesn't exist
    localized_message = database.get_localized_message(login_id=12346, message_id=message_3.message_id)
    assert localized_message is None

    # delete a message
    database.delete_message(message_1.message)
    assert database.get_message('test') is None
Пример #5
0
def test_message(setup_database):
    # user using serbian language
    database.process_user_login(login_id=12345, language_id=7, platform_id=1, device_token='123',
                                application_version=1007)

    # message with english only translation
    message_1 = database.add_message(message_name='test', language_id=1, message_title='title en',
                                      message_text='text en')
    assert message_1.message_id == 1
    localized_message = database.get_localized_message(login_id=12345, message_id=message_1.message_id)
    assert localized_message.message_title == 'title en'
    assert localized_message.message_text == 'text en'
    assert localized_message.language_id == 1
    assert localized_message.message.screen == ''

    # adding other translation different from serbian
    message_2 = database.add_message(message_name='test', language_id=0, message_title='title other',
                                      message_text='text other')
    localized_message = database.get_localized_message(login_id=12345, message_id=message_2.message_id)
    assert localized_message.message_title == 'title en'
    assert localized_message.message_text == 'text en'
    assert localized_message.language_id == 1
    assert localized_message.message.screen == ''

    # adding serbian translation
    message_3 = database.add_message(message_name='test', language_id=7, message_title='title sr',
                                      message_text='text sr')
    localized_message = database.get_localized_message(login_id=12345, message_id=message_3.message_id)
    assert localized_message.message_title == 'title sr'
    assert localized_message.message_text == 'text sr'
    assert localized_message.language_id == 7
    assert localized_message.message.screen == ''

    # message with no english neither serbian translation
    bad_message = database.add_message(message_name='test_bad', language_id=0, message_title='title bad',
                                      message_text='text bad')
    localized_message = database.get_localized_message(login_id=12345, message_id=bad_message.message_id)
    assert localized_message is None

    # user doesn't exist
    localized_message = database.get_localized_message(login_id=12346, message_id=message_3.message_id)
    assert localized_message is None

    # delete a message
    database.delete_message(message_1.message)
    assert database.get_message('test') is None
Пример #6
0
def prepare_demodata():
    # add some test users
    database.process_user_login(login_id=1, language_id=1, platform_id=2, device_token='dtoken1', application_version=200)
    database.process_user_login(login_id=2, language_id=1, platform_id=2, device_token='dtoken2', application_version=200)
    database.process_user_login(login_id=3, language_id=1, platform_id=2, device_token='dtoken3', application_version=200)

    # insert messages
    database.add_message('msg1', 1, 'title', 'text', 1)
    database.add_message('msg2', 1, 'title', 'text', 1)
    database.add_message('msg3', 1, 'title', 'text', 2)
    database.add_message('msg4', 1, 'title {title_param}', 'text {text_param}', 3)
def prepare_demodata():
    # add some test users
    database.process_user_login(login_id=1,
                                language_id=1,
                                platform_id=2,
                                device_token='dtoken1',
                                application_version=200)
    database.process_user_login(login_id=2,
                                language_id=1,
                                platform_id=2,
                                device_token='dtoken2',
                                application_version=200)
    database.process_user_login(login_id=3,
                                language_id=1,
                                platform_id=2,
                                device_token='dtoken3',
                                application_version=200)

    # insert messages with and without cooldown
    database.add_message(message_name='no_cooldown',
                         language_id=1,
                         message_title='title en',
                         message_text='text en',
                         trigger_event_id=1)
    database.add_message(message_name='cooldown_slow',
                         language_id=1,
                         message_title='title en',
                         message_text='text en',
                         cooldown_ts=10000)
    database.add_message(message_name='cooldown_fast',
                         language_id=1,
                         message_title='title en',
                         message_text='text en',
                         cooldown_ts=1,
                         trigger_event_id=1)
Пример #8
0
def prepare_demodata():
    # add some test users
    database.process_user_login(login_id=1,
                                language_id=1,
                                platform_id=2,
                                device_id='did1',
                                device_token='dtoken1',
                                application_version=200)
    database.process_user_login(login_id=2,
                                language_id=1,
                                platform_id=2,
                                device_id='did2',
                                device_token='dtoken2',
                                application_version=200)
    database.process_user_login(login_id=3,
                                language_id=1,
                                platform_id=2,
                                device_id='did3',
                                device_token='dtoken3',
                                application_version=200)

    # insert messages
    database.add_message('msg1', 1, 'title', 'text', 1)
    database.add_message('msg2', 1, 'title', 'text', 1)
    database.add_message('msg3', 1, 'title', 'text', 2)
Пример #9
0
def test_device_filter(setup_database):
    '''Test that device from device filter is used if specified in event.'''
    user_id = 12345
    event_ts_bigint = int(round(time.time() * 1000))
    login = database.upsert_login(user_id, 1)
    database.upsert_device(login_id=login.id, platform_id=1, device_token='123', application_version=1001)
    database.upsert_device(login_id=login.id, platform_id=2, device_token='456', application_version=1001)
    localized_message = database.add_message(message_name='test', language_id=1, message_title='title en',
                                      message_text='text en', priority=GCM2.PRIORITY_NORMAL)

    raw_messages = database.get_raw_messages(
        login_id=user_id, title=localized_message.message_title,
        content=localized_message.message_text.format,
        screen=localized_message.message.screen, game='game', world_id=1,
        dry_run=True, message_id=localized_message.message_id, event_ts_bigint=event_ts_bigint,
        priority=localized_message.message.priority, filter_platform_id=6, filter_device_token='789')
    assert len(raw_messages) == 1
    assert raw_messages[0]['platform'] == 6
    assert raw_messages[0]['receiver_id'] == '789'
Пример #10
0
    "Portuguese":
    "Foste desafiado para um jogo amigável! Consegues jogar melhor do que o adversário?",
    "Romanian":
    "Ai fost provocat la un meci amical! Poți juca mai bine decât adversarul?",
    "Russian":
    "Тебе вызвали на товарищеский матч! Сможешь победить?",
    "Serbian":
    "Pozvan si na prijateljsku utakmicu! Možeš li da nadigraš protivnika?",
    "Spanish":
    "¡Has sido retado a un amistoso! ¿Podrás derrotar a tu rival?",
    "Swedish":
    "Du har utmats till en vänskapsmatch! Kan du spela ut motståndaren?",
    "Thai":
    "คุณได้รับคำเชิญให้เล่นแมทช์กระชับมิตร! คุณจะสามารถเอาชนะคู่แข่งได้หรือไม่",
    "Turkish":
    "Dostluk maçına çağrıldın! Rakibini alt edebilir misin?",
    "Vietnamese":
    "Bạn đã được mời đá giao hữu! Bạn có thể đánh bại đối thủ không?",
}
if len(set(translation.keys()) - set(language_map.keys())) == 0:
    for lang, msg in translation.items():
        database.add_message(message_name='friendly_scheduled',
                             language_id=language_map[lang],
                             message_title='Top Eleven 2016',
                             message_text=msg,
                             trigger_event_id=100000,
                             cooldown_ts=60 * 60 * 1000,
                             screen='LiveMatchScene')
else:
    print("ERROR: some languages are missing in language_map")
Пример #11
0
    "French": "On te défie à l'occasion d'une rencontre amicale ! Seras-tu meilleur que ton adversaire ?",
    "German": "Du wurdest zu einem Freundschaftsspiel herausgefordert! Kannst du den Gegner besiegen?",
    "Greek": "Σας κάλεσαν σε φιλικό αγώνα! Μπορείτε να νικήσετε τον αντίπαλο;",
    "Israeli": "הוזמנת למשחק ידידות! האם תצליח לשחק טוב יותר מהיריב?",
    "Indonesian": "Kamu ditantang dalam pertandingan persahabatan! Bisa ungguli lawan?",
    "Italian": "Sei stato invitato a disputare un'amichevole. Riuscirai a battere il tuo avversario?",
    "Japanese": "親善試合の挑戦状が届いた!相手チームに勝てるかな?",
    "South Korean": "친선 경기 초대를 받았습니다! 상대를 꺾을 준비가 되셨나요?",
    "Malayan": "Anda telah dicabar untuk sebuah perlawanan persahabatan! Bolehkah anda mengalahkan pihak lawan?",
    "Norwegian": "Du er blitt utfordret til en vennskapskamp! Kan du vinne over motstanderen?",
    "Polish": "Zostałeś zaproszony do rozegrania meczu towarzyskiego! Pokonasz przeciwnika?",
    "Brazilian": "Você foi desafiado para um amistoso! Consegue superar o adversário?",
    "Portuguese": "Foste desafiado para um jogo amigável! Consegues jogar melhor do que o adversário?",
    "Romanian": "Ai fost provocat la un meci amical! Poți juca mai bine decât adversarul?",
    "Russian": "Тебе вызвали на товарищеский матч! Сможешь победить?",
    "Serbian": "Pozvan si na prijateljsku utakmicu! Možeš li da nadigraš protivnika?",
    "Spanish": "¡Has sido retado a un amistoso! ¿Podrás derrotar a tu rival?",
    "Swedish": "Du har utmats till en vänskapsmatch! Kan du spela ut motståndaren?",
    "Thai": "คุณได้รับคำเชิญให้เล่นแมทช์กระชับมิตร! คุณจะสามารถเอาชนะคู่แข่งได้หรือไม่",
    "Turkish": "Dostluk maçına çağrıldın! Rakibini alt edebilir misin?",
    "Vietnamese": "Bạn đã được mời đá giao hữu! Bạn có thể đánh bại đối thủ không?",
}
if len(set(translation.keys()) - set(language_map.keys())) == 0:
    for lang, msg in translation.items():
        database.add_message(message_name='friendly_scheduled', language_id=language_map[lang],
                             message_title='Top Eleven 2016',
                             message_text=msg, trigger_event_id=100000, cooldown_ts=60 * 60 * 1000,
                             screen='LiveMatchScene')
else:
    print("ERROR: some languages are missing in language_map")