def test_delete_user(self): self.new_user.save_new_user() test_user = User("Rovine", 2345) test_user.save_new_user() self.new_user.delete_user() self.assertEqual(len(User.User_List),1)
class TestUser(unittest.TestCase): def setUp(self): self.new_user = User('Raphael', 'Katana', '0720132613') #new user self.new_credentials = Credentials('1123', 'hjk') #new credentials def test_init(self): self.assertEqual(self.new_user.f_name, 'Raphael') self.assertEqual(self.new_user.l_name, 'Katana') self.assertEqual(self.new_user.p_number, '0720132613') #assert test for credentials self.assertEqual(self.new_credentials.acc_name, '1123') self.assertEqual(self.new_credentials.password, 'hjk') def tearDown(self): user_details = [] user_info = [] #test to check if user detailsare saved def test_save_user(self): self.new_user.save_user() self.assertEqual(len(User.user_info), 2) #test to check if credentials are saved self.new_credentials.save_info() self.assertEqual(len(Credentials.user_details), 4) #Test to check if multiple accounts can be saved def test_multi_save(self): self.new_user.save_user() self.new_user = User('Kk', 'pk', '1432') self.assertEqual(len(User.user_info), 1) #test for credentials self.new_credentials.save_info() self.new_credentials = Credentials('23', 'kde') self.assertEqual(len(Credentials.user_details), 3) #test to check for profile and details def check_profile_name(self): self.new_credentials.save_info() unique_user = Credentials('kbc', '5360') unique_user.save_info() search_user = Credentials.search_acc_name('kbc') self.assertEqual(search_user.password, unique_user.password) def test_acc_exists(self): self.new_credentials.save_info() new_acc = Credentials('kcb', '1020') new_acc.save_info() new_acc = Credentials.acc_exist('1123') self.assertTrue(new_acc) def test_show_details(self): self.assertEqual(Credentials.show_details(), Credentials.user_details)
def test_multi_save(self): self.new_user.save_user() self.new_user = User('Kk', 'pk', '1432') self.assertEqual(len(User.user_info), 1) #test for credentials self.new_credentials.save_info() self.new_credentials = Credentials('23', 'kde') self.assertEqual(len(Credentials.user_details), 3)
def test_delete_user(self): ''' delete user's account ''' self.new_user.save_user() test_user=User("mwalo254","mwalo254") test_user.save_user() self.new_user.delete_user() self.assertEqual(len(User.user_list),1)
class TestUser(unittest.TestCase): def setUp(self): self.new_user = User("Wanjala", 12345) def test_init(self): self.assertEqual(self.new_user.username,"Wanjala") self.assertEqual(self.new_user.password,12345) def test_save_user(self): self.new_user.save_new_user() self.assertEqual(len(User.User_List),1) def test_save_multiple_user(self): self.new_user.save_new_user() second_user = User("Rovine",2345) second_user.save_new_user() self.assertEqual(len(User.User_List),2) def tearDown (second_user): User.User_List = [] def test_display_all_users(self): self.assertEqual(User.display_users(),User.User_List) def test_delete_user(self): self.new_user.save_new_user() test_user = User("Rovine", 2345) test_user.save_new_user() self.new_user.delete_user() self.assertEqual(len(User.User_List),1)
def create_account(users_name, username, password): """ function to create new credentials for a new account """ new_account = User(users_name) new_account = Credentials(username, password) return new_account
def valid_username_cookie(username): # DB lookup here for user username = username.split('|') if (not len(username) == 2): return None user = User.lookup_user(username[0]) if (user and user.pw_hash == username[1]): return user else: return None
def __init__(self, parent): QObject.__init__(self, parent) self._parent = parent self._user = User() self._control_mode = self.AUTOMATIC self._lng = self.DEFAULT_LNG self._default = 0 self._emer = False self._what = ''
def post(self): username = self.request.get('username') password = self.request.get('password') pw_hash = User.check_credentials(username, password) if (not pw_hash): self.render("login.html", login_error="Invalid login") else: self.redirect("/welcome") self.response.headers.add_header( 'Set-Cookie', str('username=%s|%s; Path=/' % (username, pw_hash)))
def post(self): username = self.request.get('username') password = self.request.get('password') verify = self.request.get('verify') email = self.request.get('email') invalid_username = "" invalid_password = "" invalid_verify = "" invalid_email = "" if (not chk_username(username)): invalid_username = "******" if (not chk_password(password)): invalid_password = "******" if (password != verify): invalid_verify = "Your passwords didn't match." if (email and not chk_email(email)): invalid_email = "That's not a valid email." if (not (invalid_username or invalid_password or invalid_verify or invalid_email)): if (User.lookup_user(username)): invalid_username = "******" if (invalid_username or invalid_password or invalid_verify or invalid_email): self.render("signup.html", username=username, email=email, invalid_username=invalid_username, invalid_password=invalid_password, invalid_verify=invalid_verify, invalid_email=invalid_email) else: a = User.make_user(username, password, email) a.put() self.redirect("/welcome") self.response.headers.add_header( 'Set-Cookie', str('username=%s|%s; Path=/' % (a.username, a.pw_hash)))
def get(self): teams = {} individuals = [] # Query all users registered this year. query = Individual.query(Individual.year == YEAR) for member in query: if member.team != -1: if member.team in teams: teams[member.team]['members'].append(member.serialize()) else: teams[member.team] = { 'members': [member.serialize()] } else: individuals.append(member.serialize()) for team_id in teams: record = Team.get_by_id(team_id) teams[team_id]['name'] = record.name teams[team_id]['id'] = int(team_id) teams[team_id]['assigned_id'] = record.assigned_id teams[team_id]['paid'] = record.paid teams[team_id]['user'] = record.user users_query = User.query() users = {} for user in users_query: users[user.key.id()] = user.auth_ids[0] # Inform the client of success. self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps({ 'teams': teams, 'individuals': individuals, 'users': users }))
def test_check_user(self): ''' Function to test whether the login in function check_user works as expected ''' self.new_user = User("mwalo254","mwalo254") self.new_user.save_user() user2 = User('nick','nick9214') user2.save_user() for user in User.user_list: if user.lockname == user2.lockname and user.password == user2.password: current_user = user.lockname return current_user self.assertEqual(current_user,Account.check_user(user2.password,user2.lockname))
def get(self): teams = {} individuals = [] # Query all users registered this year. query = Individual.query(Individual.year == YEAR) for member in query: if member.team != -1: if member.team in teams: teams[member.team]['members'].append(member.serialize()) else: teams[member.team] = {'members': [member.serialize()]} else: individuals.append(member.serialize()) for team_id in teams: record = Team.get_by_id(team_id) teams[team_id]['name'] = record.name teams[team_id]['id'] = int(team_id) teams[team_id]['assigned_id'] = record.assigned_id teams[team_id]['paid'] = record.paid teams[team_id]['user'] = record.user users_query = User.query() users = {} for user in users_query: users[user.key.id()] = user.auth_ids[0] # Inform the client of success. self.response.headers['Content-Type'] = 'application/json' self.response.write( json.dumps({ 'teams': teams, 'individuals': individuals, 'users': users }))
class testUser(unittest.TestCase): ''' Test class that defines test cases for the user class behaviours. Args: unittest.TestCase: TestCase class that helps in creating test cases ''' def setUp(self): ''' Set up method to run before each test cases. ''' self.new_user = User("mwalo","mwalo9214") # create contact object def test_init(self): ''' test_init test case to test if the object is initialized properly ''' self.assertEqual(self.new_user.lockname,"mwalo") self.assertEqual(self.new_user.password,"mwalo9214") def test_save_user(self): ''' test_save_user test case to test if the user's object is saved into the user's list ''' self.new_user.save_user() self.assertEqual(len(User.user_list),2) def test_delete_user(self): ''' delete user's account ''' self.new_user.save_user() test_user=User("mwalo254","mwalo254") test_user.save_user() self.new_user.delete_user() self.assertEqual(len(User.user_list),1)
def user_check(name): return User.check_user(name)
def setUp(self): ''' Set up method to run before each test cases. ''' self.new_user = User("mwalo","mwalo9214") # create contact object
def setUp(self): self.new_user = User("Wanjala", 12345)
class testAccounts(unittest.TestCase): ''' Test class that defines test cases for the account class behaviours. Args: unittest.TestCase: TestCase class that helps in creating test cases ''' def test_check_user(self): ''' Function to test whether the login in function check_user works as expected ''' self.new_user = User("mwalo254","mwalo254") self.new_user.save_user() user2 = User('nick','nick9214') user2.save_user() for user in User.user_list: if user.lockname == user2.lockname and user.password == user2.password: current_user = user.lockname return current_user self.assertEqual(current_user,Account.check_user(user2.password,user2.lockname)) def setUp(self): ''' Set up method to run before each test cases. ''' self.new_account = Account("Github","mwalo254","mwalo9214") def test_init(self): ''' test_init test case to test if the object is initialized properly ''' self.assertEqual(self.new_account.somedia,"Github") self.assertEqual(self.new_account.username,"mwalo254") self.assertEqual(self.new_account.accpassword,"mwalo9214") # def test_save_account(self): # ''' # test_save_account test case to test if the account object is saved into # the account list # ''' # self.new_account.save_account() # self.assertEqual(len(Account.account_list),1) def test_save_account(self): ''' test_save_multiple_account to check if we can save multiple account objects to our account_list ''' self.new_account.save_account() codewars= Account("Codewars","mwalo254","user11") codewars.save_account() self.assertEqual(len(Account.account_list),2) def tearDown(self): ''' tearDown method that does clean up after each test case has run. ''' Account.account_list = [] User.user_list=[] def test_display_accounts(self): ''' method that returns a list of all accounts saved ''' self.new_account.save_account() codewars = Account('Codewars', 'mwalz','user') codewars.save_account() gmail= Account('Gmail','mwalznick','mwalz9214') gmail.save_account() self.assertEqual(len(Account.display_accounts(codewars.somedia)),3) def test_find_by_somedia(self): ''' Test to check if the find_by_somedia method returns the correct account ''' self.new_account.save_account() codewars = Account('Codewars','mwalz','user') codewars.save_account() account_exists = Account.find_by_somedia('Codewars') self.assertEqual(account_exists,codewars) def test_delete_account(self): ''' test_delete_account to test if we can remove an account from our account list ''' self.new_account.save_account() test_account = Account("Codewars","mwalz","user") test_account.save_account() self.new_account.delete_account() self.assertEqual(len(Account.account_list),1) def test_copy_account(self): ''' test to check if the copy an account method copies the correct account ''' self.new_account.save_account() codewars= Account('Codewars','mwalz','user') codewars.save_account() find_account = None for account in Account.user_account_list: find_account=Account.find_by_somedia(account.somedia) return pyperclip.copy(find_account.accpassword) Account.copy_account(self.new_account.somedia) self.assertEqual('mwalo9214',pyperclip.paste()) print(pyperclip.paste())
def test_display_all_users(self): self.assertEqual(User.display_users(),User.User_List)
def test_save_multiple_user(self): self.new_user.save_new_user() second_user = User("Rovine",2345) second_user.save_new_user() self.assertEqual(len(User.User_List),2)
def setUp(self): self.new_user = User('Raphael', 'Katana', '0720132613') #new user self.new_credentials = Credentials('1123', 'hjk') #new credentials
def setUp(self): """ The setup method is used to run before each testcase. """ self.new_account = User("James") #create user object
def create_user(f_name, l_name, p_number): new_user = User(f_name, l_name, p_number) return new_user
def setupUserConfig(self, config_xml): """! Parser xml configuration file. @param config_xml: airbus_cobot_gui configuration path. @type config_xml: string. """ #Check path from configuration file if not os.path.isfile(config_xml): self._context.getLogger().critical('User config file "%s" not found !'%config_xml) #Open and parse xml file xconfig = ElementTree.parse(config_xml).getroot() app_mode = self.APP_MODE_RELEASE try: app_mode = xconfig.attrib['mode'].lower() except: pass lng = Context.DEFAULT_LNG try: lng = xconfig.find('translate').attrib['type'].lower() except: pass xwindow = xconfig.find('window') if xwindow is None: self._context.getLogger().critical('Cannot found "<window>" tag into config file !') return try: self.display_mode = xwindow.attrib['display-mode'].lower() except: self.display_mode = "" #Read node window for node in xwindow: if node.tag == 'default-size': try: width = int(node.find('width').text) height = int(node.find('height').text) self.resize(width, height) except: self.resize(1920, 1080) elif node.tag == 'header': self.installHeader(node) elif node.tag == 'launcher': self.installLauncher(node) else: self.getContext().getLogger().warn('Invalid tag "%s" into user configuration !'%node.tag) self.getContext().switchLanguage(lng) if app_mode == self.APP_MODE_DEBUG: self.getContext().switchUser(User('Airbus Group', Privilege.EXPERT)) else: # Load default user none -> open login dialog self.getContext().switchUser(User()) login = LoginDialog(self, False) QTimer.singleShot(1000, login.show)
def create_user(myname, mypassword): ''' Function to create a new user's account ''' new_user = User(myname, mypassword) return new_user
def display_details(): return Credentials.show_details() return User.show_profile()