Ejemplo n.º 1
0
    def __init__(self, bot, config, server_service):
        """Initializes the object

        :param bot:
        :param config:
        :param server_service:
        """
        self.bot = bot
        self.config = config
        self.service = NotificationService(config, server_service)

        self.send_server_notification.start()
def test_msg_contains_servers_info(service: NotificationService, test_pop_servers, mention):
    msg = service.create_msg_content(test_pop_servers, mention)

    # Not all A2S server information is used in the messages, so don't iterate over key-item pairs
    isCorrectMsg = True
    for server in test_pop_servers:
        if msg.find(server["server_name"]) == -1:
            isCorrectMsg = False
        if msg.find(server["map"]) == -1:
            isCorrectMsg = False
        if msg.find(str(server["player_count"])) == -1:
            isCorrectMsg = False
        if msg.find(str(server["max_players"])) == -1:
            isCorrectMsg = False

    assert isCorrectMsg
def test_msg_shouldnt_ping_role(service: NotificationService, mention, test_pop_servers):
    service.should_ping_role = False
    msg = service.create_msg_content(test_pop_servers, mention)
    assert msg.find(mention) == -1
def test_empty_servers_notice(service: NotificationService, mention):
    msg = service.create_msg_content([], mention)
    assert msg.find("empty") != -1
def test_returns_edit_notification_if_last_message_and_shouldnt_ping(service: NotificationService):
    service.should_ping_role = False
    notification_type = service.get_notification_type(1, 1, [], False)
    assert notification_type.Edit
def test_returns_new_notification_if_not_last_message(service: NotificationService):
    service.should_ping_role = False
    notification_type = service.get_notification_type(0, 1, [], False)
    assert notification_type.New
def test_returns_new_notification_if_should_ping(service: NotificationService, test_pop_servers):
    service.should_ping_role = True
    notification_type = service.get_notification_type(1, 1, test_pop_servers, False)
    assert notification_type == NotificationType.New
def test_force_updates_doesnt_timeout_pings(service: NotificationService):
    service.get_notification_type(0, 1, [], True)
    assert service.timeout_timer.is_alive() is False
def test_returns_notice_when_forced_and_no_active(service: NotificationService):
    notification_type = service.get_notification_type(0, 1, [], True)
    assert notification_type == NotificationType.Forced
def test_does_nothing_when_no_active(service: NotificationService):
    notification_type = service.get_notification_type(0, 1, [], False)
    assert notification_type == NotificationType.NoNotification
def service(config):
    server_service = ServerService(config)
    service = NotificationService(config, server_service)
    yield service
    del service
def test_msg_should_contain_time(service: NotificationService, test_pop_servers, mention):
    msg = service.create_msg_content(test_pop_servers, mention)
    time = re.search(r'\d{2}:\d{2}', msg)
    assert time is not None
def test_server_over_ping_threshold(service: NotificationService, mention, test_pop_servers):
    service.config["min_ping_players"] = 0
    service.should_ping_role = True
    msg = service.create_msg_content(test_pop_servers, mention)
    assert msg.find(mention) != -1