# Path: pushkin/request/requests.py
# class NotificationRequestSingle(AbstractRequest):
#     def __init__(self, login_id, title, content, screen=''):
#         self.login_id = login_id
#         self.title = title
#         self.content = content
#         self.screen = screen
# 
# Path: pushkin/request/requests.py
# class NotificationRequestBatch():
#     """Encapsulates a batch of notifications ready for processing."""
# 
#     def __init__(self, notifications):
#         self.notifications = notifications
# 
#     def process(self):
#         for notification in self.notifications:
#             try:
#                 if self.validate_single(notification):
#                     self.process_single(notification)
#                 else:
#                     context.main_logger.error("Notification proto is not valid: {}".format(notification))
#             except:
#                 context.main_logger.exception("Error while processing notification proto: {}".format(notification))
# 
#     def process_single(self, notification):
#         raw_messages = database.get_raw_messages(notification.login_id, notification.title, notification.content,
#                                                  notification.screen, config.game, config.world_id, config.dry_run)
#         if len(raw_messages) > 0:
#             for raw_message in raw_messages:
#                 context.main_logger.debug("Submitting to NotificationSender: {}".format(raw_message))
#                 context.request_processor.sender_manager.submit(raw_message)
#         else:
#             context.main_logger.debug("No device for user {login_id}, notification not sent".format(login_id=notification.login_id))
# 
#     def validate_single(self, notification):
#         """Validate a single notification proto."""
#         result = True
#         result = result and notification.has_field('login_id')
#         result = result and notification.has_field('title')
#         result = result and notification.has_field('content')
#         return result
# 
#     def __repr__(self):
#         return "NotificationsRequests({})".format(len(self.notifications))
# 
#     def __str__(self):
#         return "NotificationsRequests({})".format(len(self.notifications))
# 
# Path: pushkin/context.py
# PERSIST_LOGGER_PREFFIX = 'persist_'
# def setup_loggers():
# def setup_configuration(configuration_filename):
# def start_processors():
# 
# Path: pushkin/database/database.py
# ENGINE = None
# SESSION = None
# ALEMBIC_CONFIG = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'alembic.ini')
#         ENGINE = create_engine(config.sqlalchemy_url, poolclass=pool.NullPool)
#         SESSION = sessionmaker(bind=ENGINE)
# def init_db():
# def create_database():
# def upgrade_database():
# def get_head_revision():
# def get_current_revision():
# def execute_query(query):
# def execute_query_with_results(query):
# def session_scope():
# def get_device_tokens(login_id):
# def get_raw_messages(login_id, title, content, screen, game, world_id, dry_run, message_id=0, event_ts_bigint=None,
#                      expiry_millis=None, priority=GCM2.PRIORITY_NORMAL, filter_platform_id=None, filter_device_token=None):
# def update_canonicals(canonicals):
# def update_unregistered_devices(unregistered):
# def process_user_login(login_id, language_id, platform_id, device_token, application_version):
# def upsert_login(login_id, language_id):
# def upsert_device(login_id, platform_id, device_token, application_version, unregistered_ts=None):
# def get_all_logins():
# def get_all_message_blacklist():
# def upsert_message_blacklist(login_id, blacklist):
# def get_login(login_id):
# def get_devices(login):
# def delete_login(login):
# def delete_device(device):
# def get_localized_message(login_id, message_id):
# def upsert_message(message_name, cooldown_ts, trigger_event_id, screen, expiry_millis, priority):
# def upsert_message_localization(message_name, language_id, message_title, message_text):
# def add_message(message_name, language_id, message_title, message_text, trigger_event_id=None, cooldown_ts=None,
#                 screen='', expiry_millis=None, priority=GCM2.PRIORITY_NORMAL):
# def get_all_messages():
# def get_message(message_name):
# def get_message_localizations(message):
# def delete_message(message):
# def delete_message_localization(message_localization):
# def get_event_to_message_mapping():
# def get_and_update_messages_to_send(user_message_set):


import pytest
from pushkin.request.requests import NotificationRequestSingle
from pushkin.request.requests import NotificationRequestBatch
from pushkin.context import config
from pushkin.database import database
    notification = NotificationRequestSingle(1338, "Msg title", "Text of a message.", "some_screen_id")
    assert NotificationRequestBatch([notification]).validate_single(notification)


def test_notification_proto_without_login_id(mock_log):
    '''Test that a notification proto without login_id fails validation'''
    notification = NotificationRequestSingle(None, "Msg title", "Text of a message.", "some_screen_id")
    assert not NotificationRequestBatch([notification]).validate_single(notification)


def test_notification_proto_without_title(mock_log):
    '''Test that a notification proto without title fails validation'''
    notification = NotificationRequestSingle(1338, None, "Text of a message.", "some_screen_id")
    assert not NotificationRequestBatch([notification]).validate_single(notification)


def test_notification_proto_empty_title(mock_log):
    '''Test that a notification proto with empty title fails validation'''
    notification = NotificationRequestSingle(1338, "", "Text of a message.", "some_screen_id")
    assert not NotificationRequestBatch([notification]).validate_single(notification)


def test_notification_proto_without_content(mock_log):
    '''Test that a notification proto without content fails validation'''
    notification = NotificationRequestSingle(1338, "Msg title", None, "some_screen_id")
    assert not NotificationRequestBatch([notification]).validate_single(notification)


def test_notification_proto_empty_content(mock_log):
    '''Test that a notification proto with empty content fails validation'''

