Example #1
0
    def testAddTeam(self):
        # add a league and a sponsor
        sponsor = self.add_sponsor("Test Import Sponsor")
        league = self.add_league("Test Import League")
        color = "Pink"

        # set the logger
        logging.basicConfig(level=logging.INFO,
                            format='%(asctime)s %(message)s')
        logger = logging.getLogger(__name__)
        lines = ["Sponsor:,{},".format(sponsor['sponsor_name']),
                 "Color:,{},".format(color),
                 "Captain:,Test Captain,",
                 "League:,{},".format(league['league_name']),
                 "Player Name,Player Email,Gender (M/F)"
                 "Laura Visentin,[email protected],F",
                 "Test Captain,[email protected],M",
                 "Test Girl,[email protected],F",
                 "Test Boy,[email protected],M"]
        importer = TeamList(lines, logger=logger, session=MockSession(self))

        # no point checking for errors that were tested above
        importer.add_team()
        self.assertEqual(importer.warnings, ['Team was created'],
                         "Should be no warnings")
Example #2
0
    def testAddTeamAlreadyExists(self):
        """Import a team that already exists"""

        # the testing lines
        sponsor = "Test Import Sponsor"
        color = "Blue"
        captain = "Test Captain"
        league = "Test Import League"
        lines = [
            "{}:,{},".format(BACKGROUND['sponsor_name'], sponsor),
            "{}:,{},".format(BACKGROUND['team_color'], color),
            "{}:,{},".format(BACKGROUND['captain_name'], captain),
            "{}:,{},".format(BACKGROUND['league_name'], league),
            "{},{},{}".format(HEADERS['name'], HEADERS['email'],
                              HEADERS['gender']),
            "Test Captain,[email protected],M",
            "Test Girl,[email protected],F",
            "Test Boy,[email protected],M"
        ]

        # added the needed background
        sponsor = self.add_sponsor(sponsor)
        league = self.add_league(league)
        team = self.add_team(color, sponsor, league, date.today().year)

        # import the a test team
        importer = TeamList(lines, session=TestImportMockSession(self))
        importer.add_team_functional()
        self.assertEqual(importer.warnings, [], "Importing team gave warnings")
        team = Team.query.get(team['team_id'])
        self.assertEqual(len(team.players), 3,
                         "Importing team players were not created")
Example #3
0
    def testImportPlayers(self):
        # add a league and a sponsor
        sponsor = self.add_sponsor("Test Import Sponsor")
        league = self.add_league("Test Import League")
        color = "Pink"
        logging.basicConfig(level=logging.INFO,
                            format='%(asctime)s %(message)s')
        logger = logging.getLogger(__name__)
        lines = ["Sponsor:,{},".format(sponsor['sponsor_name']),
                 "Color:,{},".format(color),
                 "Captain:,Test Captain,",
                 "League:,{},".format(league['league_name']),
                 "Player Name,Player Email,Gender (M/F)"
                 "Laura Visentin,[email protected],F",
                 "Test Captain,[email protected],M",
                 "Test Girl,[email protected],F",
                 "Test Boy,[email protected],M"]
        importer = TeamList(lines, logger=logger, session=MockSession(self))

        # mock the first half
        team_id = self.add_team(color, sponsor, league)['team_id']
        team = DB.session.query(Team).get(team_id)
        importer.team = team
        importer.captain_name = "Test Captain"
        importer.email_index = 1
        importer.name_index = 0
        importer.gender_index = 2

        # if no errors are raised then golden
        importer.import_players(5)
Example #4
0
 def testImportHeaders(self):
     logging.basicConfig(level=logging.INFO,
                     format='%(asctime)s %(message)s')
     logger = logging.getLogger(__name__)
     lines = [   "Sponsor:,Domus,",
                 "Color:,Pink,",
                 "Captain:,Dallas Fraser,",
                 "League:,Monday & Wedneday,",
                 "Player Name,Player Email,Gender (M/F)",]
     importer = TeamList(lines, logger=logger)
     # test a invalid sponsor
     try:
         importer.import_headers()
         self.assertEqual(True, False, "Sponsor does not exist")
     except SponsorDoesNotExist as __:
         pass
     self.addSponsors()
     importer = TeamList(lines, logger=logger)
     # test a invalid league
     try:
         importer.import_headers()
         self.assertEqual(True, False, "League does not exist")
     except LeagueDoesNotExist as __:
         pass
     self.addLeagues()
     importer.import_headers()
     self.assertEqual(importer.captain_name, "Dallas Fraser", "Captain name not set")
     self.assertNotEqual(importer.team, None, "Team no set properly")
