コード例 #1
0
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 = {
        'state':
        'collectionDay',
        'collection_end_time':
        datetime.utcnow().strftime("%Y%m%dT%H%M%S.xxxx"),
        'participants': [{
            'name': 'AAA',
            'tag': '#AAA',
            'battles_played': 1,
            'number_of_battles': 3
        }, {
            'name': 'BBB',
            'tag': '#BBB',
            'battles_played': 1,
            'number_of_battles': 3
        }]
    }

    fake_members = [{'tag': '#AAA'}]

    assert discord.send_war_nag(config, fake_current_war,
                                fake_members) == False
コード例 #2
0
def test_get_role_label():
    config = load_config_file(False)

    assert crtools.get_role_label(
        config, 'member', 0, 'good', False, True,
        False) == config['strings']['roleBlacklisted']
    assert crtools.get_role_label(
        config, 'leader', 100, 'bad', True, True,
        False) == config['strings']['roleBlacklisted']
    assert crtools.get_role_label(config, 'leader', 100, 'bad', True, False,
                                  False) == config['strings']['roleVacation']
    assert crtools.get_role_label(
        config, 'leader', 100, 'bad', False, False,
        False) == config['strings']['roleInactive'].format(days=100)

    assert crtools.get_role_label(config, 'leader', 0, 'good', False, False,
                                  False) == config['strings']['roleLeader']
    assert crtools.get_role_label(config, 'coLeader', 0, 'good', False, False,
                                  False) == config['strings']['roleCoLeader']
    assert crtools.get_role_label(config, 'elder', 0, 'good', False, False,
                                  False) == config['strings']['roleElder']
    assert crtools.get_role_label(config, 'member', 0, 'good', False, False,
                                  False) == config['strings']['roleMember']

    assert crtools.get_role_label(config, 'leader', 0, 'good', False, False,
                                  True) == config['strings']['roleNoPromote']
コード例 #3
0
def test_process_current_war_nowar():
    config = load_config_file(False)

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

    assert war.state_label == 'The clan is not currently engaged in a war.'
コード例 #4
0
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_clan_size={}'
        .format(crtools.MAX_CLAN_SIZE))
    config = load_config_file(config_file.realpath())

    members = []
    for i in range(0, crtools.MAX_CLAN_SIZE):
        members.append({
            "role": "leader",
            "trophies": 9999,
            "donations": 999,
            "score": 999,
            "vacation": False,
            "safe": True,
            "blacklist": False,
            "no_promote": False
        })

    suggestions = crtools.get_suggestions(config, members, __fake_clan__)

    assert len(suggestions) == 1
    assert suggestions[0] == config['strings']['suggestionNone']
コード例 #5
0
def test_get_scoring_rules(tmpdir):
    config_file = tmpdir.mkdir('test_get_scoring_rules').join('testfile')
    config_file.write(__config_file_score__)
    config = load_config_file(config_file.realpath())

    rules = crtools.get_scoring_rules(config)

    assert rules[0]['yes'] == 0
    assert rules[0]['no'] == -1
    assert rules[0]['yes_status'] == 'normal'
    assert rules[0]['no_status'] == 'bad'
    assert rules[1]['yes'] == 0
    assert rules[1]['no'] == -5
    assert rules[1]['yes_status'] == 'normal'
    assert rules[1]['no_status'] == 'bad'
    assert rules[2]['yes'] == 2
    assert rules[2]['no'] == 0
    assert rules[2]['yes_status'] == 'good'
    assert rules[2]['no_status'] == 'normal'
    assert rules[3]['yes'] == 15
    assert rules[3]['no'] == -30
    assert rules[3]['yes_status'] == 'good'
    assert rules[3]['no_status'] == 'bad'
    assert rules[4]['yes'] == 5
    assert rules[4]['no'] == 0
    assert rules[4]['yes_status'] == 'good'
    assert rules[4]['no_status'] == 'normal'
