def test_trigger_webhooks_no_nag_returns_false(tmpdir):
    config_file = tmpdir.mkdir('test_trigger_webhooks_no_nag_returns_false').join('testfile')
    config_file.write(__config_file_no_nag__)
    config = load_config_file(config_file.realpath())

    assert discord.trigger_webhooks(config, pybrawl.WarCurrent(state = 'collectionDay'), None) == True
    assert discord.trigger_webhooks(config, pybrawl.WarCurrent(state = 'warDay'), None) == True
def test_send_war_nag_participants_completed_returns_false_because_url_invalid(tmpdir):

    config_file = tmpdir.mkdir('test_send_war_nag_threshold_not_met_returns_true').join('testfile')
    config_file.write(__config_file__)
    config = load_config_file(config_file.realpath())

    fake_current_war = pybrawl.WarCurrent(
        state               = 'collectionDay',
        collection_end_time = datetime.utcnow().strftime("%Y%m%dT%H%M%S.xxxx"),
        participants        = [
            pybrawl.WarParticipant(
                name              = 'AAA',
                tag               = '#AAA',
                battles_played    = 1,
                number_of_battles = 3
            ),
            pybrawl.WarParticipant(
                name              = 'BBB',
                tag               = '#BBB',
                battles_played    = 1,
                number_of_battles = 3
            )
        ]
    )

    fake_members = [pybrawl.WarParticipant(tag='#AAA')]

    assert discord.send_war_nag(config, fake_current_war, fake_members) == False
def test_process_current_war_nowar():
    config = load_config_file(False)

    war = ProcessedCurrentWar(config=config,
                              current_war=pybrawl.WarCurrent(state='notInWar'))

    assert war.state_label == 'The Club is not currently engaged in a war.'
def test_send_war_nag_war_no_members_returns_true(tmpdir):
    config_file = tmpdir.mkdir('test_send_war_nag_war_no_members_returns_true').join('testfile')
    config_file.write(__config_file__)
    config = load_config_file(config_file.realpath())

    fake_current_war = pybrawl.WarCurrent(
        state        = 'warDay',
        war_end_time = datetime.utcnow().strftime("%Y%m%dT%H%M%S.xxxx"),
        participants = []
    )

    assert discord.send_war_nag(config, fake_current_war, []) == True
def test_process_current_war_collection():
    config = load_config_file(False)

    war = ProcessedCurrentWar(config=config,
                              current_war=pybrawl.WarCurrent(
                                  state='collectionDay',
                                  collection_end_time='20190209T212846.354Z',
                                  Club=__fake_war_club__,
                                  participants=__fake_war_participants__))

    assert war.collection_end_time
    assert war.end_label
Example #6
0
def test_get_war_date():
    raw_date_string = '20190213T000000.000Z'
    test_date = datetime.strptime(
        raw_date_string.split('.')[0], '%Y%m%dT%H%M%S')

    assert warparticipation._get_war_date(
        pybrawl.War(created_date=raw_date_string)) == datetime.timestamp(
            test_date - timedelta(days=1))

    assert warparticipation._get_war_date(
        pybrawl.WarCurrent(
            state='warDay',
            war_end_time=raw_date_string)) == datetime.timestamp(test_date -
                                                                 timedelta(
                                                                     days=2))

    assert warparticipation._get_war_date(
        pybrawl.WarCurrent(
            state='collectionDay',
            collection_end_time=raw_date_string)) == datetime.timestamp(
                test_date - timedelta(days=1))
def test_process_current_war_warday():
    config = load_config_file(False)

    war = ProcessedCurrentWar(config=config,
                              current_war=pybrawl.WarCurrent(
                                  state='warDay',
                                  war_end_time='20190209T212846.354Z',
                                  Club=__fake_war_club__,
                                  participants=__fake_war_participants__,
                                  clubs=[__fake_war_club__]))

    assert war.state_label == 'War Day'
    assert war.collection_end_time_label == 'Complete'
    assert war.end_label
def test_get_suggestions_nosuggestions(tmpdir):
    config_file = tmpdir.mkdir('test_get_suggestions').join('testfile')
    config_file.write(
        __config_file_score__ +
        '\nthreshold_demote=-999999\nthreshold_promote=9999999\nmin_club_size={}'
        .format(bstools.MAX_CLAN_SIZE))
    config = load_config_file(config_file.realpath())

    war = ProcessedCurrentWar(config=config,
                              current_war=pybrawl.WarCurrent(state='notInWar'))
    factory = MemberFactory(config=config,
                            member_history=history.get_member_history(
                                __fake_club__.members,
                                config['bstools']['timestamp'], '{}', war),
                            current_war=war,
                            Club=__fake_club__,
                            warlog=pybrawl.WarLog(items=[]))

    members = []
    for i in range(0, bstools.MAX_CLAN_SIZE):
        member = factory.get_processed_member(
            pybrawl.ClubMember(tag="#AAAAAA",
                               name="PresidentPerson",
                               role="president",
                               explevel=13,
                               trophies=9999,
                               name_color="",
                               last_seen="20190802T154619.000Z"))
        member.safe = True
        members.append(member)

    suggestions = bstools.get_suggestions(config, members,
                                          __fake_club__.required_trophies)

    assert len(suggestions) == 1
    assert suggestions[-1] == config['strings']['suggestionNone']
    war_incomplete.collection_battle_wins = 2
    war_incomplete.collection_battle_losses = 0
    assert calc.get_war_score(war_incomplete) == -26

    war_na = WarParticipation(config=config, member=ProcessedMember(__fake_member_list__[4]), war=__fake_war__)
    assert calc.get_war_score(war_na)         == -1

    war_new = WarParticipation(config=config, member=ProcessedMember(__fake_member_list__[4]), war=__fake_war__)
    war_new.status = 'not-in-Club'
    assert calc.get_war_score(war_new)        == 0

def test_donations_score(tmpdir):
    config_file = tmpdir.mkdir('test_donations_score').join('testfile')
    config_file.write(__config_file_score__)
    config = load_config_file(config_file.realpath())

    calc = ScoreCalculator(config)

    war = ProcessedCurrentWar(config=config, current_war=pybrawl.WarCurrent(state='notInWar'))
    member_history = history.get_member_history(__fake_member_list__, config['bstools']['timestamp'], '{}', war)
    date = datetime(2019, 2, 12, 7, 32, 1, 0)

    member_6 = MemberFactory(config=config, current_war=war, Club=__fake_club__, member_history=member_history, warlog=pybrawl.WarLog(items=[]), days_from_donation_reset=6).get_processed_member(__fake_member_list__[0])
    member_3 = MemberFactory(config=config, current_war=war, Club=__fake_club__, member_history=member_history, warlog=pybrawl.WarLog(items=[]), days_from_donation_reset=3).get_processed_member(__fake_member_list__[0])
    member_0 = MemberFactory(config=config, current_war=war, Club=__fake_club__, member_history=member_history, warlog=pybrawl.WarLog(items=[]), days_from_donation_reset=0).get_processed_member(__fake_member_list__[0])

    assert calc.get_member_donations_score(member_6) == 11
    assert calc.get_member_donations_score(member_3) == 18
    assert calc.get_member_donations_score(member_0) == 31

def test_send_war_nag_not_in_war_returns_false(tmpdir):
    config_file = tmpdir.mkdir('test_send_war_nag_not_in_war_returns_false').join('testfile')
    config_file.write(__config_file__)
    config = load_config_file(config_file.realpath())

    assert discord.send_war_nag(config, pybrawl.WarCurrent(state = 'notInWar'), None) == True