Пример #1
0
    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
Пример #2
0
 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"})
Пример #3
0
 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
Пример #4
0
 def testGenderValidator(self):
     # test with a non-number
     test = 1
     self.assertEqual(gender_validator(test), False,
                      'Gender Validator: 1 was a valid Gender')
     # test empty string
     test = ""
     self.assertEqual(gender_validator(test), False,
                      'Gender Validator: "" was a valid Gender')
     # test with non-valid gender
     test = "X"
     self.assertEqual(gender_validator(test), False,
                      'Gender Validator: X was a valid Gender')
     # test fpr ca[senstivty
     test = "f"
     self.assertEqual(gender_validator(test), True,
                      'Gender Validator: f was a invalid Gender')
     # test fpr ca[senstivty
     test = "M"
     self.assertEqual(gender_validator(test), True,
                      'Gender Validator: M was a invalid Gender')
Пример #5
0
 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()
Пример #6
0
    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"})