def test_staff_save_state(self): path = "db/" file_name = "mydb" file_ = file_name + ".db" #clean up to avoid conflict between tests os.remove(path + file_) self.clear_stores() #memory staff = Staff("onsn", "edsk", "46546412") staff.register() Person.save_state(file_name) #db engine = create_engine("sqlite:///" + path + file_, echo=False) Session = sessionmaker(bind=engine) session = Session() db_staff = session.query(Person).filter_by( phonenumber="46546412").first() #compare full_staff = [ staff.first_name, staff.last_name, staff.phone, staff.type_, staff.opt_in ] full_db_staff = [ db_staff.firstname, db_staff.lastname, db_staff.phonenumber, db_staff.role, db_staff.optin ] session.close() self.assertEqual(full_staff, full_db_staff)
def add_person(first_name, last_name, phone, type_, opt_in="N"): try: type_ = type_.upper() if type_ == "FELLOW": fellow = Fellow(first_name, last_name, phone, opt_in) fellow.register() first_name = fellow.first_name last_name = fellow.last_name type_ = fellow.type_ available_offices = Office.available() if available_offices is False: print_pretty(" There are currently no available offices.") else: selection = random.choice(list(available_offices)) office = Office(selection) office.allocate_to(fellow) print_pretty( " The fellow: %s has been allocated to the office: %s." % (fellow.last_name, office.name)) if fellow.opt_in == "Y": available_livingspaces = LivingSpace.available() if available_livingspaces is False: print_pretty( " There are currently no available living spaces.") else: selection = random.choice(list(available_livingspaces)) livingspace = LivingSpace(selection) livingspace.allocate_to(fellow) print_pretty( " The fellow: %s has been allocated to the living space: %s." % (fellow.last_name, livingspace.name)) print_pretty(" A %s: %s %s has been successfully created." % (type_, first_name, last_name)) elif type_ == "STAFF": staff = Staff(first_name, last_name, phone, opt_in) staff.register() first_name = staff.first_name last_name = staff.last_name type_ = staff.type_ available_offices = Office.available() if available_offices is False: print_pretty(" There are currently no available offices.") else: selection = random.choice(list(available_offices)) office = Office(selection) office.allocate_to(staff) print_pretty( " The staff: %s has been allocated to the office: %s." % (staff.last_name, office.name)) print_pretty(" A %s: %s %s has been successfully created." % (type_, first_name, last_name)) else: print_pretty(" %s is currently not a supported role." % type_) #print(persons_detail) except Exception as e: print_pretty(str(e))
def setUp(self): self.tom_fellow = Fellow('Tom', 'Soyer', True) self.joe_staff = Staff('Joe', 'Swanson') self.becky_staff = Staff('Rebecca', 'Storm', 'The Office') self.occupants = { self.tom_fellow.first_name + ' ' + self.tom_fellow.last_name: self.tom_fellow, self.joe_staff.first_name + ' ' + self.joe_staff.last_name: self.joe_staff, self.becky_staff.first_name + ' ' + self.becky_staff.last_name: self.becky_staff } self.blue_office = Office('Blue Office', self.occupants)
def test_allocate_to_new_staff_space(self): office = Office("staff" + "Foin") staff = Staff("staff" + "Neritus", "staff" + "Otieno", "0784334537") result = len(allocations) office.allocate_to(staff) result_1 = len(allocations) self.assertEqual(result + 1, result_1)
def test_available_office(self): result = Office.available() office = Office('MyO55e89') Office.add(office) staff = Staff("staff" + "Njsiritus", "staff" + "Otsdeno", "0700000537") office.allocate_to(staff) staff = Staff("staff" + "Njsiritus", "staff" + "Otsdeno", "0700001537") office.allocate_to(staff) result_2 = Office.available() staff = Staff("staff" + "Njsiritus", "staff" + "Otsdeno", "0700002537") office.allocate_to(staff) staff = Staff("staff" + "Njsiritus", "staff" + "Otsdeno", "0700003537") office.allocate_to(staff) result_3 = Office.available() self.assertTrue([result, result_3, type(result_2)], [False, False, "set"])
def test_reallocate_existing_staff_to_office(self): office = Office('My9994') Office.add(office) staff = Staff("Ugeg", "Insdnis", "073437") office.allocate_to(staff) with self.assertRaises(ValueError): Room.reallocate(staff, office)
class TestStaff(unittest.TestCase): """Test cases for the staff class""" # Instantiating objects for using in the tests def setUp(self): self.tom_staff = Staff('Tom', 'Soyer') self.becky_staff = Staff('Rebecca', 'Storm', 'The Office') # Test if the class creates an instance of itself def test_staff_instance(self): self.assertIsInstance( self.tom_staff, Staff, msg='The object should be an instance of the `Staff` class') # Test if the class creates an instance of Person def test_person_instance(self): self.assertIsInstance( self.becky_staff, Person, msg='The object should be an instance of the `Person` class') # Test if the class creates a type of itself def test_type(self): self.assertTrue((type(self.becky_staff) is Staff), msg='The object should be of type `Staff`') # Test if reallocate_living_space method returns the right value for the given inputs def test_reallocate(self): self.assertTrue(self.tom_staff.reallocate('Dope'), msg='Tom should get a new office') self.assertEqual('Dope', self.tom_staff.office_name, msg='Tom should get a new office')
def test_arrogate_from_existing_staff(self): office = Office("staff" + 'Focs') staff = Staff("staff" + "Erits", "staff" + "Teno", "0785534224", "Y") office.allocate_to(staff) allocated_1 = office.has_allocation(staff) office.arrogate_from(staff) allocated_2 = office.has_allocation(staff) self.assertEqual([allocated_1, allocated_2], [True, False])
def test_reallocate_staff_to_livingspace(self): office = Office('M777848') Office.add(office) staff = Staff("jjjkkdsj", "liidsls", "0799034987") office.allocate_to(staff) livingspace1 = LivingSpace('U988934') LivingSpace.add(livingspace1) with self.assertRaises(Exception): Room.reallocate(staff, livingspace1)
def get_person(phone): try: return Fellow.from_phone(phone) except ValueError: pass try: return Staff.from_phone(phone) except ValueError: raise ValueError("specifed phone is unknown")
def test_reallocate_staff_to_office(self): office = Office('Myok848') Office.add(office) staff = Staff("UNidng", "Inignis", "07089797537") office.allocate_to(staff) office1 = Office('M949438') Office.add(office1) Room.reallocate(staff, office1) self.assertEqual([office1.has_allocation(staff), office.has_allocation(staff)], [True, False])
def test_allocate_to_staff_no_space(self): office = Office("staff" + 'Focusp') with self.assertRaises(ValueError): x = 0 while (x <= 5): suffix = str(x) staff = Staff("staff" + "Neris" + suffix, "staff" + "Oten" + suffix, "078433448" + suffix, "N") office.allocate_to(staff) x += 1
def authenticate(username, password): username = username.strip() user = Staff.search_username_by_email(username) if user and hashlib.sha1( password.encode('utf-8')).hexdigest() == user.password: return User(id=user.staff_id, user_info={ 'username': user.email, 'first_name': user.first_name, 'last_name': user.last_name, }) return None
def get_staff_by_id(staff_id): try: client = MongoClient(Constant.DB_CONNECTION_URL) document = client[Constant.DB_NAME][StaffDB.COLLECTION_NAME] staff_object = document.find_one({'staffId': staff_id}) staff = Staff(staff_id, staff_object['name'], staff_object['department'], staff_object['phoneNumber'], staff_object['isSecurityStaff']) client.close() return staff except Exception as e: print('unable to get staff') raise Exception('Could not get staff from DB')
def createStaff(): print("Job title:") jobTitle = input() print("ID: {}") id = input() print("Name: {}") name = input() print("SSN: {}") ssn = input() print("Address: {}") address = input() print("Salary: {}") salary = input() cls() return Staff(name, address, ssn, id, jobTitle, salary)
def setUp(self): self.tom_staff = Staff('Tom', 'Soyer') self.becky_staff = Staff('Rebecca', 'Storm', 'The Office')
def test_allocate_to_existing_staff_space(self): office = Office("staff" + "Focuspo") staff = Staff("staff" + "Nerits", "staff" + "Oteno", "0784334222", "N") office.allocate_to(staff) with self.assertRaises(ValueError): office.allocate_to(staff)
def add_person(self, firstname, surname, person_type, wants_accomodation='N'): if person_type.lower() not in ['fellow', 'staff']: return (error('Only fellow and staff allowed!')) if not isinstance(firstname, str) or not isinstance(surname, str): return (error('People names can only be strings!')) if firstname + ' ' + surname in self.all_people: return (error('%s %s exists!' % (firstname, surname))) else: if represents_int(firstname) or represents_int(surname): return error('Names can not be or contain integers!') if person_type.lower() == 'fellow': # create a fellow firstname = firstname.capitalize() surname = surname.capitalize() fellow = Fellow(firstname, surname) self.fellows.append(firstname + ' ' + surname) self.all_people.append(firstname + ' ' + surname) if self.offices: all_offices = list(self.offices.keys()) checked_offices = [] while True: office = random.choice(list(self.offices)) if len(self.offices[office]) < 6: self.offices[office].append(firstname + ' ' + surname) print( success( 'Fellow %s %s has been assigned office %s!' % (firstname, surname, office))) break if office not in checked_offices: checked_offices.append(office) if checked_offices == all_offices: print(error('All offices are full at the moment!')) break else: print(error('No office to assign!')) if wants_accomodation == 'Y': self.wants_accomodation.append(firstname + ' ' + surname) if wants_accomodation == 'Y' and self.livingspaces: all_livingspaces = list(self.livingspaces.keys()) checked_livingspaces = [] while True: room = random.choice(list(self.livingspaces)) if len(self.livingspaces[room]) < 4: self.livingspaces[room].append(firstname + ' ' + surname) print( success( 'Fellow %s %s has been assigned livingspace %s!' % (firstname, surname, room))) break if room not in checked_livingspaces: checked_livingspaces.append(room) if checked_livingspaces == all_livingspaces: print( error( 'All livingspaces are full at the moment!') ) break return (success('Fellow %s %s has been added successfully!' % (firstname, surname))) elif person_type.lower() == 'staff': # create a staff member if wants_accomodation == 'Y': print(error('Staff can not be allocated livingspace!')) staff = Staff(firstname, surname) self.staff.append(firstname + ' ' + surname) self.all_people.append(firstname + ' ' + surname) if self.offices: office = random.choice(list(self.offices)) self.offices[office].append(firstname + ' ' + surname) print( success('Staff %s %s has been assigned office %s!' % (firstname, surname, office))) else: print(error('No office to assign!')) return (success('Staff %s %s has been added successfully!' % (firstname, surname)))
def add_person(first_name, last_name, person_type='', wants_accomodation=False): name = first_name + ' ' + last_name output = '' if name and person_type: if name and name not in get_all_office_occupants(): if not [ a_room for a_room in the_dojo.get_vacant_rooms().values() if isinstance(a_room, Office) ]: initial_room_count = len(the_dojo.rooms) final_room_count = 0 while initial_room_count >= final_room_count: appendix = random.choice( range(0, total_number_of_rooms + 1)) create_room('office', 'Office ' + str(appendix)) final_room_count = len(the_dojo.rooms) an_office = random.choice([ a_room for a_room in the_dojo.get_vacant_rooms().values() if isinstance(a_room, Office) ]) if person_type.lower() == 'fellow': if not wants_accomodation and name not in get_all_office_occupants( ): a_fellow = Fellow(first_name, last_name, wants_accomodation, an_office.name) an_office.occupants[name] = a_fellow if name in get_all_office_occupants(): output += 'Fellow ' + name + ' has been successfully added. \n' + \ first_name + ' has been allocated the office ' + an_office.name elif wants_accomodation and name not in get_all_livingspace_occupants( ) and name not in get_all_office_occupants(): if not [ a_room for a_room in the_dojo.get_vacant_rooms().values() if isinstance(a_room, LivingSpace) ]: initial_room_count = len(the_dojo.rooms) final_room_count = 0 while initial_room_count >= final_room_count: appendix = random.choice( range(0, total_number_of_rooms + 1)) create_room('livingspace', 'Livingspace ' + str(appendix)) final_room_count = len(the_dojo.rooms) a_livingspace = random.choice([ a_room for a_room in the_dojo.get_vacant_rooms().values() if isinstance(a_room, LivingSpace) ]) a_fellow = Fellow(first_name, last_name, wants_accomodation, an_office.name, a_livingspace.name) a_livingspace.occupants[name] = a_fellow an_office.occupants[name] = a_fellow if name in get_all_office_occupants( ) and name in get_all_livingspace_occupants(): output += 'Fellow ' + name + ' has been successfully added. \n' + \ first_name + ' has been allocated the office ' + an_office.name + '\n' + \ first_name + ' has been allocated the livingspace ' + a_livingspace.name elif person_type.lower() == 'staff': a_staff = Staff(first_name, last_name, an_office.name) an_office.occupants[name] = a_staff if name in get_all_office_occupants(): output += 'Staff ' + name + ' has been successfully added. \n' + \ first_name + ' has been allocated the office ' + an_office.name if name not in get_all_office_occupants(): if person_type.lower( ) == 'fellow' and name not in get_all_livingspace_occupants(): new_fellow = Fellow(first_name, last_name) unallocated_people[name] = new_fellow output = 'Fellow ' + name + ' is unallocated' elif person_type.lower() == 'staff': new_staff = Staff(first_name, last_name) unallocated_people[name] = new_staff output = 'Staff ' + name + ' is unallocated' else: new_person = Person(first_name, last_name) unallocated_people[name] = new_person output = 'Person ' + name + ' is unallocated' return output
from models.order import Order from models.store import Store from models.product import Product from models.staff import Staff from models.customer import Customer stores = [ Store(1, "IUT-WebStore Management System", "Deutga", "156-25-63"), ] staffs = [ Staff("Jaiden", "Tashkent", "123465", 12, "Cashier", 5600), Staff("Humongus", "Balls", "965412", 15, "Guard", 7600) ] customers = [ Customer("5632879", "Dave", "Dventiliga", 256, 10, "589-44-85", ["Wings", "Golden"]), Customer("9653287", "Gustavo", "Feritana", 25, 562, "555-44-44", ["Premium"]) ] products = [ Product(123456, "Chocolate Flavor", "Cookies with chocolate", 25, 1), Product(954687, "Meat", "Tasty meat", 50, 5), Product(248984, "Brick", "It is just a brick", 900, 3), Product(967485, "Secret sause", "Special secret Krabsburger sause", 150, 2), Product(336599, "Stick", "Stick for real man", 10, 4) ] orders = [ Order(stores[0], customers[0], staffs[0], [{Order.PRODUCT_KEY:product[0], Order.QUANTITY_KEY: product[1]} for product in [(products[0], 2), (products[1], 3), (products[2], 1)]]),
def test_register_phone_exists_error(self): fellow = Fellow("LIOLZ", "SKIDH", "8483664855", "Y") fellow.register() fellow_1 = Staff("LIOLZ", "SKIDH", "8483664855", "Y") with self.assertRaises(ValueError): fellow_1.register()
def test_creates_staff_instance(self): self.staff = Staff('James', 'Ndiga') self.assertTrue('James' == self.staff.firstname and 'Ndiga' == self.staff.surname)