Exemplo n.º 1
0
    def test_unit__validate_password__false__bad_password(self):
        """
        Check if validate_password can correctly check if password is
        an uncorrect correct one
        """
        name = 'Damien'
        email = '*****@*****.**'
        password = '******'

        user = User()
        user.display_name = name
        user.email = email
        user.password = password

        assert user.validate_password('uncorrect_password') is False
Exemplo n.º 2
0
    def test__unit__validate_password__ok__nominal_case(self):
        """
        Check if validate_password can correctly check if password i the correct
        one
        """

        name = 'Damien'
        email = '*****@*****.**'
        password = '******'

        user = User()
        user.display_name = name
        user.email = email
        user.password = password

        assert user.validate_password(password) is True
Exemplo n.º 3
0
    def test_unit__password__ok__nominal_case(self):
        """
        Check if password can be set and hashed password
        can be retrieve. Verify if hashed password is not
        same as password.
        """
        name = 'Damien'
        email = '*****@*****.**'
        password = '******'

        user = User()
        user.display_name = name
        user.email = email
        assert user._password is None
        user.password = password
        assert user._password is not None
        assert user._password != password
        assert user.password == user._password
Exemplo n.º 4
0
    def update(
        self,
        user: User,
        name: str = None,
        email: str = None,
        password: str = None,
        timezone: str = None,
        groups: typing.Optional[typing.List[Group]] = None,
        do_save=True,
    ) -> User:
        if name is not None:
            user.display_name = name

        if email is not None:
            email_exist = self._check_email(email)
            if not email_exist:
                raise EmailValidationFailed(
                    'Email given form {} is uncorrect'.format(email))  # nopep8
            user.email = email

        if password is not None:
            user.password = password

        if timezone is not None:
            user.timezone = timezone

        if groups is not None:
            # INFO - G.M - 2018-07-18 - Delete old groups
            for group in user.groups:
                if group not in groups:
                    user.groups.remove(group)
            # INFO - G.M - 2018-07-18 - add new groups
            for group in groups:
                if group not in user.groups:
                    user.groups.append(group)

        if do_save:
            self.save(user)

        return user