diff --git a/crtools/crtools.py b/crtools/crtools.py
index fad6d54..5b65c01 100644
--- a/crtools/crtools.py
+++ b/crtools/crtools.py
@@ -21,6 +21,11 @@
HISTORY_FILE_NAME = 'history.json'
+MAX_CLAN_SIZE = 50
+
+SUGGESTION_RECRUIT ='Recruit new members! The team needs some fresh blood.'
+SUGGESTION_NO_SUGGESTIONS = 'No suggestions at this time. The clan is in good order.'
+
logger = logging.getLogger(__name__)
def write_object_to_file(file_path, obj):
@@ -201,13 +206,13 @@ def war_score(config, war):
return war_score
-def get_suggestions(config, members):
+def get_suggestions(config, processed_members):
""" Returns list of suggestions for the clan leadership to perform.
Suggestions are to kick, demote, or promote. Suggestions are based on
user score, and various thresholds in configuration. """
# sort members by score, and preserve trophy order if relevant
- members_by_score = sorted(members, key=lambda k: (k['score'], k['trophies']))
+ members_by_score = sorted(processed_members, key=lambda k: (k['score'], k['trophies']))
logger.debug("min_clan_size: {}".format(config['score']['min_clan_size']))
logger.debug("# members: {}".format(len(members_by_score)))
@@ -237,10 +242,10 @@ def get_suggestions(config, members):
# If there are no other suggestions, give some sort of message
if len(suggestions) == 0:
- if config['score']['min_clan_size'] >= len(members_by_score):
- suggestions.append('Recruit new members! The team needs some fresh blood.')
+ if len(members_by_score) < MAX_CLAN_SIZE:
+ suggestions.append(SUGGESTION_RECRUIT)
else:
- suggestions.append('No suggestions at this time. The clan is in good order.')
+ suggestions.append(SUGGESTION_NO_SUGGESTIONS)
return suggestions
diff --git a/tests/test_crtools.py b/tests/test_crtools.py
index 905796f..94de949 100644
--- a/tests/test_crtools.py
+++ b/tests/test_crtools.py
@@ -1,9 +1,10 @@
from datetime import datetime, timedelta
+import copy
import json
import os
import shutil
-from crtools import crtools, load_config_file
+from crtools import crtools, load_config_file, history
CLAN_TAG = '#FakeClanTag'
@@ -86,6 +87,19 @@
"name": "Arena 7"
},
"join_date": 0
+ },
+ {
+ "tag": "#EEEEEE",
+ "name": "MemberPersonToBePromoted",
+ "role": "member",
+ "expLevel": 8,
+ "trophies": 2144,
+ "donations": 100000000,
+ "arena": {
+ "id": 54000008,
+ "name": "Arena 7"
+ },
+ "join_date": 0
}
]
}
@@ -353,6 +367,78 @@ def test_get_scoring_rules(tmpdir):
assert rules[4]['yes_status'] == 'good'
assert rules[4]['no_status'] == 'normal'
+def test_get_suggestions_recruit(tmpdir):
+ config_file = tmpdir.mkdir('test_get_suggestions').join('testfile')
+ config_file.write(__config_file_score__ + '\nthreshold_demote=-999999\nthreshold_promote=9999999')
+ config = load_config_file(config_file.realpath())
+
+ h = history.get_member_history(__fake_clan__['memberList'], None)
+
+ members = crtools.process_members(config, __fake_clan__, __fake_warlog__, {"state": "notInWar"}, h)
+
+ suggestions = crtools.get_suggestions(config, members)
+
+ print(suggestions)
+
+ assert len(suggestions) == 1
+ assert suggestions[0] == crtools.SUGGESTION_RECRUIT
+
+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
+ })
+
+ suggestions = crtools.get_suggestions(config, members)
+
+ assert len(suggestions) == 1
+ assert suggestions[0] == crtools.SUGGESTION_NO_SUGGESTIONS
+
+def test_get_suggestions_kick(tmpdir):
+ config_file = tmpdir.mkdir('test_get_suggestions').join('testfile')
+ config_file.write(__config_file_score__ + '\nmin_clan_size=1')
+ config = load_config_file(config_file.realpath())
+
+ h = history.get_member_history(__fake_clan__['memberList'], None)
+
+ members = crtools.process_members(config, __fake_clan__, __fake_warlog__, {"state": "notInWar"}, h)
+
+ suggestions = crtools.get_suggestions(config, members)
+
+ print(suggestions)
+
+ assert suggestions[0].startswith('Kick')
+ assert members[3]['name'] in suggestions[0]
+
+def test_get_suggestions_promote_demote(tmpdir):
+ config_file = tmpdir.mkdir('test_get_suggestions').join('testfile')
+ config_file.write(__config_file_score__ + '\nthreshold_promote=10')
+ config = load_config_file(config_file.realpath())
+
+ h = history.get_member_history(__fake_clan__['memberList'], None)
+
+ members = crtools.process_members(config, __fake_clan__, __fake_warlog__, {"state": "notInWar"}, h)
+
+ suggestions = crtools.get_suggestions(config, members)
+
+ print(suggestions)
+
+ assert suggestions[0].startswith('Demote')
+ assert members[2]['name'] in suggestions[0]
+ assert suggestions[1].startswith('Promote')
+ assert members[4]['name'] in suggestions[1]
+
def test_process_clan(tmpdir):
config_file = tmpdir.mkdir('test_process_clan').join('testfile')
config_file.write(__config_file_score__)