Пример #1
0
    def test_unit__unicode__ok__nominal_case(self):
        name = 'Damien'
        email = '*****@*****.**'

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

        assert user.__unicode__() == name
Пример #2
0
    def test_unit__repr__ok__nominal_case(self):
        name = 'Damien'
        email = '*****@*****.**'

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

        assert user.__repr__(
        ) == "<User: email='*****@*****.**', display='Damien'>"  # nopep8
Пример #3
0
    def test_unit__validate_password__false__null_password(self):
        # Check bug #70 fixed
        # http://tracim.org/workspaces/4/folders/5/threads/70

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

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

        assert user.validate_password('') is False
Пример #4
0
    def test_null_password(self):
        # Check bug #70 fixed
        # http://tracim.org/workspaces/4/folders/5/threads/70

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

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

        eq_(False, user.validate_password(None))
Пример #5
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
Пример #6
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
Пример #7
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
Пример #8
0
    def update(
            self,
            user: User,
            name: str=None,
            email: str=None,
            do_save=True,
            timezone: str='',
    ):
        if name is not None:
            user.display_name = name

        if email is not None:
            user.email = email

        user.timezone = timezone

        if do_save:
            self.save(user)
Пример #9
0
    def test_unit__create__ok__nominal_case(self):
        self.session.flush()
        transaction.commit()
        name = 'Damien'
        email = '*****@*****.**'

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

        self.session.add(user)
        self.session.flush()
        transaction.commit()

        new_user = self.session.query(User).filter(
            User.display_name == name).one()  # nopep8

        assert new_user.display_name == name
        assert new_user.email == email
        assert new_user.email_address == email
Пример #10
0
    def create_minimal_user(self, email, groups=[], save_now=False) -> User:
        """Previous create_user method"""
        user = User()

        email_exist = self._check_email(email)
        if not email_exist:
            raise EmailValidationFailed(
                'Email given form {} is uncorrect'.format(email))  # nopep8
        user.email = email
        user.display_name = email.split('@')[0]

        for group in groups:
            user.groups.append(group)

        self._session.add(user)

        if save_now:
            self._session.flush()

        return user
Пример #11
0
    def test_create(self):
        self.session.flush()
        transaction.commit()
        name = 'Damien'
        email = '*****@*****.**'

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

        self.session.add(user)
        self.session.flush()
        transaction.commit()

        new_user = self.session.query(User).filter(
            User.display_name == name).one()

        eq_(new_user.display_name, name)
        eq_(new_user.email, email)
        eq_(new_user.email_address, email)
Пример #12
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