def remove_project(user: User): """ Remove a project for user :param user: user with all projects """ user.projects = get_projects_by_user_id(user.user_id) if not len(user.projects): return msg = "Insert the project id to remove: " user_input = helpers.get_int(msg) # get all project ids all_projects_id = user.get_projects_id() while user_input not in all_projects_id: print("invalid option, Try again. Type 0 for exit") user_input = helpers.get_int(msg) if user_input == 0: return # Remove project from db project_was_removed = conn.remove_project_by_id(user_input) if not project_was_removed: print("Cannot remove the project") return user.remove_project(user_input) print("Project is removed!")
def test_add_user(self): user_a = User() user_a.id = self.id_manager.get_id() user_a.name = 'user_a' self.assertTrue(self.room.add_user(user_a)) self.assertEqual(user_a, self.room.users[0])
def test_serialization(self): user = User() user.id = 1 user.name = 'Franco' serialized_user = user.serialize() self.assertEqual(serialized_user['name'], 'Franco') self.assertEqual(serialized_user['id'], 1)
def setUp(self): self.controller_1 = ManualController(0) self.controller_2 = ManualController(1) self.user_1 = User(0, self.controller_1) self.user_2 = User(1, self.controller_2) self.engine = Engine() self.engine.add_user(self.user_1) self.engine.add_user(self.user_2) self.engine.deck = Deck(shuffle=False, is_small=False)
def test_serialization(self): user_a = User() user_a.id = self.id_manager.get_id() user_a.name = 'user_a' user_b = User() user_b.id = self.id_manager.get_id() user_b.name = 'user_b' user_names = ['user_a', 'user_b'] self.assertTrue(self.room.add_user(user_a)) self.assertTrue(self.room.add_user(user_b)) serialized = self.room.serialize(only_usernames=True) self.assertEqual(serialized['users'], user_names) self.assertEqual(serialized['id'], 0) self.assertFalse(serialized['inGame']) serialized = self.room.serialize(only_usernames=False) self.assertEqual('user_a', serialized['users'][0]['name']) self.assertEqual(0, serialized['users'][0]['id']) self.assertEqual('user_b', serialized['users'][1]['name']) self.assertEqual(1, serialized['users'][1]['id'])
def main(): while True: game = Engine() user_1 = User(1, AIController(1)) user_2 = User(2, ManualController(2)) game.add_user(user_1) game.add_user(user_2) game.init_game() game.update_users() while not game.is_ended(): game.one_tick() game.outcomes_notify(game.generate_outcomes())
def test_add_too_much_users(self): user_a = User() user_b = User() user_c = User() user_d = User() user_e = User() should_be = [user_a, user_b, user_c, user_d] self.assertTrue(self.room.add_user(user_a)) self.assertTrue(self.room.add_user(user_b)) self.assertTrue(self.room.add_user(user_c)) self.assertTrue(self.room.add_user(user_d)) self.assertFalse(self.room.add_user(user_e)) self.assertNotIn(user_e, self.room.users) self.assertEqual(self.room.users, should_be)
def create_user() -> bool: """ Create a new user and insert into the Database :returns: True if user was created """ # TODO: verify len, number, lower and upper name = input("Insert username: "******"Insert Password: "******"Insert email: ") number = input("Insert phone number: ") # Creating user new_user = User(name=name, email=email, number=number) try: # Insert the user into the database user_id = conn.create_user(user=new_user, password=password) except Exception as e: print("Error in the Database, ", e) return False if user_id == -1: return False return True
def post(self): """Authenticate and get token""" username = self.get_argument('username') password = self.get_argument('password') try: user = User.logon(username, password) except UserNotFound: data = errors.get(errors.INVALID_LOGIN) else: token = utils.get_token() session = { 'username': username, 'token': token } db.sessions.insert(session) data = { 'username': username, 'is_staff': user.is_staff, 'token': token } self.finish(data)
def post(self): """Create user""" username = self.get_argument('username').strip() password = self.get_argument('password').strip() is_staff = True if self.get_argument('is_staff') == '1' else False try: User.create(username, password, is_staff) except UsernameExists: data = errors.get(errors.USERNAME_EXISTS) except UnicodeEncodeError: data = errors.get(errors.BAD_PASSWORD) else: data = { 'status': 'ok' } self.finish(data)
def get(self): """List all users""" users = [] for user in User.objects(): users.append({ 'username': user.username, 'is_staff': user.is_staff, }) self.finish({ 'users': users })
def show_projects_by_user(user: User): """ Print all the projects for a user :param user: user object :return all user projects: """ projects = get_projects_by_user_id(user.user_id) if not len(projects): return user.projects = projects print("\n========================PROJECTS================================") message = "ID: {}, Name: {}, Description: {}" for project in projects: print(message.format(project.project_id, project.name, project.description)) print("==================================================================\n")
return user_id # Close connection def close_connection(self): """Close the connection""" self._conn.close() self._conn = None # -- End of class if __name__ == '__main__': tables = ['user', 'projects', 'task', 'TASK_USER', 'PROJECT_USER', 'PROJECT_TASK'] new_user = User(name="Raul Pichardo", email="*****@*****.**", number="7873776957") conn = SQLiteConnection("./pythonsqlite.db") conn.init_db() # new_user.user_id = conn.create_user(new_user) # conn.create_project(new_user, "Capstone", "Scrum capstone") # conn.add_user_to_project(2, 1) # conn.add_user_to_project(3, 1) # conn.add_user_to_project(4, 1) # conn.get_user_by_email(User.email)
def setUp(self): self.user_1 = User(0, ManualController(0)) self.user_2 = User(1, ManualController(1)) self.game_table = BlackJackGameTable([self.user_1, self.user_2])
def __init__ (self): GameHandler.__init__(self) Character.__init__(self) GradualImprovable.__init__(self) User.__init__(self) self._context = None