Example #5
0
 def testColumnsIndives(self):
     logging.basicConfig(level=logging.INFO,
                     format='%(asctime)s %(message)s')
     logger = logging.getLogger(__name__)
     importer = TeamList([], logger=logger)
     try:
         importer.set_columns_indices("asd,asd,asd".split(","))
         self.assertEqual(True, False, "Should have raised invalid field error")
     except InvalidField as __:
         pass
     # if it runs then should be good
     importer.set_columns_indices("Player Name,Player Email,Gender (M/F)".split(","))
     self.assertEqual(importer.name_index, 0, "Name index not set properly")
     self.assertEqual(importer.email_index, 1, "Email index not set properly")
     self.assertEqual(importer.gender_index, 2, "Gender index not set properly")
Example #6
0
def admin_import_team_list():
    results = {'errors': [], 'success':False, 'warnings': []}
    if not logged_in():
        results['errors'].append("Permission denied")
        return dumps(results)
    file = request.files['file']
    result = None
    if file and allowed_file(file.filename):
        content = (file.read()).decode("UTF-8")
        lines = content.replace("\r", "")
        lines = lines.split("\n")
        team = TeamList(lines)
        team.add_team()
        result = team.warnings
    else:
        raise InvalidField(payload={'detail': "File format not accepted (csv)"})
    return dumps(result)
Example #7
0
def admin_import_team_list():
    results = {'errors': [], 'success': False, 'warnings': []}
    if not logged_in():
        results['errors'].append("Permission denied")
        return dumps(results)
    file = request.files['file']
    result = None
    if file and allowed_file(file.filename):
        content = (file.read()).decode("UTF-8")
        lines = content.replace("\r", "")
        lines = lines.split("\n")
        team = TeamList(lines)
        team.add_team()
        result = team.warnings
    else:
        s = "File format not accepted (csv)"
        raise InvalidField(payload={'detail': s})
    return dumps(result)
Example #8
0
    def testAddTeamPlayerAlreadyExists(self):
        """Import a team where one player already exists"""

        # the testing lines
        sponsor = "Test Import Sponsor"
        color = "Blue"
        captain = "Test Captain"
        league = "Test Import League"
        player_email = "*****@*****.**"
        player_name = "Test Girl"
        player_gender = "F"
        lines = [
            "{}:,{},".format(BACKGROUND['sponsor_name'], sponsor),
            "{}:,{},".format(BACKGROUND['team_color'], color),
            "{}:,{},".format(BACKGROUND['captain_name'], captain),
            "{}:,{},".format(BACKGROUND['league_name'], league),
            "{},{},{}".format(HEADERS['name'], HEADERS['email'],
                              HEADERS['gender']),
            "Test Captain,[email protected],M",
            "{},{},{}".format(player_name, player_email, player_gender)
        ]

        # added the needed background
        sponsor = self.add_sponsor(sponsor)
        league = self.add_league(league)
        player = self.add_player(player_name,
                                 player_email,
                                 gender=player_gender)

        # import the a test team
        importer = TeamList(lines, session=TestImportMockSession(self))
        importer.add_team_functional()
        self.assertEqual(importer.warnings, [], "Importing team gave warnings")
        teams = (Team.query.filter(
            func.lower(Team.color) == func.lower(color)).filter(
                Team.sponsor_id == sponsor['sponsor_id']).filter(
                    Team.year == date.today().year)).all()
        self.assertTrue(len(teams) > 0, "Import team was not created")
        team = teams[0]
        self.assertEqual(len(team.players), 2,
                         "Importing team players were not created")
        player_ids = [p.id for p in team.players]
        self.assertTrue(player['player_id'] in player_ids,
                        "Import team existing player not added")
Example #9
0
    def testImportHeaders(self):
        # add a league and a sponsor
        color = "Pink"
        logging.basicConfig(level=logging.INFO,
                            format='%(asctime)s %(message)s')
        logger = logging.getLogger(__name__)
        lines = ["Sponsor:,{},".format("Test Import Sponsor"),
                 "Color:,{},".format(color),
                 "Captain:,Test Captain,",
                 "League:,{},".format("Test Import League"),
                 "Player Name,Player Email,Gender (M/F)"
                 "Laura Visentin,[email protected],F",
                 "Test Captain,[email protected],M",
                 "Test Girl,[email protected],F",
                 "Test Boy,[email protected],M"]
        importer = TeamList(lines, logger=logger, session=MockSession(self))

        # test a invalid sponsor
        try:
            importer.import_headers()
            self.assertEqual(True, False, "Sponsor does not exist")
        except SponsorDoesNotExist as __:
            pass

        # add the sponsor
        self.add_sponsor("Test Import Sponsor")
        importer = TeamList(lines, logger=logger, session=MockSession(self))

        # test a invalid league
        try:
            importer.import_headers()
            self.assertEqual(True, False, "League does not exist")
        except LeagueDoesNotExist as __:
            pass

        # add the league
        self.add_league("Test Import League")
        importer.import_headers()
        self.assertEqual(importer.captain_name,
                         "Test Captain",
                         "Captain name not set")
        self.assertNotEqual(importer.team, None, "Team no set properly")
