<s> '''<STR_LIT>''' <EOL> import pytest <EOL> from pushkin . database import database <EOL> import datetime <EOL> from pushkin import context <EOL> from pushkin import test_config_ini_path <EOL> context . setup_configuration ( test_config_ini_path ) <EOL> @ pytest . fixture <EOL> def setup_database ( ) : <EOL> database . init_db ( ) <EOL> database . create_database ( ) <EOL> def test_devices ( setup_database ) : <EOL> database . process_user_login ( login_id = <NUM_LIT> , language_id = <NUM_LIT:7> , platform_id = <NUM_LIT:1> , device_id = '<STR_LIT>' , device_token = '<STR_LIT>' , <EOL> application_version = <NUM_LIT> ) <EOL> assert list ( database . get_device_tokens ( login_id = <NUM_LIT> ) ) == [ ( <NUM_LIT:1> , '<STR_LIT>' ) ] <EOL> database . process_user_login ( login_id = <NUM_LIT> , language_id = <NUM_LIT:7> , platform_id = <NUM_LIT:1> , device_id = None , device_token = '<STR_LIT>' , <EOL> application_version = <NUM_LIT> ) <EOL> database . process_user_login ( login_id = <NUM_LIT> , language_id = <NUM_LIT:7> , platform_id = <NUM_LIT:1> , device_id = '<STR_LIT>' , device_token = None , <EOL> application_version = <NUM_LIT> ) <EOL> assert list ( database . get_device_tokens ( login_id = <NUM_LIT> ) ) == [ ( <NUM_LIT:1> , '<STR_LIT>' ) ] <EOL> database . process_user_login ( login_id = <NUM_LIT> , language_id = <NUM_LIT:7> , platform_id = <NUM_LIT:1> , device_id = '<STR_LIT>' , device_token = '<STR_LIT>' , <EOL> application_version = <NUM_LIT> ) <EOL> assert list ( database . get_device_tokens ( login_id = <NUM_LIT> ) ) == [ ( <NUM_LIT:1> , '<STR_LIT>' ) ] <EOL> database . process_user_login ( login_id = <NUM_LIT> , language_id = <NUM_LIT:7> , platform_id = <NUM_LIT:1> , device_id = '<STR_LIT>' , device_token = '<STR_LIT>' , <EOL> application_version = <NUM_LIT> ) <EOL> assert list ( database . get_device_tokens ( login_id = <NUM_LIT> ) ) == [ ( <NUM_LIT:1> , '<STR_LIT>' ) , ( <NUM_LIT:1> , '<STR_LIT>' ) ] <EOL> def test_message ( setup_database ) : <EOL> database . process_user_login ( login_id = <NUM_LIT> , language_id = <NUM_LIT:7> , platform_id = <NUM_LIT:1> , device_id = '<STR_LIT>' , device_token = '<STR_LIT>' , <EOL> application_version = <NUM_LIT> ) <EOL> message_1 = database . add_message ( message_name = '<STR_LIT:test>' , language_id = <NUM_LIT:1> , message_title = '<STR_LIT>' , <EOL> message_text = '<STR_LIT>' ) <EOL> localized_message = database . get_localized_message ( login_id = <NUM_LIT> , message_id = message_1 . message_id ) <EOL> assert localized_message . message_title == '<STR_LIT>' <EOL> assert localized_message . message_text == '<STR_LIT>' <EOL> assert localized_message . language_id == <NUM_LIT:1> <EOL> assert localized_message . message . screen == '<STR_LIT>' <EOL> message_2 = database . add_message ( message_name = '<STR_LIT:test>' , language_id = <NUM_LIT:0> , message_title = '<STR_LIT>' , <EOL> message_text = '<STR_LIT>' ) <EOL> localized_message = database . get_localized_message ( login_id = <NUM_LIT> , message_id = message_2 . message_id ) <EOL> assert localized_message . message_title == '<STR_LIT>' <EOL> assert localized_message . message_text == '<STR_LIT>' <EOL> assert localized_message . language_id == <NUM_LIT:1> <EOL> assert localized_message . message . screen == '<STR_LIT>' <EOL> message_3 = database . add_message ( message_name = '<STR_LIT:test>' , language_id = <NUM_LIT:7> , message_title = '<STR_LIT>' , <EOL> message_text = '<STR_LIT>' ) <EOL> localized_message = database . get_localized_message ( login_id = <NUM_LIT> , message_id = message_3 . message_id ) <EOL> assert localized_message . message_title == '<STR_LIT>' <EOL> assert localized_message . message_text == '<STR_LIT>' <EOL> assert localized_message . language_id == <NUM_LIT:7> <EOL> assert localized_message . message . screen == '<STR_LIT>' <EOL> bad_message = database . add_message ( message_name = '<STR_LIT>' , language_id = <NUM_LIT:0> , message_title = '<STR_LIT>' , <EOL> message_text = '<STR_LIT>' ) <EOL> localized_message = database . get_localized_message ( login_id = <NUM_LIT> , message_id = bad_message . message_id ) <EOL> assert localized_message is None <EOL> localized_message = database . get_localized_message ( login_id = <NUM_LIT> , message_id = message_3 . message_id ) <EOL> assert localized_message is None <EOL> database . delete_message ( message_1 . message ) <EOL> assert database . get_message ( '<STR_LIT:test>' ) is None <EOL> def test_user ( setup_database ) : <EOL> login = database . upsert_login ( <NUM_LIT> , <NUM_LIT:7> ) <EOL> assert login == database . get_login ( <NUM_LIT> ) <EOL> device = database . upsert_device ( login_id = login . id , platform_id = <NUM_LIT:1> , device_id = '<STR_LIT>' , device_token = '<STR_LIT>' , <EOL> application_version = <NUM_LIT> , unregistered_ts = datetime . datetime . now ( ) ) <EOL> assert device == login . devices [ <NUM_LIT:0> ] <EOL> database . delete_device ( device ) <EOL> assert len ( login . devices ) == <NUM_LIT:0> <EOL> database . delete_login ( login ) <EOL> assert database . get_login ( <NUM_LIT> ) is None <EOL> def test_unregistered_device ( setup_database ) : <EOL> login = database . upsert_login ( <NUM_LIT> , <NUM_LIT:7> ) <EOL> device = database . upsert_device ( login_id = login . id , platform_id = <NUM_LIT:1> , device_id = '<STR_LIT>' , device_token = '<STR_LIT>' , <EOL> application_version = <NUM_LIT> ) <EOL> assert len ( database . get_device_tokens ( <NUM_LIT> ) . all ( ) ) == <NUM_LIT:1> <EOL> database . update_unregistered_devices ( [ { '<STR_LIT>' : device . login_id , '<STR_LIT>' : device . device_token } ] ) <EOL> assert len ( database . get_device_tokens ( <NUM_LIT> ) . all ( ) ) == <NUM_LIT:0> </s>