コード例 #6
0
def test_war_score(tmpdir):
    # FIXME: should replace once we test crtools.process_members()
    war_complete = {
        "battles_played": 1,
        "wins": 1,
        "collection_day_battles_played": 3,
        "collectionBattleWins": 2,
        "collectionBattleLosses": 0,
        "status": "na"
    }
    war_incomplete = {
        "battles_played": 0,
        "wins": 0,
        "collection_day_battles_played": 3,
        "collectionBattleWins": 2,
        "collectionBattleLosses": 0,
        "status": "na"
    }
    war_na = {"status": "na"}
    war_new = {"status": "not-in-clan"}

    config_file = tmpdir.mkdir('test_war_score').join('testfile')
    config_file.write(__config_file_score__)
    config = load_config_file(config_file.realpath())

    assert crtools.war_score(config, war_complete) == 24
    assert crtools.war_score(config, war_incomplete) == -26
    assert crtools.war_score(config, war_na) == -1
    assert crtools.war_score(config, war_new) == 0
コード例 #7
0
def test_get_role_label():
    config = load_config_file(False)

    factory = MemberFactory(config, None, None, None)

    vacation_end = 999999999999999999

    assert factory.get_role_label(
        'member', 0, 'good', MemberVacation(tag='#AAA'), True,
        False) == config['strings']['roleBlacklisted']
    assert factory.get_role_label(
        'leader', 100, 'bad', MemberVacation(tag='#AAA'), True,
        False) == config['strings']['roleBlacklisted']
    assert factory.get_role_label('leader', 100, 'bad',
                                  MemberVacation(tag='#AAA'), False,
                                  False) == config['strings']['roleVacation']
    assert factory.get_role_label(
        'leader', 100, 'bad', None, False,
        False) == config['strings']['roleInactive'].format(days=100)

    assert factory.get_role_label('leader', 0, 'good', None, False,
                                  False) == config['strings']['roleLeader']
    assert factory.get_role_label('coLeader', 0, 'good', None, False,
                                  False) == config['strings']['roleCoLeader']
    assert factory.get_role_label('elder', 0, 'good', None, False,
                                  False) == config['strings']['roleElder']
    assert factory.get_role_label('member', 0, 'good', None, False,
                                  False) == config['strings']['roleMember']

    assert factory.get_role_label('leader', 0, 'good', None, False,
                                  True) == config['strings']['roleNoPromote']
コード例 #8
0
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 = pyroyale.WarCurrent(
        state='collectionDay',
        collection_end_time=datetime.utcnow().strftime("%Y%m%dT%H%M%S.xxxx"),
        participants=[
            pyroyale.WarParticipant(name='AAA',
                                    tag='#AAA',
                                    battles_played=1,
                                    number_of_battles=3),
            pyroyale.WarParticipant(name='BBB',
                                    tag='#BBB',
                                    battles_played=1,
                                    number_of_battles=3)
        ])

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

    assert discord.send_war_nag(config, fake_current_war,
                                fake_members) == False
コード例 #9
0
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, {'state': 'notInWar'}, None) == True
コード例 #10
0
def test_process_current_war_nowar():
    config = load_config_file(False)

    processed_current_war = crtools.process_current_war(
        config, {"state": "notInWar"})

    assert processed_current_war[
        'stateLabel'] == 'The clan is not currently engaged in a war.'
コード例 #11
0
def test_get_member_data_from_sheets_no_google_doc_config_does_nothing():
    config = load_config_file()

    config = gdoc.get_member_data_from_sheets(config)

    assert config['members']['blacklist'] == {}
    assert config['members']['no_promote'] == {}
    assert config['members']['vacation'] == {}
コード例 #12
0
def test_process_current_war_collection():
    config = load_config_file(False)

    processed_current_war = crtools.process_current_war(
        config, __fake_currentwar_collectionday__)

    assert 'collectionEndTimeLabel' in processed_current_war
    assert 'endLabel' in processed_current_war
