def test_find_found_in_id_map_found_in_DB(monkeypatch): # Test Data unexpected = Waiting('room', User('name', 'password'), 'time', 'description', Equipment("trcyvu"), 1) expected = Waiting('room1', User('name2', 'password3'), 'time1', 'description2', Equipment("fgvkgas"), 2) # Mock def id_find(_, __): return expected def tdg_find(_): return [[ unexpected.getId(), unexpected.getRoom(), unexpected.getUser(), unexpected.getDescription(), unexpected.getTimeslot() ]] monkeypatch.setattr(IdMap, 'find', id_find) monkeypatch.setattr(WaitingTDG, 'find', tdg_find) # Execute val = WaitingMapper.find(1) # Verify assert (val.getTimeslot() is expected.getTimeslot()) assert (val.getRoom() is expected.getRoom()) assert (val.getUser() is expected.getUser()) assert (val.getDescription() is expected.getDescription()) assert (val.getId() is expected.getId())
def test_setting_password(monkeypatch): #Initialization user = User("taimoor","secretTaimoorPassword") #The password is not really secret assert user.getPassword() == "secretTaimoorPassword" #Checking for comparison between different passwords assert not user.getPassword() == "someOtherString" #Checking that internally automagically the # string case is not being ignored... assert not user.getPassword() == "secrettaimoorpassword"
def test_find_found_in_id_map_not_found_in_DB(monkeypatch): # Test Data expected = Waiting("room", User("mammad", "password"), Timeslot(1, 2, "date", 1, "mammad", "timeID_ibuon"), 'description', Equipment('equipment'), "waitingID_vubion") # Mock def id_find(_, __): return expected def no_find(_): return monkeypatch.setattr(IdMap, 'find', id_find) monkeypatch.setattr(WaitingTDG, 'find', no_find) # Execute val = WaitingMapper.find("waitingID_vubion") # Verify assert (val.getTimeslot() is expected.getTimeslot()) assert (val.getRoom() is expected.getRoom()) assert (val.getUser() is expected.getUser()) assert (val.getDescription() is expected.getDescription()) assert (val.getId() is expected.getId())
def reservation_not_found(_): room = Room(1) user = User('buddy', 'boy') time = Timeslot(1, 2, datetime(2020, 01, 01), '', 1, 1) equipment = Equipment("EquipmentID_iionask") return Reservation(room, user, time, 'description', equipment, 'test')
def test_find_not_found_in_id_map_found_in_DB(monkeypatch): # Test Data expected_timeslot = Timeslot(1, 2, 'date', 1, 'usernameid','timeid') expected_room = Room(1) expected = Reservation(expected_room, User('name', 'password'), expected_timeslot, 'description', Equipment("3w4ex5rcy"), "reservationID####") # Mock def no_find(_, __): return def yes_find(_): return [[expected.getId(), expected_room.getId(), expected.getDescription(), expected.getUser().getId(), expected.getEquipment().getId(), expected_timeslot.getId()]] def timeslot_find(_): return expected_timeslot def room_find(_): return expected_room monkeypatch.setattr(IdMap, 'find', no_find) monkeypatch.setattr(ReservationTDG, 'find', yes_find) monkeypatch.setattr(TimeslotMapper, 'find', timeslot_find) monkeypatch.setattr(RoomMapper, 'find', room_find) # Execute val = ReservationMapper.find("trcyv") # Verify assert(val.getRoom().getId() is expected_room.getId()) assert(val.getDescription() is expected.getDescription()) assert(val.getTimeslot().getId() is expected_timeslot.getId()) assert(val.getId() is expected.getId())
def reservation_create(*args, **kwargs): room = Room(1) user = User('buddy', 'boy') time = Timeslot(1, 2, datetime(2020, 01, 01), 1, "userID_tyvub", "timeslotID_ugvhbjk") return Reservation(room, user, time, 'description', Equipment("equipmentID_yvhjb"), "reservationID_vghjbk")
def find_by_room(*args, **kwargs): room = Room(1) user = User('buddy', 'boy') time = Timeslot(1, 2, datetime(2020, 01, 01), 1, "userID_ibun", "timeslotID_vuhbjk") return [ Reservation(room, user, time, 'description', Equipment("equipmentID_vguhbikjn"), "reservationID_tcytvuhb") ]
def find_by_user(*args, **kwargs): room = Room(1) user = User('buddy', 'boy') time = Timeslot(1, 2, datetime(2020, 01, 01), 1, "userID_bijknklm", "timeslotID_ghvjbk") return [ Reservation(room, user, time, 'description', Equipment("equipmentID_hgcvjb"), "reservationID_vuhbiuj") ]
def find_by_room(*args, **kwargs): room = Room(1) user = User('buddy', 'boy') time = Timeslot(1, 2, datetime(2020, 01, 01), 1, "userID_vubin", "timeslotID_hbijkn") return [ Reservation(room, user, time, 'description', Equipment("equipmentID_uyvbin"), "reservationID_ygvuhjbk") ]
def reservations_found(): room = Room(1) user = User('buddy', 'boy') time = Timeslot(1, 2, datetime(2020, 01, 01), 1, 'buddy', 'timeslotID_7g8hij') return [ Reservation(room, user, time, 'description', Equipment("equipmentID_ionoi"), "reservationID") ]
def test_find_found_in_id_map_not_found_in_DB(monkeypatch): # Test Data expected = User('joel', 'shmoel', True) # Mock def id_find(_, __): return expected def no_find(_): return monkeypatch.setattr(IdMap, 'find', id_find) monkeypatch.setattr(UserTDG, 'find', no_find) # Execute val = UserMapper.find(1) # Verify assert (val.getPassword() is expected.getPassword()) assert (val.getId() is expected.getId()) assert (val.isCapstone() is expected.isCapstone())
def test_find_not_found_in_id_map_found_in_DB(monkeypatch): # Test Data expected_timeslot = Timeslot(1, 2, 'date', 1, 'usernameid', 'timeid') expected_room = Room(1) expected_user = User('abe', 3) expected_equipment = Equipment("equipmentID_uvibonpm") expected = Waiting(expected_room, expected_user, expected_timeslot, 'joe', expected_equipment, 234) # Mock def no_find(_, __): return def yes_find(_): return [[ expected.getId(), expected.getRoom(), expected.getUser(), expected.getDescription(), expected_equipment.getId(), expected.getTimeslot().getId() ]] def timeslot_find(_): return expected_timeslot def room_find(_): return expected_room def user_find(_): return expected_user monkeypatch.setattr(IdMap, 'find', no_find) monkeypatch.setattr(WaitingTDG, 'find', yes_find) monkeypatch.setattr(TimeslotMapper, 'find', timeslot_find) monkeypatch.setattr(RoomMapper, 'find', room_find) monkeypatch.setattr(UserMapper, 'find', user_find) # Execute val = WaitingMapper.find("iyubon") # Verify assert (val.getTimeslot() is expected_timeslot) assert (val.getRoom() is expected_room) assert (val.getUser() is expected_user) assert (val.getDescription() is expected.getDescription()) assert (val.getId() is expected.getId())
async def get_users(self): while True: data = await r.post(f'{self.url}/c/get-users', data={'id': self.id}) if data is None: continue if data['status'] == 'success' and len(data['users']) > 0: break await asyncio.sleep(15) users = data['users'] log.info(f'Retrieved {len(users)} users from the base.') for user in users: g.user_handler.append( User(user['vk_websocket'], user['vk_id'], user['delay']))
async def main(): g.stats = Stats() if config.mode == 1: proxy_f = '/app/proxies.list' else: proxy_f = 'proxies.list' with open(proxy_f) as f: g.proxy_list = f.read().splitlines() if config.mode == 1: matb = MotherBase(mother_api) try: ensure_future(matb.get_users()) ensure_future(matb.run_interaction_loop()) while True: await asyncio.sleep(1) except Exception as e: log.error(f'Main thread exception: {e}') finally: await matb.shutdown() elif config.mode == 2: with open(f'../../core/db/{config.single_db}') as f: users = json.loads(f.read()) for user in users: g.user_handler.append(User(user['url'], user['user_id'], randint(1, 3))) with open(f'../../core/tasks/{config.single_task}') as f: tasks = json.loads(f.read()) # shuffle(tasks) g.task_handler.extend(tasks) while True: tracemalloc.start() await asyncio.sleep(120) snapshot = tracemalloc.take_snapshot() top_stats = snapshot.statistics('lineno') print("[ Top 10 ]") for stat in top_stats[:10]: print(stat) else: log.error('Unknown launch mode.')
def test_find_found_in_id_map_not_found_in_DB(monkeypatch): # Test Data expected = Reservation('room', User('name', 'password'), 'time', 'description',Equipment("dxhtcfjygv"), 1) # Mock def id_find(_, __): return expected def no_find(_): return monkeypatch.setattr(IdMap, 'find', id_find) monkeypatch.setattr(ReservationTDG, 'find', no_find) # Execute val = ReservationMapper.find("vuybi") # Verify assert(val.getRoom() is expected.getRoom()) assert(val.getDescription() is expected.getDescription()) assert(val.getTimeslot() is expected.getTimeslot()) assert(val.getId() is expected.getId())
def test_change_capstone_status(monkeypatch): #Initialization user1 = User("arek","secretArekPassword") user2 = User("bruce","secretBrucePassword",False) user3 = User("cc","secretCCPassword",True) #By default, users are not capstone students, # so making sure this is correctly enforced assert user1.isCapstone() == False assert user2.isCapstone() == False assert user3.isCapstone() == True #Forcing capstone attribute to False user1.setCapstone(False) user2.setCapstone(False) user3.setCapstone(False) #Student should now be a regular student assert user1.isCapstone() == False assert user2.isCapstone() == False assert user3.isCapstone() == False #Granting student capstone status user1.setCapstone(True) user2.setCapstone(True) #By default, this method can # be called with no arguments... user3.setCapstone() #Checking user3 assert user3.isCapstone() == True #Student now is a capstone student assert user1.isCapstone() == True #Taking off capstone status, returning to regular student status user1.setCapstone(False) #Making sure student is really a regular student assert user1.isCapstone() == False
def makeNew(username, password, capstone): user = User(username, password, capstone) UnitOfWork.registerNew(user) return user
def find(username): result = UserTDG.find(username) if not result: return else: return User(result[0][0], result[0][1], result[0][2])
def delete(username): UnitOfWork.registerDeleted(User(username, None, None))
def user_find(_): return User('buddy', 'boy')