def get_group(self, group_name: str) -> Union[Team, bool]: todo_ref = self.db.collection(os.getenv('DISCORD_DB_PATH') + '/groups') if group_name: doc = todo_ref.document(group_name).get() if doc.to_dict(): return Team(doc.to_dict()['name'], doc.to_dict()['members'], doc.to_dict()['role_id']) return None
def setUp(self): """ Setup function to initialize different model lists """ part1 = Part("PARTLIST_5E6B2", "PART_1F2BA", 1386, 50) part2 = Part("PARTLIST_5E6B2", "PART_95365", 1546, 42) part3 = Part("PARTLIST_06D40", "PART_C5965", 2725, 32) part4 = Part("PARTLIST_06D40", "PART_FAEF0", 3834, 25) part5 = Part("PARTLIST_33599", "PART_AC9B8", 3769, 26) car1 = Car("CARID_1402", "MODEL_B1BFE", 124, 160, "PARTLIST_5E6B2") car2 = Car("CARID_7347", "MODEL_39E91", 104, 205, "PARTLIST_06D40") car3 = Car("CARID_3861", "MODEL_3B4C7", 120, 201, "PARTLIST_33599") team1 = Team("0", "Force India", ["CARID_1402", "CARID_7347"], 9000) team2 = Team("2", "Mercedes", ["CARID_3861"], 8770) PartList.parts = [part1, part2, part3, part4, part5] CarList.cars = [car1, car2, car3] TeamList.teams = [team1, team2]
def recover_web_group_by_user(self, email): users_ref = self.db.collection(os.getenv('HACKESP2020_DB_PATH') + '/users') todo_ref = self.db.collection(os.getenv('HACKESP2020_DB_PATH') + '/teams') for grp in todo_ref.stream(): members = grp.to_dict()['members'] for member in members: user = users_ref.document(member.id).get().to_dict() if user['email'] == email: return WebUser(user['accepted'], user['birthDate'], user['displayName'], user['email'], user['fullName'], user['githubUrl'], user['nickname']), Team(grp.to_dict()['name']) return self.recover_web_user(email), None
def test_team_model(self): """ Unittests to test team model """ team = Team("0", "Force India", ["CARID_1402", "CARID_7347"], 9000) self.assertEqual("0", team.get_team_id()) self.assertEqual("Force India", team.get_team_name()) self.assertEqual(["CARID_1402", "CARID_7347"], team.get_cars()) self.assertEqual(9000, team.get_funds())
async def create_command(self, ctx): import src.texts.create_texts as texts user = DB.get_user(discord_id=ctx.message.author.id) if not user: logging.info("[COMMAND CREATE - ERROR] Usuario no registrado") await ctx.send(texts.NOT_REGISTERED_ERROR) return if user.group_name is not None and user.group_name != '': logging.info( "[COMMAND CREATE - ERROR] El usuario ya se encuentra en un grupo" ) await ctx.send(texts.ALREADY_ON_GROUP_ERROR) return command = ctx.message.content.split() if len(command) < 2: logging.info("[COMMAND CREATE - ERROR] La sintaxis es incorrecta") await ctx.send(texts.SINTAXIX_ERROR) return group = DB.get_group(group_name=' '.join(command[1:])) if not group: group = DB.recover_web_group(' '.join(command[1:])) if group: logging.info( "[COMMAND CREATE - ERROR] El grupo indicado ya existe") await ctx.send(texts.GROUP_ALREADY_EXISTS_ERROR) return await ctx.send(texts.STARTING_CREATE_GROUP) group = Team(' '.join(command[1:]), [ctx.message.author.id]) self.create_group_on_server(group, ctx.message.author, ctx.guild) user.group_name = group.name DB.create_or_update_user(user) logging.info("[COMMAND CREATE - OK] Informando all Ok") await ctx.send(texts.CREATED_GROUP) pass
def test_add_allows_multiple_unknowns(self): team = Team([]) team.add('unknown', 0) team.add('lucio', 1) team.add('unknown', 2) self.assertEqual(['unknown', 'lucio', 'unknown'], team.heroes)
def recover_web_group(self, name) -> Union[Team, bool]: todo_ref = self.db.collection(os.getenv('HACKESP2020_DB_PATH') + '/teams') doc = todo_ref.document(name).get() return Team(doc.to_dict()['name']) if doc.to_dict() else None
def test_num_tanks(self): team = Team(['ana', 'dva', 'reinhardt']) self.assertEqual(2, team.num_tanks()) team = Team(['torbjorn', 'mercy', 'lucio', 'soldier76']) self.assertEqual(0, team.num_tanks())
def test_empty_returns_false_when_not_all_unknown(self): team = Team(['unknown', 'genji']) self.assertFalse(team.empty())
def test_size(self): team = Team(['ana', 'dva', 'reinhardt']) self.assertEqual(3, team.size()) team = Team(['ana', 'unknown', 'reinhardt']) self.assertEqual(2, team.size())
def test_empty_returns_true_when_all_unknown(self): team = Team(['unknown', 'unknown', 'unknown']) self.assertTrue(team.empty())
def test_empty_returns_true_when_empty(self): team = Team([]) self.assertTrue(team.empty())
def test_add_disallows_duplicate_heroes(self): team = Team([]) team.add('unknown', 0) team.add('lucio', 1) team.add('lucio', 2) self.assertEqual(['unknown', 'lucio'], team.heroes)
def test_fully_detected(self): team = Team(['ana', 'dva', 'reinhardt']) self.assertFalse(team.fully_detected()) team = Team(['ana', 'dva', 'reinhardt', 'unknown', 'unknown', 'hanzo']) self.assertTrue(team.fully_detected())
def test_num_healers(self): team = Team(['ana', 'dva', 'reinhardt']) self.assertEqual(1, team.num_healers()) team = Team(['widowmaker', 'mercy', 'zenyatta', 'symmetra']) self.assertEqual(2, team.num_healers())
def test_add_orders_heroes_by_position(self): team = Team([]) team.add('mercy', 1) team.add('ana', 0) team.add('reinhardt', 2) self.assertEqual(['ana', 'mercy', 'reinhardt'], team.heroes)
def test_add_adds_heroes(self): team = Team([]) self.assertEqual([], team.heroes) team.add('mercy', 1) self.assertEqual(['mercy'], team.heroes)