コード例 #13
0
def test_trigger_webhooks_no_url_returns_false(tmpdir):
    config_file = tmpdir.mkdir(
        'test_trigger_webhooks_no_url_returns_false').join('testfile')
    config_file.write('')
    config = load_config_file(config_file.realpath())

    result = discord.trigger_webhooks(config, None, None)

    assert result == False
コード例 #14
0
def test_config_unknown_key(tmpdir):
    """ Sections and properties in INI files should never be added to
    config object if they aren't in the template """
    config_file = tmpdir.mkdir('test_config_unknown_key').join('config.ini')
    config_file.write(__config_file_unknown_key)

    config = load_config_file(config_file.realpath())

    assert ('garbage' in config) == False
コード例 #15
0
def test_config_debug(tmpdir):
    """ Sections and properties in INI files should never be added to
    config object if they aren't in the template """
    config_file = tmpdir.mkdir('test_config_unknown_key').join('config.ini')
    config_file.write(__config_debug)

    config = load_config_file(config_file.realpath())

    assert config['crtools']['debug'] == True
コード例 #16
0
def test_calc_donation_status(tmpdir):
    config_file = tmpdir.mkdir('test_calc_donation_status').join('config.ini')
    config_file.write(__config_file_score_donations__)
    config = load_config_file(config_file.realpath())

    assert crtools.calc_donation_status(config, 1000, 100, 6) == 'good'
    assert crtools.calc_donation_status(config, 0, 0, 6) == 'bad'
    assert crtools.calc_donation_status(config, 0, 5, 6) == 'ok'
    assert crtools.calc_donation_status(config, 0, 0, 0) == 'normal'
コード例 #17
0
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, {'state': 'collectionDay'},
                                    None) == True
    assert discord.trigger_webhooks(config, {'state': 'warDay'}, None) == True
コード例 #18
0
def test_calc_activity_status():
    config = load_config_file(False)

    assert crtools.calc_activity_status(config, 0) == 'good'
    assert crtools.calc_activity_status(config, -1) == 'good'
    assert crtools.calc_activity_status(config, 1) == 'na'
    assert crtools.calc_activity_status(config, 3) == 'normal'
    assert crtools.calc_activity_status(config, 7) == 'ok'
    assert crtools.calc_activity_status(config, 400) == 'bad'
コード例 #19
0
def test_process_current_war_warday():
    config = load_config_file(False)

    processed_current_war = crtools.process_current_war(
        config, __fake_currentwar_warday__)

    assert processed_current_war['stateLabel'] == 'War Day'
    assert processed_current_war['collectionEndTimeLabel'] == 'Complete'
    assert 'endLabel' in processed_current_war
コード例 #20
0
def test_calc_member_status(tmpdir):
    config_file = tmpdir.mkdir('test_calc_member_status').join('config.ini')
    config_file.write(__config_file_score_thresholds__)
    config = load_config_file(config_file.realpath())

    assert crtools.calc_member_status(config, -1, False) == 'bad'
    assert crtools.calc_member_status(config, 5, False) == 'ok'
    assert crtools.calc_member_status(config, 10, False) == 'normal'
    assert crtools.calc_member_status(config, 100, False) == 'good'
    assert crtools.calc_member_status(config, 100, True) == 'normal'
コード例 #21
0
def test_bad_locale_defaults_to_default(tmpdir, capsys):
    config_file = tmpdir.mkdir('test_bad_locale_defaults_to_default').join(
        'config.ini')
    bad_locale = 'sdlkjfasldfjalsdfjalsdf'
    config_file.write('[crtools]\nlocale=' + bad_locale)

    config = load_config_file(config_file.realpath(), True)
    out, err = capsys.readouterr()
    expected = LOCALE_NOT_FOUND_ERROR_TEMPLATE.format(bad_locale)
    assert expected in out