Example #10
0
 def testAddTeam(self):
     logging.basicConfig(level=logging.INFO,
                     format='%(asctime)s %(message)s')
     logger = logging.getLogger(__name__)
     lines = [   "Sponsor:,Domus,",
                 "Color:,Pink,",
                 "Captain:,Dallas Fraser,",
                 "League:,Monday & Wedneday,",
                 "Player Name,Player Email,Gender (M/F)"
                 "Laura Visentin,[email protected],F",
                 "Dallas Fraser,[email protected],M",
                 "Mitchell Ellul,[email protected],M",
                 "Mitchell Ortofsky,[email protected],M",
                 "Adam Shaver,[email protected],M",
                 "Taylor Takamatsu,[email protected],F",
                 "Jordan Cross,[email protected],M",
                 "Erin Niepage,[email protected],F",
                 "Alex Diakun,[email protected],M",
                 "Kevin Holmes,[email protected],M",
                 "Kevin McGaire,[email protected],M",
                 "Kyle Morrison,[email protected],M",
                 "Ryan Lackey,[email protected],M",
                 "Rory Landy,[email protected],M",
                 "Claudia Vanderholst,[email protected],F",
                 "Luke MacKenzie,[email protected],M",
                 "Jaron Wu,[email protected],M",
                 "Tea Galli,[email protected],F",
                 "Cara Hueston ,[email protected],F",
                 "Derek Schoenmakers,[email protected],M",
                 "Marni Shankman,[email protected],F",
                 "Christie MacLeod ,[email protected],F"
                 ]
     importer = TeamList(lines, logger=logger)
     self.addLeagues()
     self.addSponsors()
     # no point checking for errors that were tested above
     importer.add_team()
     self.assertEqual(importer.warnings, ['Team was created'],
                      "Should be no warnings")
Example #11
0
 def testImportPlayers(self):
     logging.basicConfig(level=logging.INFO,
                     format='%(asctime)s %(message)s')
     logger = logging.getLogger(__name__)
     lines = [   "Sponsor:,Domus,",
                 "Color:,Pink,",
                 "Captain:,Dallas Fraser,",
                 "League:,Monday & Wedneday,",
                 "Player Name,Player Email,Gender (M/F)"
                 "Laura Visentin,[email protected],F",
                 "Dallas Fraser,[email protected],M",
                 "Mitchell Ellul,[email protected],M",
                 "Mitchell Ortofsky,[email protected],M",
                 "Adam Shaver,[email protected],M",
                 "Taylor Takamatsu,[email protected],F",
                 "Jordan Cross,[email protected],M",
                 "Erin Niepage,[email protected],F",
                 "Alex Diakun,[email protected],M",
                 "Kevin Holmes,[email protected],M",
                 "Kevin McGaire,[email protected],M",
                 "Kyle Morrison,[email protected],M",
                 "Ryan Lackey,[email protected],M",
                 "Rory Landy,[email protected],M",
                 "Claudia Vanderholst,[email protected],F",
                 "Luke MacKenzie,[email protected],M",
                 "Jaron Wu,[email protected],M",
                 "Tea Galli,[email protected],F",
                 "Cara Hueston ,[email protected],F",
                 "Derek Schoenmakers,[email protected],M",
                 "Marni Shankman,[email protected],F",
                 "Christie MacLeod ,[email protected],F"
                 ]
     importer = TeamList(lines, logger=logger)
     # mock the first half
     self.addTeams()
     importer.team = self.teams[0]
     importer.captain_name = "Dakkas Fraser"
     importer.email_index = 1
     importer.name_index = 0
     importer.gender_index = 2
     # if no errors are raised then golden
     importer.import_players(5)
Example #12
0
    def testColumnsIndives(self):
        logging.basicConfig(level=logging.INFO,
                            format='%(asctime)s %(message)s')
        logger = logging.getLogger(__name__)
        importer = TeamList([], logger=logger, session=MockSession(self))
        try:
            importer.set_columns_indices("asd,asd,asd".split(","))
            self.assertEqual(True, False,
                             "Should have raised invalid field error")
        except InvalidField as __:
            pass

        # if it runs then should be good
        importer.set_columns_indices("Player Name,Player Email,Gender (M/F)"
                                     .split(","))
        self.assertEqual(importer.name_index, 0,
                         "Name index not set properly")
        self.assertEqual(importer.email_index, 1,
                         "Email index not set properly")
        self.assertEqual(importer.gender_index, 2,
                         "Gender index not set properly")