Пример #1
0
 def testDateValidator(self):
     self.assertEqual(False, date_validator('01-01-2014'),
                      "Date Validator: Invalid Date")
     self.assertEqual(False, date_validator('2014-01-2014'),
                      "Date Validator: Invalid Date")
     self.assertEqual(False, date_validator('2014-13-01'),
                      "Date Validator: Invalid Date")
     self.assertEqual(True, date_validator('2014-12-01'),
                      "Date Validator: Valid Date")
Пример #2
0
 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
Пример #3
0
    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')
Пример #4
0
 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')
Пример #5
0
    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
Пример #6
0
    def __init__(self,
                 team_id,
                 sponsor_id=None,
                 description=None,
                 points=0.0,
                 receipt=None,
                 time=None,
                 date=None):
        """The constructor.

            Raises:
                SponsorDoesNotExist
                TeamDoesNotExist
        """
        if not float_validator(points):
            raise InvalidField(payload={"details": "Game - points"})
        self.points = float(points)
        self.date = datetime.now()
        sponsor = None
        if sponsor_id is not None:
            sponsor = Sponsor.query.get(sponsor_id)
        self.receipt = receipt
        if sponsor_id is not None and sponsor is None:
            raise SponsorDoesNotExist(payload={"details": sponsor_id})
        team = Team.query.get(team_id)
        if team is None:
            raise TeamDoesNotExist(payload={"details": team_id})
        self.description = description
        self.team_id = team_id
        self.sponsor_id = sponsor_id
        self.kik = None
        if date is not None and not date_validator(date):
            raise InvalidField(payload={'details': "Game - date"})
        if time is not None and not time_validator(time):
            raise InvalidField(payload={'details': "Game - time"})
        if date is not None and time is None:
            self.date = datetime.strptime(date + "-" + time, '%Y-%m-%d-%H:%M')
        else:
            self.date = datetime.today()
Пример #7
0
    def update(self,
               team_id=None,
               sponsor_id=None,
               description=None,
               points=None,
               receipt=None,
               date=None,
               time=None):
        """Used to update an existing espy transaction.

            Raises:
                TeamDoesNotExist
                SponsorDoesNotExist
        """
        if points is not None:
            self.points = points
        if description is not None:
            self.description = description
        if team_id is not None:
            if Team.query.get(team_id) is not None:
                self.team_id = team_id
            else:
                raise TeamDoesNotExist(payload={"details": team_id})
        if sponsor_id is not None:
            if Sponsor.query.get(sponsor_id) is not None:
                self.sponsor_id = sponsor_id
            else:
                raise SponsorDoesNotExist(payload={"details": sponsor_id})
        if receipt is not None:
            self.receipt = receipt
        if date is not None and time is None:
            self.date = datetime.strptime(date + "-" + time, '%Y-%m-%d-%H:%M')
        if date is not None and time is not None:
            if date is not None and not date_validator(date):
                raise InvalidField(payload={'details': "Game - date"})
            if time is not None and not time_validator(time):
                raise InvalidField(payload={'details': "Game - time"})
            self.date = datetime.strptime(date + "-" + time, '%Y-%m-%d-%H:%M')
Пример #8
0
 def __init__(self,
              team_id,
              sponsor_id=None,
              description=None,
              points=0.0,
              receipt=None,
              time=None,
              date=None):
     '''
         Raises:
             SponsorDoesNotExist
             TeamDoesNotExist
     '''
     if not float_validator(points):
         raise InvalidField(payload={"details": "Game - points"})
     self.points = float(points)
     self.date = datetime.now()
     sponsor = None
     if sponsor_id is not None:
         sponsor = Sponsor.query.get(sponsor_id)
     self.receipt = receipt
     if sponsor_id is not None and sponsor is None:
         raise SponsorDoesNotExist(payload={"details": sponsor_id})
     team = Team.query.get(team_id)
     if team is None:
         raise TeamDoesNotExist(payload={"details": team_id})
     self.description = description
     self.team_id = team_id
     self.sponsor_id = sponsor_id
     self.kik = None
     if date is not None and not date_validator(date):
         raise InvalidField(payload={'details':"Game - date"})
     if time is not None and not time_validator(time):
         raise InvalidField(payload={'details':"Game - time"})
     if date is not None and time is None:
         self.date = datetime.strptime(date + "-" +time, '%Y-%m-%d-%H:%M')
     else:
         self.date = datetime.today()
Пример #9
0
 def update(self,
            team_id=None,
            sponsor_id=None,
            description=None,
            points=None,
            receipt=None,
            date=None,
            time=None):
     '''
         used to update an existing espy transaction
         Raises:
             TeamDoesNotExist
             SponsorDoesNotExist
     '''
     if points is not None:
         self.points = points
     if description is not None:
         self.description = description
     if team_id is not None:
         if Team.query.get(team_id) is not None:
             self.team_id = team_id
         else:
             raise TeamDoesNotExist(payload={"details": team_id})
     if sponsor_id is not None:
         if Sponsor.query.get(sponsor_id) is not None:
             self.sponsor_id = sponsor_id
         else:
             raise SponsorDoesNotExist(payload={"details": sponsor_id})
     if receipt is not None:
         self.receipt = receipt
     if date is not None and time is None:
         self.date = datetime.strptime(date + "-" +time, '%Y-%m-%d-%H:%M')
     if date is not None and time is not None:
         if date is not None and not date_validator(date):
             raise InvalidField(payload={'details':"Game - date"})
         if time is not None and not time_validator(time):
             raise InvalidField(payload={'details':"Game - time"})
         self.date = datetime.strptime(date + "-" +time, '%Y-%m-%d-%H:%M')