def update(self, name: str = None, link: str = None, description: str = None, active: bool = None) -> None: """Updates an existing sponsor. Raises: InvalidField """ if name is not None and string_validator(name): self.name = name elif name is not None: raise InvalidField(payload={'details': "Sponsor - name"}) if description is not None and string_validator(description): self.description = description elif description is not None: raise InvalidField(payload={'details': "Sponsor - description"}) if link is not None and string_validator(link): self.link = link elif link is not None: raise InvalidField(payload={'details': "Sponsor - link"}) if active is not None and boolean_validator(active): self.active = active elif active is not None: raise InvalidField(payload={'detail': "Player - active"})
def __init__(self, name, email, gender=None, password="******", active=True): """The constructor. Raises: InvalidField NonUniqueEmail """ if not string_validator(name): raise InvalidField(payload={"details": "Player - name"}) # check if email is unique if not string_validator(email): raise InvalidField(payload={'details': "Player - email"}) player = Player.query.filter_by(email=email).first() if player is not None: raise NonUniqueEmail(payload={'details': email}) if gender is not None and not gender_validator(gender): raise InvalidField(payload={'details': "Player - gender"}) self.name = name self.email = email if gender is not None: gender = gender.lower() self.gender = gender self.set_password(password) self.active = active
def update(self, name=None, email=None, gender=None, password=None): ''' updates an existing player Parameters: name: the name of the player email: the unique email of the player gender: the gender of the player password: the password of the player Raises: InvalidField NonUniqueEmail ''' if email is not None: # check if email is unique if not string_validator(email): raise InvalidField(payload="Player - email") player = Player.query.filter_by(email=email).first() if player is not None: raise NonUniqueEmail(payload={'details':email}) self.email = email if gender is not None and gender_validator(gender): self.gender = gender.lower() elif gender is not None: raise InvalidField(payload={'details':"Player - gender"}) if name is not None and string_validator(name): self.name = name elif name is not None: raise InvalidField(payload={'details':"Player - name"})
def __init__(self, name, link=None, description=None, active=True, nickname=None): """The constructor. Raises: InvalidField """ if not string_validator(name): raise InvalidField(payload={'details': "Sponsor - name"}) if not string_validator(link): raise InvalidField(payload={'details': "Sponsor - link"}) if not string_validator(description): raise InvalidField(payload={'details': "Sponsor - description"}) self.name = name self.description = description self.link = link self.active = active if nickname is None: self.nickname = name else: self.nickname = nickname
def __init__(self, name, email, gender=None, password="******", active=True): ''' Raises: InvalidField NonUniqueEmail ''' if not string_validator(name): raise InvalidField(payload={"details": "Player - name"}) # check if email is unique if not string_validator(email): raise InvalidField(payload={'details':"Player - email"}) player = Player.query.filter_by(email=email).first() if player is not None: raise NonUniqueEmail(payload={'details':email}) if gender is not None and not gender_validator(gender): raise InvalidField(payload={'details':"Player - gender"}) self.name = name self.email = email if gender is not None: gender = gender.lower() self.gender = gender self.set_password(password) self.active = active
def testStringValidator(self): # test with a number test = 1 self.assertEqual(string_validator(test), False, 'String Validator: 1 was a valid string') # test with an empty string test = "" self.assertEqual(string_validator(test), False, 'String Validator: "" was a valid string') test = "Bob Saget" self.assertEqual(string_validator(test), True, 'String Validator: Bob Saget was a invalid string')
def __init__(self, name: str, shortname: str = None): """The constructor Raises: InvalidField """ if not string_validator(name): raise InvalidField(payload={'details': "Division - name"}) if shortname is not None and not string_validator(shortname): raise InvalidField(payload={'details': "Division - short name"}) self.name = name self.shortname = shortname
def update(self, name: str = None, shortname: str = None) -> None: """Update an existing division. Raises: InvalidField """ if name is not None and not string_validator(name): raise InvalidField(payload={'details': "Division - name"}) if shortname is not None and not string_validator(shortname): raise InvalidField(payload={'details': "Division - shortname"}) if name is not None: self.name = name if shortname is not None: self.shortname = shortname
def __init__(self, name, link=None, description=None, active=True, nickname=None): if not string_validator(name): raise InvalidField(payload={'details':"Sponsor - name"}) if not string_validator(link): raise InvalidField(payload={'details':"Sponsor - link"}) if not string_validator(description): raise InvalidField(payload={'details':"Sponsor - description"}) self.name = name self.description = description self.link = link self.active = active if nickname is None: self.nickname = name else: self.nickname = nickname
def __init__(self, email: str, name: str, team: 'Team', gender: str): if team is None or not isinstance(team, Team) or team.id is None: raise TeamDoesNotExist("Given team does not exist") if not gender_validator(gender): raise InvalidField(payload={ 'details': "Player League Request - gender"}) if not string_validator(email): raise InvalidField(payload="Player League Request - email") if not string_validator(name): raise InvalidField(payload="Player League Request - name") self.email = email.lower() self.name = name self.team_id = team.id self.pending = True self.gender = gender.lower()
def update(self, color=None, sponsor_id=None, league_id=None, year=None): ''' updates an existing team Raises: InvalidField SponsorDoesNotExist LeagueDoesNotExist ''' # does nothing with espys given if color is not None and string_validator(color): self.color = color elif color is not None: raise InvalidField(payload={'details':"Team - color"}) if sponsor_id is not None and Sponsor.query.get(sponsor_id) is not None: self.sponsor_id = sponsor_id elif sponsor_id is not None: raise SponsorDoesNotExist(payload={'details':sponsor_id}) if league_id is not None and League.query.get(league_id) is not None: self.league_id = league_id elif league_id is not None: raise LeagueDoesNotExist(payload={'details':league_id}) if year is not None and year_validator(year): self.year = year elif year is not None: raise InvalidField(payload={'details':"Team - year"})
def __init__(self, color=None, sponsor_id=None, league_id=None, year=date.today().year): """ The constructor. Raises InvalidField SponsorDoesNotExist LeagueDoesNotExist """ if color is not None and not string_validator(color): raise InvalidField(payload={'details': "Team - color"}) if sponsor_id is not None and Sponsor.query.get(sponsor_id) is None: raise SponsorDoesNotExist(payload={'details': sponsor_id}) if league_id is not None and League.query.get(league_id) is None: raise LeagueDoesNotExist(payload={'details': league_id}) if year is not None and not year_validator(year): raise InvalidField(payload={'details': "Team - year"}) self.color = color self.sponsor_id = sponsor_id self.league_id = league_id self.year = year self.kik = None
def update(self, color=None, sponsor_id=None, league_id=None, year=None): """Updates an existing team. Raises: InvalidField SponsorDoesNotExist LeagueDoesNotExist """ # does nothing with espys given if color is not None and string_validator(color): self.color = color elif color is not None: raise InvalidField(payload={'details': "Team - color"}) if (sponsor_id is not None and Sponsor.query.get(sponsor_id) is not None): self.sponsor_id = sponsor_id elif sponsor_id is not None: raise SponsorDoesNotExist(payload={'details': sponsor_id}) if league_id is not None and League.query.get(league_id) is not None: self.league_id = league_id elif league_id is not None: raise LeagueDoesNotExist(payload={'details': league_id}) if year is not None and year_validator(year): self.year = year elif year is not None: raise InvalidField(payload={'details': "Team - year"})
def __init__(self, date, time, home_team_id, away_team_id, league_id, status="", field=""): ''' Raises: InvalidField TeamDoesNotExist LeagueDoesNotExist ''' # check for all the invalid parameters if not date_validator(date): raise InvalidField(payload={'details':"Game - date"}) if not time_validator(time): raise InvalidField(payload={'details':"Game - time"}) self.date = datetime.strptime(date + "-" +time, '%Y-%m-%d-%H:%M') if (Team.query.get(home_team_id) is None): raise TeamDoesNotExist(payload={'details':home_team_id}) if Team.query.get(away_team_id) is None: raise TeamDoesNotExist(payload={'details':away_team_id}) if League.query.get(league_id) is None: raise LeagueDoesNotExist(payload={'details':league_id}) if ((status != "" and not string_validator(status)) or (field != "" and not field_validator(field))): raise InvalidField(payload={'details':"Game - field/status"}) # must be good now self.home_team_id = home_team_id self.away_team_id = away_team_id self.league_id = league_id self.status = status self.field = field
def __init__(self, name=None): ''' Raises: InvalidField ''' if not string_validator(name): raise InvalidField(payload={'details':"League - name"}) self.name = name
def update(self, league): """Update an existing league. Raises: InvalidField """ if not string_validator(league): raise InvalidField(payload={'details': "League - name"}) self.name = league
def update(self, name=None, link=None, description=None): ''' updates an existing sponsor Raises: InvalidField ''' if name is not None and string_validator(name): self.name = name elif name is not None: raise InvalidField(payload={'details':"Sponsor - name"}) if description is not None and string_validator(description): self.description = description elif description is not None: raise InvalidField(payload={'details':"Sponsor - description"}) if link is not None and string_validator(link): self.link = link elif link is not None: raise InvalidField(payload={'details':"Sponsor - link"})
def __init__(self, name=None): """The constructor. Raises: InvalidField """ if not string_validator(name): raise InvalidField(payload={'details': "League - name"}) self.name = name
def update(self, league): ''' updates an existing league Raises: InvalidField ''' if not string_validator(league): raise InvalidField(payload={'details':"League - name"}) self.name= league
def update(self, date: str = None, time: str = None, home_team_id: int = None, away_team_id: int = None, league_id: int = None, status: str = None, field: str = None, division_id: int = None) -> None: """Update an existing game. Raises: InvalidField TeamDoesNotExist LeagueDoesNotExist """ d = self.date.strftime("%Y-%m-%d") t = self.date.strftime("%H:%M") if date is not None and date_validator(date): d = date elif date is not None: raise InvalidField(payload={'details': "Game - date"}) if time is not None and time_validator(time): t = time elif time is not None: raise InvalidField(payload={'details': "Game - time"}) if (home_team_id is not None and Team.query.get(home_team_id) is not None): self.home_team_id = home_team_id elif home_team_id is not None: raise TeamDoesNotExist(payload={'details': home_team_id}) if (away_team_id is not None and Team.query.get(away_team_id) is not None): self.away_team_id = away_team_id elif away_team_id is not None: raise TeamDoesNotExist(payload={'details': away_team_id}) if league_id is not None and League.query.get(league_id) is not None: self.league_id = league_id elif league_id is not None: raise LeagueDoesNotExist(payload={'details': league_id}) if status is not None and string_validator(status): self.status = status elif status is not None: raise InvalidField(payload={'details': "Game - status"}) if field is not None and field_validator(field): self.field = field elif field is not None: raise InvalidField(payload={'details': "Game - field"}) if (division_id is not None and Division.query.get(division_id) is not None): self.division_id = division_id elif division_id is not None: raise DivisionDoesNotExist(payload={'details': "division_id"}) # worse case just overwrites it with same date or time self.date = datetime.strptime(d + "-" + t, '%Y-%m-%d-%H:%M')
def update(self, name: str = None, email: str = None, gender: str = None, password: str = None, active: bool = None) -> None: """Update an existing player Parameters: name: the name of the player email: the unique email of the player gender: the gender of the player password: the password of the player Raises: InvalidField NonUniqueEmail """ if email is not None: # check if email is unique if not string_validator(email): raise InvalidField(payload="Player - email") email = email.strip().lower() player = Player.query.filter_by(email=email).first() if player is not None: raise NonUniqueEmail(payload={'details': email}) self.email = email if gender is not None and gender_validator(gender): self.gender = gender.lower() elif gender is not None: raise InvalidField(payload={'details': "Player - gender"}) if name is not None and string_validator(name): self.name = name elif name is not None: raise InvalidField(payload={'details': "Player - name"}) if active is not None and boolean_validator(active): self.active = active elif active is not None: raise InvalidField(payload={'detail': "Player - active"})
def update(self, date=None, time=None, home_team_id=None, away_team_id=None, league_id=None, status=None, field=None): ''' updates an existing game Raises: InvalidField TeamDoesNotExist LeagueDoesNotExist ''' d = self.date.strftime("%Y-%m-%d") t = self.date.strftime("%H:%M") if date is not None and date_validator(date): d = date elif date is not None: raise InvalidField(payload={'details':"Game - date"}) if time is not None and time_validator(time): t = time elif time is not None: raise InvalidField(payload={'details':"Game - time"}) if (home_team_id is not None and Team.query.get(home_team_id) is not None): self.home_team_id = home_team_id elif home_team_id is not None: raise TeamDoesNotExist(payload={'details':home_team_id}) if (away_team_id is not None and Team.query.get(away_team_id) is not None): self.away_team_id = away_team_id elif away_team_id is not None: raise TeamDoesNotExist(payload={'details':away_team_id}) if league_id is not None and League.query.get(league_id) is not None: self.league_id = league_id elif league_id is not None: raise LeagueDoesNotExist(payload={'details':league_id}) if status is not None and string_validator(status): self.status = status elif status is not None: raise InvalidField(payload={'details':"Game - status"}) if field is not None and field_validator(field): self.field = field elif field is not None: raise InvalidField(payload={'details':"Game - field"}) # worse case just overwrites it with same date or time self.date = datetime.strptime(d + "-" +t, '%Y-%m-%d-%H:%M')
def __init__(self, date: str, time: str, home_team_id: int, away_team_id: int, league_id: int, division_id: int, status: str = "", field: str = ""): """The Constructor. Raises: InvalidField TeamDoesNotExist LeagueDoesNotExist DivisionDoesNotExist """ # check for all the invalid parameters if not date_validator(date): raise InvalidField(payload={'details': "Game - date"}) if not time_validator(time): raise InvalidField(payload={'details': "Game - time"}) self.date = datetime.strptime(date + "-" + time, '%Y-%m-%d-%H:%M') if (home_team_id is None or Team.query.get(home_team_id) is None): raise TeamDoesNotExist(payload={'details': home_team_id}) if (away_team_id is None or Team.query.get(away_team_id) is None): raise TeamDoesNotExist(payload={'details': away_team_id}) if League.query.get(league_id) is None: raise LeagueDoesNotExist(payload={'details': league_id}) if ((status != "" and not string_validator(status)) or (field != "" and not field_validator(field))): raise InvalidField(payload={'details': "Game - field/status"}) if Division.query.get(division_id) is None: raise DivisionDoesNotExist(payload={'details': division_id}) # must be good now self.home_team_id = home_team_id self.away_team_id = away_team_id self.league_id = league_id self.status = status self.field = field self.division_id = division_id
def __init__(self, color=None, sponsor_id=None, league_id=None, year=date.today().year): ''' Raises InvalidField SponsorDoesNotExist LeagueDoesNotExist ''' if color is not None and not string_validator(color): raise InvalidField(payload={'details':"Team - color"}) if sponsor_id is not None and Sponsor.query.get(sponsor_id) is None: raise SponsorDoesNotExist(payload={'details':sponsor_id}) if league_id is not None and League.query.get(league_id) is None: raise LeagueDoesNotExist(payload={'details':league_id}) if year is not None and not year_validator(year): raise InvalidField(payload={'details':"Team - year"}) self.color = color self.sponsor_id = sponsor_id self.league_id = league_id self.year = year self.kik = None