# Path: pushkin/request/requests.py
# class NotificationRequestSingle(AbstractRequest):
#     def __init__(self, login_id, title, content, screen=''):
#         self.login_id = login_id
#         self.title = title
#         self.content = content
#         self.screen = screen
# 
# Path: pushkin/request/requests.py
# class NotificationRequestBatch():
#     """Encapsulates a batch of notifications ready for processing."""
# 
#     def __init__(self, notifications):
#         self.notifications = notifications
# 
#     def process(self):
#         for notification in self.notifications:
#             try:
#                 if self.validate_single(notification):
#                     self.process_single(notification)
#                 else:
#                     context.main_logger.error("Notification proto is not valid: {}".format(notification))
#             except:
#                 context.main_logger.exception("Error while processing notification proto: {}".format(notification))
# 
#     def process_single(self, notification):
#         raw_messages = database.get_raw_messages(notification.login_id, notification.title, notification.content,
#                                                  notification.screen, config.game, config.world_id, config.dry_run)
#         if len(raw_messages) > 0:
#             for raw_message in raw_messages:
#                 context.main_logger.debug("Submitting to NotificationSender: {}".format(raw_message))
#                 context.request_processor.sender_manager.submit(raw_message)
#         else:
#             context.main_logger.debug("No device for user {login_id}, notification not sent".format(login_id=notification.login_id))
# 
#     def validate_single(self, notification):
#         """Validate a single notification proto."""
#         result = True
#         result = result and notification.has_field('login_id')
#         result = result and notification.has_field('title')
#         result = result and notification.has_field('content')
#         return result
# 
#     def __repr__(self):
#         return "NotificationsRequests({})".format(len(self.notifications))
# 
#     def __str__(self):
#         return "NotificationsRequests({})".format(len(self.notifications))
# 
# Path: pushkin/context.py
# PERSIST_LOGGER_PREFFIX = 'persist_'
# def setup_loggers():
# def setup_configuration(configuration_filename):
# def start_processors():
# 
# Path: pushkin/database/database.py
# ENGINE = None
# SESSION = None
# ALEMBIC_CONFIG = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'alembic.ini')
#         ENGINE = create_engine(config.sqlalchemy_url, poolclass=pool.NullPool)
#         SESSION = sessionmaker(bind=ENGINE)
# def init_db():
# def create_database():
# def upgrade_database():
# def get_head_revision():
# def get_current_revision():
# def execute_query(query):
# def execute_query_with_results(query):
# def session_scope():
# def get_device_tokens(login_id):
# def get_raw_messages(login_id, title, content, screen, game, world_id, dry_run, message_id=0, event_ts_bigint=None,
#                      expiry_millis=None, priority=GCM2.PRIORITY_NORMAL, filter_platform_id=None, filter_device_token=None):
# def update_canonicals(canonicals):
# def update_unregistered_devices(unregistered):
# def process_user_login(login_id, language_id, platform_id, device_token, application_version):
# def upsert_login(login_id, language_id):
# def upsert_device(login_id, platform_id, device_token, application_version, unregistered_ts=None):
# def get_all_logins():
# def get_all_message_blacklist():
# def upsert_message_blacklist(login_id, blacklist):
# def get_login(login_id):
# def get_devices(login):
# def delete_login(login):
# def delete_device(device):
# def get_localized_message(login_id, message_id):
# def upsert_message(message_name, cooldown_ts, trigger_event_id, screen, expiry_millis, priority):
# def upsert_message_localization(message_name, language_id, message_title, message_text):
# def add_message(message_name, language_id, message_title, message_text, trigger_event_id=None, cooldown_ts=None,
#                 screen='', expiry_millis=None, priority=GCM2.PRIORITY_NORMAL):
# def get_all_messages():
# def get_message(message_name):
# def get_message_localizations(message):
# def delete_message(message):
# def delete_message_localization(message_localization):
# def get_event_to_message_mapping():
# def get_and_update_messages_to_send(user_message_set):


# Path: pushkin/tests/request/test_notification_request_batch.py
import pytest
from pushkin.request.requests import NotificationRequestSingle
from pushkin.request.requests import NotificationRequestBatch
from pushkin.context import config
from pushkin.database import database

    notification = NotificationRequestSingle(1338, "Msg title", "Text of a message.", "some_screen_id")
    assert NotificationRequestBatch([notification]).validate_single(notification)


def test_notification_proto_without_login_id(mock_log):
    '''Test that a notification proto without login_id fails validation'''
    notification = NotificationRequestSingle(None, "Msg title", "Text of a message.", "some_screen_id")
    assert not NotificationRequestBatch([notification]).validate_single(notification)


def test_notification_proto_without_title(mock_log):
    '''Test that a notification proto without title fails validation'''
    notification = NotificationRequestSingle(1338, None, "Text of a message.", "some_screen_id")
    assert not NotificationRequestBatch([notification]).validate_single(notification)


def test_notification_proto_empty_title(mock_log):
    '''Test that a notification proto with empty title fails validation'''
    notification = NotificationRequestSingle(1338, "", "Text of a message.", "some_screen_id")
    assert not NotificationRequestBatch([notification]).validate_single(notification)


def test_notification_proto_without_content(mock_log):
    '''Test that a notification proto without content fails validation'''
    notification = NotificationRequestSingle(1338, "Msg title", None, "some_screen_id")
    assert not NotificationRequestBatch([notification]).validate_single(notification)


def test_notification_proto_empty_content(mock_log):
    '''Test that a notification proto with empty content fails validation'''

    notification = NotificationRequestSingle(1338, "Msg title", "", "some_screen_id")