Exemplo n.º 1
0
    def test__unit__unicode__ok__no_display_name(self):

        email = '*****@*****.**'

        user = User()
        user.email = email

        assert user.__unicode__() == email
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 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))
Exemplo n.º 5
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
Exemplo n.º 6
0
    def create_user(self, email=None, groups=[], save_now=False) -> User:
        user = User()

        if email:
            user.email = email

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

        self._session.add(user)

        if save_now:
            self._session.flush()

        return user
Exemplo n.º 7
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)
Exemplo n.º 8
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.º 9
0
    def test_notifier_factory_method(self):
        u = User()

        self.app_config.EMAIL_NOTIFICATION_ACTIVATED = True
        notifier = NotifierFactory.create(self.app_config, u)
        eq_(EmailNotifier, notifier.__class__)

        self.app_config.EMAIL_NOTIFICATION_ACTIVATED = False
        notifier = NotifierFactory.create(self.app_config, u)
        eq_(DummyNotifier, notifier.__class__)
Exemplo n.º 10
0
    def execute_created_user_actions(self, created_user: User) -> None:
        """
        Execute actions when user just been created
        :return:
        """
        # NOTE: Cyclic import
        # TODO - G.M - 28-03-2018 - [Calendar] Reenable Calendar stuff
        #from tracim.lib.calendar import CalendarManager
        #from tracim.model.organisational import UserCalendar

        # TODO - G.M - 04-04-2018 - [auth]
        # Check if this is already needed with
        # new auth system
        created_user.ensure_auth_token(
            session=self._session,
            validity_seconds=self._config.USER_AUTH_TOKEN_VALIDITY)

        # Ensure database is up-to-date
        self._session.flush()
        transaction.commit()
Exemplo n.º 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)
Exemplo n.º 12
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
Exemplo n.º 13
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
Exemplo n.º 14
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
Exemplo n.º 15
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.º 16
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.º 17
0
 def disable(self, user: User, do_save=False):
     user.is_active = False
     if do_save:
         self.save(user)
Exemplo n.º 18
0
 def enable(self, user: User, do_save=False):
     user.is_active = True
     if do_save:
         self.save(user)