def test_update_parameter_none(self): user = User() user.id = 1 user.name = 'Tomas' user.surename = 'Krystof' user.login = '******' user.password = None result = self.user_repository.update(user) self.assertEqual(result, None)
def test_user_delete_valid(self): user = User() user.id = 3 user.name = 'Johny' user.surename = 'Knoxville' user.login = '******' user.password = 12345 self.user_repository.add_new_user(user) self.user_repository.user_delete(3)
def test_add_new_user_parameter_none(self): user = User() user.id = 2 user.name = None user.surename = 'Sochan' user.login = '******' user.password = 12345 result = self.user_repository.add_new_user(user) self.assertEqual(result, None)
def test_add_new_user_valid(self): user = User() user.id = 2 user.name = 'Jaroslav' user.surename = 'Sochan' user.login = '******' user.password = 12345 self.user_repository.add_new_user(user) self.assertEqual(user.id, 2) self.assertEqual(user.name, 'Jaroslav') self.assertEqual(user.surename, 'Sochan') self.assertEqual(user.login, 'Jaro') self.assertEqual(user.password, 12345)
def test_update_valid(self): user = User() user.id = 1 user.name = 'Tomas' user.surename = 'Krystof' user.login = '******' user.password = 1234 self.user_repository.update(user) self.assertEqual(user.id, 1) self.assertEqual(user.name, 'Tomas') self.assertEqual(user.surename, 'Krystof') self.assertEqual(user.login, 'Toso') self.assertEqual(user.password, 1234)
def get_one_by_id(self, id): if id == None or id < 0: return None self.cursor.execute("SELECT * from projekt.user where id=%d ;" % id) records_user = self.cursor.fetchone() if records_user == None: return None new_user = User() new_user.id = records_user[0] new_user.name = records_user[1] new_user.surename = records_user[2] new_user.login = records_user[3] new_user.password = records_user[4] new_user.lastlogin = records_user[5] new_user.lastlogintime = records_user[6] return new_user
def get_all(self): self.cursor.execute("SELECT * from projekt.user ;") records_user = self.cursor.fetchall() if records_user == None: return None user_list = [] for user in records_user: new_user = User() new_user.id = user[0] new_user.name = user[1] new_user.surename = user[2] new_user.login = user[3] new_user.password = user[4] new_user.lastlogin = user[5] new_user.lastlogintime = user[6] user_list.append(new_user) return user_list
def user_select(self, login_result, pass_result): if login_result == None or pass_result == None: return None user_select_query = "SELECT * from projekt.user where login=%s and password=%s" parameters = (str(login_result), str(pass_result)) self.cursor.execute(user_select_query, parameters) selected_user = self.cursor.fetchone() if selected_user != None: new_user = User() new_user.id = selected_user[0] new_user.name = selected_user[1] new_user.surename = selected_user[2] new_user.login = selected_user[3] new_user.password = selected_user[4] new_user.lastlogin = selected_user[5] new_user.lastlogintime = selected_user[6] return new_user else: return None
'Do you want to delete an user? type yes or no: ') if result_user_del == 'yes': result_user_delete = input( 'Type id of the user you want to delete: ') result = user_repository.user_delete(result_user_delete) result_user_in = input( 'Do you want to add an user? type yes or no: ') if result_user_in == 'no': break if result_user_in == 'yes': user = User() book = Book() user.id = input('Type id of the user you want to add: ') user.name = input('Type name of the user you want to add: ') user.surename = input( 'Type surename of the user you want to add: ') user.login = input('Type login of the user you want to add: ') user.password = input( 'Type password of the user you want to add: ') user_repository.add_new_user(user) book.name_of_the_book = input( 'Type new book for the new user here: ') book.author = input('Type author for the book: ') book_repository.add_new_book(book) break