コード例 #22
0
def test_calc_activity_status():
    config = load_config_file(False)

    factory = MemberFactory(config, None, None, None)

    assert factory.calc_activity_status(0) == 'good'
    assert factory.calc_activity_status(-1) == 'good'
    assert factory.calc_activity_status(1) == 'na'
    assert factory.calc_activity_status(3) == 'normal'
    assert factory.calc_activity_status(7) == 'ok'
    assert factory.calc_activity_status(400) == 'bad'
コード例 #23
0
def test_process_recent_wars(tmpdir):
    config_file = tmpdir.mkdir('test_process_recent_wars').join('config.ini')
    config_file.write(__config_file__)

    config = load_config_file(config_file.realpath())

    processed_warlog = crtools.process_recent_wars(config, __fake_warlog__)

    assert processed_warlog[0]['clan']['tag'] == CLAN_TAG
    assert processed_warlog[0]['rank'] == 1
    assert processed_warlog[0]['date'] == '2/3'
    assert processed_warlog[0]['trophy_change'] == 999
コード例 #24
0
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 = pyroyale.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
コード例 #25
0
def test_process_recent_wars(tmpdir):
    config_file = tmpdir.mkdir('test_process_recent_wars').join('config.ini')
    config_file.write(__config_file__)

    config = load_config_file(config_file.realpath())

    processed_warlog = crtools.process_recent_wars(config, __fake_warlog__)

    assert processed_warlog[0].clan.tag == CLAN_TAG
    assert processed_warlog[0].rank == 1
    assert processed_warlog[0].date == '2/9'
    assert processed_warlog[0].trophy_change == 111
コード例 #26
0
def test_process_clan(tmpdir):
    config_file = tmpdir.mkdir('test_process_clan').join('testfile')
    config_file.write(__config_file_score__)
    config = load_config_file(config_file.realpath())

    processed_clan = crtools.process_clan(config, __fake_clan__,
                                          __fake_currentwar_warday__)

    assert 'member_list' not in processed_clan
    assert processed_clan['warLeague'] == 'gold'
    assert processed_clan['warLeagueName'] == 'Gold League'
    assert processed_clan['currentWarState'] == 'warDay'
コード例 #27
0
def test_config_paths_empty(tmpdir):
    config_file = tmpdir.mkdir('test_config_paths_empty').join('config.ini')
    config_file.write(
        __config_paths_template__.format(logo=False,
                                         favicon=False,
                                         description=False))
    config = load_config_file(config_file.realpath())

    assert config['paths']['clan_logo'].endswith('/templates/crtools-logo.png')
    assert config['paths']['favicon'].endswith(
        '/templates/crtools-favicon.ico')
    assert config['paths']['description_html_src'] == None
コード例 #28
0
def test_version_update_request_fail(requests_mock, tmpdir):
    mock_object = {}

    requests_mock.get(PYPI_URL, json=mock_object, status_code=500)

    config_file = tmpdir.mkdir('test_config_unknown_key').join('config.ini')
    config_file.write(__config_debug)

    config = load_config_file(config_file.realpath(), True)

    assert config['crtools']['latest_version'] == config['crtools']['version']
    assert config['crtools']['update_available'] == False
コード例 #29
0
def test_member_warlog(tmpdir):
    config_file = tmpdir.mkdir('test_member_warlog').join('testfile')
    config_file.write(__config_file_score__)
    config = load_config_file(config_file.realpath())

    warlog = crtools.member_warlog(config, __fake_clan__['member_list'][0],
                                   __fake_warlog__)
    assert warlog[0]['status'] == 'good'

    warlog = crtools.member_warlog(config, __fake_clan__['member_list'][1],
                                   __fake_warlog__)
    assert warlog[0]['status'] == 'na'
コード例 #30
0
def test_process_current_war_collection():
    config = load_config_file(False)

    war = ProcessedCurrentWar(config=config,
                              current_war=pyroyale.WarCurrent(
                                  state='collectionDay',
                                  collection_end_time='20190209T212846.354Z',
                                  clan=__fake_war_clan__,
                                  participants=__fake_war_participants__))

    assert war.collection_end_time
    assert war.end_label