def create_test_users(): # create some test users users = [] users.append(accounts.create_user("Eric", "Cartman", "exc", "password")) users.append(accounts.create_user("Randy", "Marsh", "rxm", "password")) users.append(accounts.create_user("Stan", "Marsh", "sxm1", "password", big=users[1].key())) users.append(accounts.create_user("Kyle", "Broflovski", "kxb1", "password")) return users
def test_missing_arguments(self): """This method tests whether the create_user function actually requires the right number of arguments""" try: accounts.create_user() # pylint: disable=E1120 self.fail("Should have thrown a TypeError " + "becuase create_user requires at least" + "4 arguments") except TypeError, error: self.assertEqual(error.message, "create_user() takes exactly 4 " + "arguments (0 given)")
def test_error_on_nonmod_kwargs(self): """This method tests whether the create_user function will throw an error when a nonmodifiable field of kwargs is tried to be set via the kwargs dictionary""" try: accounts.create_user("John", "Schmidt", "jjs11", "password", hash="hash") self.fail("Should have thrown an AttributeError") except AttributeError: pass
def test_error_on_invalid_kwargs(self): """This method tests whether the create_user function will error like its supposed to when an invalid type for one of the kwargs is passed in""" try: accounts.create_user("John", "Schmidt", "jjs11", "password", mname=55) self.fail("Should have thrown an AttributeError") except AttributeError: pass
def test_non_unique_cwruid(self): """This method tests whether the create_user function will throw an error upon trying to create a user with a duplicate cwruID""" accounts.create_user("John", "Smith", "jxs11", "password") try: accounts.create_user("John", "Smith", "jxs11", "password") self.fail("Should have thrown an AttributeError " + "because cwruid must be unique") except AttributeError: pass
def test_missing_arguments(self): """This method tests whether the create_user function actually requires the right number of arguments""" try: accounts.create_user() # pylint: disable=E1120 self.fail('Should have thrown a TypeError ' + 'becuase create_user requires at least' + '4 arguments') except TypeError, error: self.assertEqual( error.message, 'create_user() takes exactly 4 ' + 'arguments (0 given)')
def test_non_unique_cwruid(self): """This method tests whether the create_user function will throw an error upon trying to create a user with a duplicate cwruID""" accounts.create_user('John', 'Smith', 'jxs11', 'password') try: accounts.create_user('John', 'Smith', 'jxs11', 'password') self.fail('Should have thrown an AttributeError ' + 'because cwruid must be unique') except AttributeError: pass
def test_error_on_nonmod_kwargs(self): """This method tests whether the create_user function will throw an error when a nonmodifiable field of kwargs is tried to be set via the kwargs dictionary""" try: accounts.create_user('John', 'Schmidt', 'jjs11', 'password', hash='hash') self.fail('Should have thrown an AttributeError') except AttributeError: pass
def create_test_users(): # create some test users users = [] users.append(accounts.create_user('Eric', 'Cartman', 'exc', 'password')) users.append(accounts.create_user('Randy', 'Marsh', 'rxm', 'password')) users.append( accounts.create_user('Stan', 'Marsh', 'sxm1', 'password', big=users[1].key())) users.append(accounts.create_user('Kyle', 'Broflovski', 'kxb1', 'password')) return users
def test_error_on_invalid_kwargs(self): """This method tests whether the create_user function will error like its supposed to when an invalid type for one of the kwargs is passed in""" try: accounts.create_user('John', 'Schmidt', 'jjs11', 'password', mname=55) self.fail('Should have thrown an AttributeError') except AttributeError: pass
def test_ignore_nonexistant_kwargs(self): """This method tests whether the create_user function will ignore kwarg keys that don't actually exist in the user model""" new_user = accounts.create_user("John", "Schmidt", "jjs11", "password", fake="fake") try: new_user.fake # pylint: disable=W0104,E1101 self.fail("Should have thrown an AttributeError") except AttributeError: pass
def test_kwargs(self): """This method tests whether the create_user function will accept kwargs""" new_user = accounts.create_user('John', 'Schmidt', 'jjs11', 'password', mname='Jacob Jinglehiemer') self.assertEqual( new_user._User__UserModel.mname, # pylint: disable=W0212,C0301 'Jacob Jinglehiemer')
def create_test_users(): # create some test users users = [] users.append(accounts.create_user('Eric', 'Cartman', 'exc', 'password')) users.append(accounts.create_user('Randy', 'Marsh', 'rxm', 'password')) users.append(accounts.create_user('Stan', 'Marsh', 'sxm1', 'password', big=users[1].key())) users.append(accounts.create_user('Kyle', 'Broflovski', 'kxb1', 'password')) return users
def test_ignore_nonexistant_kwargs(self): """This method tests whether the create_user function will ignore kwarg keys that don't actually exist in the user model""" new_user = accounts.create_user('John', 'Schmidt', 'jjs11', 'password', fake='fake') try: new_user.fake # pylint: disable=W0104,E1101 self.fail('Should have thrown an AttributeError') except AttributeError: pass
def create_user(): """ View for creating a user """ from application.generate_keys import generate_randomkey form = forms.CreateUserForm(request.form) form.family.choices = get_family_choices() form.roles.choices = get_role_choices() if request.method == 'POST': if form.validate(): # create the user with information specified in form fname = form.fname.data lname = form.lname.data cwruid = form.cwruid.data # generate a new temporary password password = generate_randomkey(16) # get optional attributes optional_attr = {} if form.mname.data != '': optional_attr['mname'] = form.mname.data if form.family.data != 'none': # look up family instance query = models.FamilyModel.all() query.filter('name =', form.family.data) families = query.fetch(1) if len(families) != 1: form.family.errors.append(u'Family %s does not exist' % form.family.data) return render_template('members/create.html', create_user_form=form) optional_attr['family'] = families[0].key() if form.big.data != '': # look up big instance users = find_users(cwruid=('=', form.big.data)) if len(users) != 1: form.big.errors.append(u'User %s does not exist' % form.big.data) return render_template('members/create.html', create_user_form=form) optional_attr['big'] = users[0].key() if form.avatar.data != '': optional_attr['avatar'] = form.avatar.data try: new_user = accounts.create_user(fname, lname, cwruid, password, **optional_attr) if new_user is None: raise AttributeError('Something went wrong with user creation') # add the case email address to the user email = models.EmailModel(user=new_user.key(), email='*****@*****.**' % new_user.cwruid, name='Case Email') email.put() # add the roles to the user for role in form.roles.data: query = RoleModel.all() query.filter('name =', role) if query.count() != 1: flash('Role %s does not exist' % role, 'error') continue desired_role = query.fetch(1)[0] new_urole = UserRoleModel(user=new_user.key(), role=desired_role.key()) new_urole.put() flash('User created successfully', 'success') form = None form = forms.CreateUserForm() form.family.choices = get_family_choices() form.roles.choices = get_role_choices() send_new_user_mail(fname, lname, cwruid, password) except AttributeError, e: flash(str(e), 'error')
def create_user(): """ View for creating a user """ from application.generate_keys import generate_randomkey form = forms.CreateUserForm(request.form) form.family.choices = get_family_choices() form.roles.choices = get_role_choices() if request.method == 'POST': if form.validate(): # create the user with information specified in form fname = form.fname.data lname = form.lname.data cwruid = form.cwruid.data # generate a new temporary password password = generate_randomkey(16) # get optional attributes optional_attr = {} if form.mname.data != '': optional_attr['mname'] = form.mname.data if form.family.data != 'none': # look up family instance query = models.FamilyModel.all() query.filter('name =', form.family.data) families = query.fetch(1) if len(families) != 1: form.family.errors.append(u'Family %s does not exist' % form.family.data) return render_template('members/create.html', create_user_form=form) optional_attr['family'] = families[0].key() if form.big.data != '': # look up big instance users = find_users(cwruid=('=', form.big.data)) if len(users) != 1: form.big.errors.append(u'User %s does not exist' % form.big.data) return render_template('members/create.html', create_user_form=form) optional_attr['big'] = users[0].key() if form.avatar.data != '': optional_attr['avatar'] = form.avatar.data try: new_user = accounts.create_user(fname, lname, cwruid, password, **optional_attr) if new_user is None: raise AttributeError( 'Something went wrong with user creation') # add the case email address to the user email = models.EmailModel(user=new_user.key(), email='*****@*****.**' % new_user.cwruid, name='Case Email') email.put() # add the roles to the user for role in form.roles.data: query = RoleModel.all() query.filter('name =', role) if query.count() != 1: flash('Role %s does not exist' % role, 'error') continue desired_role = query.fetch(1)[0] new_urole = UserRoleModel(user=new_user.key(), role=desired_role.key()) new_urole.put() flash('User created successfully', 'success') form = None form = forms.CreateUserForm() form.family.choices = get_family_choices() form.roles.choices = get_role_choices() send_new_user_mail(fname, lname, cwruid, password) except AttributeError, e: flash(str(e), 'error')
def setup(): """ This view will check the datastore for a SetupModel entity with the same version id as this instance. If the entity exists it will redirect the user to the homepage. Otherwise it will create some default data. WARNING: This is simply a convenience method. It will also clear out all data for all versions!! It will need to be changed in subsequent versions """ query = SetupModel.all() query.filter('version =', os.environ['CURRENT_VERSION_ID']) if query.count() == 0: # the app hasn't been setup yet #db.delete(db.Entry.all(keys_only=True)) boehms = FamilyModel(name='boehms') boehms.put() snm = FamilyModel(name='s & m') snm.put() newpham = FamilyModel(name='new pham') newpham.put() default_users = [] default_users.append( create_user('Devin', 'Schwab', 'dts34', 'default', family=boehms.key(), avatar='*****@*****.**')) default_users.append(create_user('Jon', 'Chan', 'jtc77', 'default')) default_users.append(create_user('Zach', 'Zanes', 'zzz111', 'password')) default_users.append( create_user('Zach', 'Zaney', 'zzz222', 'password1@')) default_users.append(create_user('Adam', 'Min', 'admin', 'password')) webmaster_role = RoleModel(name='webmaster', desc='administrator for the website') webmaster_role.put() brother_role = RoleModel(name='brother', desc='general brother in the chapter') brother_role.put() pledge_role = RoleModel(name='pledge', desc='pledge in the chapter') pledge_role.put() neophyte_role = RoleModel(name='neophyte', desc='neophyte in the chapter') neophyte_role.put() #default_users = find_users() urole1 = UserRoleModel(user=default_users[0].key(), role=webmaster_role.key()) urole2 = UserRoleModel(user=default_users[0].key(), role=brother_role.key()) urole3 = UserRoleModel(user=default_users[1].key(), role=webmaster_role.key()) urole4 = UserRoleModel(user=default_users[1].key(), role=webmaster_role.key()) urole5 = UserRoleModel(user=default_users[2].key(), role=brother_role.key()) urole6 = UserRoleModel(user=default_users[4].key(), role=webmaster_role.key()) urole1.put() urole2.put() urole3.put() urole4.put() urole5.put() urole6.put() version = SetupModel(version=os.environ['CURRENT_VERSION_ID']) version.put() flash('Setup the application!', 'success') else: flash('Application is already setup', 'error') return redirect('/')
def test_kwargs(self): """This method tests whether the create_user function will accept kwargs""" new_user = accounts.create_user("John", "Schmidt", "jjs11", "password", mname="Jacob Jinglehiemer") self.assertEqual(new_user._User__UserModel.mname, "Jacob Jinglehiemer") # pylint: disable=W0212,C0301
def setup(): """ This view will check the datastore for a SetupModel entity with the same version id as this instance. If the entity exists it will redirect the user to the homepage. Otherwise it will create some default data. WARNING: This is simply a convenience method. It will also clear out all data for all versions!! It will need to be changed in subsequent versions """ query = SetupModel.all() query.filter("version =", os.environ["CURRENT_VERSION_ID"]) if query.count() == 0: # the app hasn't been setup yet # db.delete(db.Entry.all(keys_only=True)) boehms = FamilyModel(name="boehms") boehms.put() snm = FamilyModel(name="s & m") snm.put() newpham = FamilyModel(name="new pham") newpham.put() default_users = [] default_users.append( create_user("Devin", "Schwab", "dts34", "default", family=boehms.key(), avatar="*****@*****.**") ) default_users.append(create_user("Jon", "Chan", "jtc77", "default")) default_users.append(create_user("Zach", "Zanes", "zzz111", "password")) default_users.append(create_user("Zach", "Zaney", "zzz222", "password1@")) default_users.append(create_user("Adam", "Min", "admin", "password")) webmaster_role = RoleModel(name="webmaster", desc="administrator for the website") webmaster_role.put() brother_role = RoleModel(name="brother", desc="general brother in the chapter") brother_role.put() pledge_role = RoleModel(name="pledge", desc="pledge in the chapter") pledge_role.put() neophyte_role = RoleModel(name="neophyte", desc="neophyte in the chapter") neophyte_role.put() # default_users = find_users() urole1 = UserRoleModel(user=default_users[0].key(), role=webmaster_role.key()) urole2 = UserRoleModel(user=default_users[0].key(), role=brother_role.key()) urole3 = UserRoleModel(user=default_users[1].key(), role=webmaster_role.key()) urole4 = UserRoleModel(user=default_users[1].key(), role=webmaster_role.key()) urole5 = UserRoleModel(user=default_users[2].key(), role=brother_role.key()) urole6 = UserRoleModel(user=default_users[4].key(), role=webmaster_role.key()) urole1.put() urole2.put() urole3.put() urole4.put() urole5.put() urole6.put() version = SetupModel(version=os.environ["CURRENT_VERSION_ID"]) version.put() flash("Setup the application!", "success") else: flash("Application is already setup", "error") return redirect("/")