def test_recover_user(self): # fake the sending of the recover email user = self.new_user() User.send_recover(user.username, force_send=False) self.db.session.commit() assert user.recover_hash is not None assert user.recover_gen is not None # now actually run the recover function user.recover(user.recover_hash, 'new_password') self.db.session.commit() # ensure we got logged in assert current_user == user
def test_check_taken(self): """ ensure registration works, and lowercases names """ self.new_user(username='******') tests = [('crowdlink', True), ('CROWdlink', True), ('dsfglkj', False)] for username, result in tests: assert User.check_taken(username)['taken'] is result
def test_login(self): user = self.new_user() ret = User.login() # make sure message is uniform with no params, or wrong params... assert ret['success'] is False assert 'cred' in ret['message'] ret = User.login(identifier='velma') assert ret['success'] is False assert 'cred' in ret['message'] # regular cred works fine ret = User.login(identifier='velma', password='******') assert current_user == user logout_user() # diff case username works! ret = User.login(identifier='VELMA', password='******') assert current_user == user logout_user() # diff case password breaks ret = User.login(identifier='VELMA', password='******') assert not ret
def test_register(self): """ ensure registration works, and lowercases names """ user = User.create('Testing_one', 'testing', '*****@*****.**', force_send=False) self.db.session.commit() self.db.session.refresh(user) print(user.to_dict()) assert user.username == 'testing_one' assert user.password != 'testing' Email.query.filter_by(address='*****@*****.**').one()
def new_user(self, username='******', active=True, login=False, login_ctx=False): # create a user for testing usr = User.create(username, "testing", username + '@crowdlink.io') self.db.session.commit() # activate the user if requested if active: Email.activate_email(username + '@crowdlink.io', force=True) # now log them in via api call, or direct call if requested if login: self.login(username=username) if login_ctx: self.login_ctx(username=username) return usr
def provision(): """ Creates fixture data for the tests by making real connections with Stripe and setting up test projects, tasks, etc """ # ensure we aren't sending any emails current_app.config['send_emails'] = False users = {} # make an admin user, and set him as the current user admin = User.create("admin", "testing", "*****@*****.**") admin.admin = True # make them an admin db.session.commit() assert Email.activate_email('*****@*****.**', force=True) login_user(admin) # make a bunch of testing users # ========================================================================= # fred isn't activated, no email address verified fred = User.create("fred", "testing", "*****@*****.**") users['fred'] = fred db.session.commit() # regular users... for username in ['velma', 'scrappy', 'shaggy', 'scooby', 'daphne', 'crowdlink', 'barney', 'betty']: usr = User.create(username, "testing", username + "@crowdlink.io") db.session.commit() assert Email.activate_email(username + '@crowdlink.io', force=True) users[username] = usr # Create projects, tasks, comments, etc from a template file # ========================================================================= pdata = yaml.load(open(root + '/assets/provision.yaml')) projects = {} for project in pdata['projects']: # create a sweet new project... proj = Project( owner=users[project['owner']], name=project['name'], website=project['website'], url_key=project['url_key'], desc=project['desc']).save() curr_proj = {'obj': proj} projects[proj.url_key] = curr_proj # subscribe some users if requested in config if 'subscribers' in project: for sub in project['subscribers']: proj.set_subscribed(True, user=users[sub]) if 'maintainers' in project: for maintainer in project['maintainers']: proj.add_maintainer(username=users[maintainer].username) # Add out tasks to the database curr_proj['tasks'] = {} for task in project.get('tasks', []): # add some solutions to the task new_task = Task.create( user=users[task.get('creator', proj.owner.username)], title=task['title'], desc=task.get('desc'), project=proj).save() curr_task = {'obj': new_task} curr_proj['tasks'][task.get('key', new_task.url_key)] = curr_task # add comments to the task curr_task['comments'] = {} for comm_tmpl in task.get('comments', []): comm = Comment.create( thing=new_task, user=users[comm_tmpl.get('creator', new_task.creator.username)], message=comm_tmpl.get('message')).save() curr_task['comments'][comm_tmpl.get('key', comm.id)] = ( {'obj': comm})