def test_change_password(self): user = self.new_user() self.assertTrue( User.change_password( id_=user.id, password=u'hejhejø123', ) ) self.assertFalse( User.change_password( id_=user.id, password=u'asdasd', current_password=u'WRONG_PASSWORD', ) ) self.assertTrue( User.change_password( id_=user.id, password=u'asdasd', current_password=u'hejhejø123', ) ) self.assertTrue( User.verify_password( id_=user.id, password=u'asdasd', ) )
def test_send(self): ''' Creates 3 users, 2 teams and 2 filters. User 1 and 2 is a member of team 1 and user 2 is a member of team 2. Team 1 has a relation to both filter 1 and 2. Team 2 has a relation to filter 2. User 1 and 3 should receive an email and User 2 should not. ''' user = User.new(name=u'Test user 1', email='*****@*****.**', notification_types={ 'send_email': { 'data': '*****@*****.**', 'enabled': True, } }) user2 = User.new(name=u'Test user 2', email='*****@*****.**', notification_types={ 'send_email': { 'data': '*****@*****.**', 'enabled': False, } }) user3 = User.new(name=u'Test user 3', email='*****@*****.**', notification_types={ 'send_email': { 'data': '*****@*****.**', 'enabled': True, } }) team = Team.new(name=u'Test team 1', ) team2 = Team.new(name=u'Test team 2', ) filter1 = Filter.new( name=u'Test filter 1', data_yaml='notify: true', ) filter2 = Filter.new( name=u'Test filter 2', data_yaml='notify: false', ) # create a relations User_team.new(team_id=team.id, user_id=user.id) User_team.new(team_id=team2.id, user_id=user2.id) User_team.new(team_id=team.id, user_id=user3.id) Filter_team.new(filter_id=filter1.id, team_id=team.id) Filter_team.new(filter_id=filter2.id, team_id=team.id) Filter_team.new(filter_id=filter2.id, team_id=team2.id) Mock_notifier.email_send = False Notifier.send(message='Test notification', filters=[ filter1, filter2, ]) self.assertTrue(Mock_notifier.email_send)
def upgrade(): op.create_table( 'users', sa.Column('id', sa.Integer(unsigned=True), primary_key=True, autoincrement=True), sa.Column('email', sa.String(45), nullable=False, unique=True), sa.Column('password', sa.CHAR(60)), sa.Column('name', sa.String(45)), sa.Column('notification_types', sa.Text), ) op.create_table( 'teams', sa.Column('id', sa.Integer(unsigned=True), primary_key=True, autoincrement=True), sa.Column('name', sa.String(45), unique=True), ) op.create_table( 'user_teams', sa.Column('user_id', sa.Integer(unsigned=True), sa.ForeignKey('users.id', onupdate='cascade', ondelete='cascade'), primary_key=True, autoincrement=False), sa.Column('team_id', sa.Integer(unsigned=True), sa.ForeignKey('teams.id', onupdate='cascade', ondelete='cascade'), primary_key=True, autoincrement=False), ) op.create_unique_constraint('uq_user_id_team_id', 'user_teams', ['user_id', 'team_id']) # create a system user User.new( name='TLOG', email='*****@*****.**', ) # create a admin user need_info = True while need_info: print 'An admin user needs to be set up.' name = raw_input("Name: ") if name: email = raw_input("Email address: ") if email: password = getpass.getpass() if password: password_again = getpass.getpass('Password again:') if password == password_again: user = User.new( name=name, email=email, ) if user: User.change_password( id_=user.id, password=password, ) print 'Thanks.' need_info = False else: print 'passwords did not match.'
def post(self): notification_types = {} for type_ in self.get_arguments('send_type_enabled'): notification_types[type_] = { 'enabled': True, 'data': self.get_argument(type_, ''), } User.update_notification_types( id_=self.current_user.id, notification_types=notification_types, ) self.redirect('/settings/notification') return
def post(self): form = forms.Signup(self.request.arguments) if form.validate(): try: user = User.new( name=form.name.data, email=form.email.data, notification_types={ 'send_email': { 'enabled': True, 'data': form.email.data, } } ) yield self.change_password( user_id=user.id, password=form.password.data, ) self.new_session( user_id=user.id, ) self.redirect(self.get_argument('next', '/')) return except User_exception_duplicate_email as e: form.email.errors.append(e.message) self.render( 'signup.html', title='Signup', form=form, )
def test_new(self): user = User.new( name=u'Test user ø', email='*****@*****.**', ) store = Store( Parse( u'<34>Oct 11 22:14:15 mymachine.example.com su - ID47 - ZwPpeQyUtrRKxw5asd' )) Log_group.add(store) group = Log_group.get(message_hash=store.message_hash) self.assertTrue( Log_group_event.new( log_group_id=group.id, user_id=user.id, message=u'Test event', )) self.assertTrue( Log_group_event.new( log_group_id=group.id, user_id=user.id, message=u'Test event 2', )) events = Log_group_events.get(log_group_id=group.id) self.assertEqual(len(events), 2) self.assertEqual(events[0].user.id, user.id)
def post(self): form = forms.Signup(self.request.arguments) if form.validate(): try: user = User.new(name=form.name.data, email=form.email.data, notification_types={ 'send_email': { 'enabled': True, 'data': form.email.data, } }) yield self.change_password( user_id=user.id, password=form.password.data, ) self.new_session(user_id=user.id, ) self.redirect(self.get_argument('next', '/')) return except User_exception_duplicate_email as e: form.email.errors.append(e.message) self.render( 'signup.html', title='Signup', form=form, )
def test_new(self): user = User.new( name=u'Test user ø', email='*****@*****.**', ) store = Store(Parse(u'<34>Oct 11 22:14:15 mymachine.example.com su - ID47 - ZwPpeQyUtrRKxw5asd')) Log_group.add(store) group = Log_group.get(message_hash=store.message_hash) self.assertTrue( Log_group_event.new( log_group_id=group.id, user_id=user.id, message=u'Test event', ) ) self.assertTrue( Log_group_event.new( log_group_id=group.id, user_id=user.id, message=u'Test event 2', ) ) events = Log_group_events.get(log_group_id=group.id) self.assertEqual(len(events), 2) self.assertEqual(events[0].user.id, user.id)
def test_new(self): user = User.new( name=u'Test user ø', email='*****@*****.**', ) session = Session.new(user_id=user.id) self.assertTrue(isinstance(session, str))
def test_get(self): user = User.new( name=u'Test user ø', email='*****@*****.**', ) session = Session.new(user_id=user.id) user2 = Session.get(session_id=session) self.assertEqual(user.id, user2.id) # test expired session = Session.new(user_id=user.id, expire_days=-1) user2 = Session.get(session_id=session) self.assertEqual(user2, None)
def test_delete(self): user = User.new( name=u'Test user ø', email='*****@*****.**', ) session = Session.new(user_id=user.id) user2 = Session.get(session_id=session) self.assertEqual(user.id, user2.id) self.assertTrue( Session.delete(session_id=session) ) user2 = Session.get(session_id=session) self.assertEqual(user2, None)
def get(cls, session_id): ''' Retrives a user by its session. :param session: str :returns: tlog.base.user.User ''' with new_session() as session: query = session.query( models.Web_session, ).filter( models.Web_session.session==session_id, models.Web_session.expires>=datetime.utcnow(), ).first() if not query: return None return User.get(id_=query.user_id)
def test_get(self): user = self.new_user() user = User.get(id_=user.id) self.assertUser(user)
def change_password(self, user_id, password): User.change_password( id_=user_id, password=password, )
def new_user(self, email='*****@*****.**'): return User.new( name=u'Test user ø', email=email, )
def login(self, email, password): return User.login( email=email, password=password, )
def test_send(self): ''' Creates 3 users, 2 teams and 2 filters. User 1 and 2 is a member of team 1 and user 2 is a member of team 2. Team 1 has a relation to both filter 1 and 2. Team 2 has a relation to filter 2. User 1 and 3 should receive an email and User 2 should not. ''' user = User.new( name=u'Test user 1', email='*****@*****.**', notification_types={ 'send_email': { 'data': '*****@*****.**', 'enabled': True, } } ) user2 = User.new( name=u'Test user 2', email='*****@*****.**', notification_types={ 'send_email': { 'data': '*****@*****.**', 'enabled': False, } } ) user3 = User.new( name=u'Test user 3', email='*****@*****.**', notification_types={ 'send_email': { 'data': '*****@*****.**', 'enabled': True, } } ) team = Team.new( name=u'Test team 1', ) team2 = Team.new( name=u'Test team 2', ) filter1 = Filter.new( name=u'Test filter 1', data_yaml='notify: true', ) filter2 = Filter.new( name=u'Test filter 2', data_yaml='notify: false', ) # create a relations User_team.new( team_id=team.id, user_id=user.id ) User_team.new( team_id=team2.id, user_id=user2.id ) User_team.new( team_id=team.id, user_id=user3.id ) Filter_team.new( filter_id=filter1.id, team_id=team.id ) Filter_team.new( filter_id=filter2.id, team_id=team.id ) Filter_team.new( filter_id=filter2.id, team_id=team2.id ) Mock_notifier.email_send = False Notifier.send( message='Test notification', filters=[ filter1, filter2, ] ) self.assertTrue(Mock_notifier.email_send)
def test_get_by_email(self): user = self.new_user() user = User.get_by_email(email=user.email) self.assertUser(user)