def test_get_phone_info_for_employee(self): # TODO write this test and remove the self.fail() statement # Create some phones, and employees, assign a phone, # call phone_info and verify correct phone info is returned # TODO check that the method returns None if the employee does not have a phone # TODO check that the method raises an PhoneError if the employee does not exist testPhone1 = Phone(1, 'Apple', 'iPhone 6') testPhone2 = Phone(2, 'Apple', 'iPhone 5') testEmployee1 = Employee(1, 'Alice') testEmployee2 = Employee(2, 'Bill') testEmployee3 = Employee(3, 'Ted') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_phone(testPhone1) testAssignmentMgr.add_phone(testPhone2) testAssignmentMgr.add_employee(testEmployee1) testAssignmentMgr.add_employee(testEmployee2) testAssignmentMgr.add_employee(testEmployee3) testAssignmentMgr.assign(testPhone1.id, testEmployee1) testAssignmentMgr.assign(testPhone2.id, testEmployee2) self.assertEqual(testAssignmentMgr.phone_info(testEmployee1), testPhone1) self.assertEqual(testAssignmentMgr.phone_info(testEmployee2), testPhone2) self.assertIsNone(testAssignmentMgr.phone_info(testEmployee3)) with self.assertRaises(PhoneError): testAssignmentMgr.assign(testAssignmentMgr.phone_info(None))
def test_get_phone_info_for_employee(self): # TODO write this test and remove the self.fail() statement # Create some phones, and employees, assign a phone, # call phone_info and verify correct phone info is returned # TODO check that the method returns None if the employee does not have a phone # TODO check that the method raises an PhoneError if the employee does not exist test_employee1 = Employee(1, 'Mike') test_employee2 = Employee(2, 'Amanda') test_employee3 = Employee(3, 'Jake') test_employee10 = Employee(10, 'Does not exist') testPhone1 = Phone(1, 'Apple', 'iPhone 5') testPhone2 = Phone(2, 'Samsung', 'Edge') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_employee(test_employee1) testAssignmentMgr.add_employee(test_employee2) testAssignmentMgr.add_employee(test_employee3) testAssignmentMgr.add_phone(testPhone1) testAssignmentMgr.add_phone(testPhone2) testAssignmentMgr.assign(testPhone1.id, test_employee1) testAssignmentMgr.assign(testPhone2.id, test_employee2) self.assertTrue( testAssignmentMgr.phone_info(test_employee1) == testPhone1) self.assertTrue( testAssignmentMgr.phone_info(test_employee2) == testPhone2) self.assertIsNone(testAssignmentMgr.phone_info(test_employee3)) with self.assertRaises(PhoneError): testAssignmentMgr.phone_info(test_employee10)
def test_un_assign_phone(self): # TODO write this test and remove the self.fail() statement # Assign a phone, unasign the phone, verify the employee_id is None test_employee1 = Employee(1, 'Mike') test_employee2 = Employee(2, 'Amanda') test_employee3 = Employee(3, 'Jake') testPhone1 = Phone(1, 'Apple', 'iPhone 5') testPhone2 = Phone(2, 'Samsung', 'Edge') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_employee(test_employee1) testAssignmentMgr.add_employee(test_employee2) testAssignmentMgr.add_employee(test_employee3) testAssignmentMgr.add_phone(testPhone1) testAssignmentMgr.add_phone(testPhone2) testAssignmentMgr.assign(testPhone1, test_employee1) testAssignmentMgr.assign(testPhone2, test_employee2) testAssignmentMgr.un_assign(testPhone1) self.assertTrue(testPhone1.employee_id == None)
def test_get_phone_info_for_employee(self): # Test if correct phone info is returned testEmployee1 = Employee(1, 'Marissa') testEmployee2 = Employee(2, 'Christine') testEmployee3 = Employee(3, 'Kimarlee') testEmployee4 = Employee(4, 'Jennifer') testPhone1 = Phone(1, 'Apple', 'iPhone 6') testPhone2 = Phone(2, 'Apple', 'iPhone 5') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_employee(testEmployee1) testAssignmentMgr.add_employee(testEmployee2) testAssignmentMgr.add_employee(testEmployee3) testAssignmentMgr.add_phone(testPhone1) testAssignmentMgr.add_phone(testPhone2) testAssignmentMgr.assign(testPhone1.id, testEmployee1) testAssignmentMgr.assign(testPhone2.id, testEmployee2) self.assertTrue(testPhone1.id, testAssignmentMgr.phone_info(testEmployee1)) self.assertTrue(testPhone2.id, testAssignmentMgr.phone_info(testEmployee2)) # Return None for testEmployee3 who does not have a phone self.assertEqual(None, testAssignmentMgr.phone_info(testEmployee3)) # Raises PhoneError for testEmployee4 who has not been added with self.assertRaises(PhoneError): testAssignmentMgr.phone_info(testEmployee4)
def test_assign_phone_to_employee(self): # TODO write this test and remove the self.fail() statement # TODO you'll need to fix the assign method in PhoneAssignments test_employee1 = Employee(1, 'Mike') test_employee2 = Employee(2, 'Amanda') test_employee3 = Employee(3, 'Jake') testPhone1 = Phone(1, 'Apple', 'iPhone 6') testPhone2 = Phone(2, 'Apple', 'iPhone 5') testPhone3 = Phone(3, 'Samsung', 'Edge') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_employee(test_employee1) testAssignmentMgr.add_employee(test_employee2) testAssignmentMgr.add_employee(test_employee3) testAssignmentMgr.add_phone(testPhone1) testAssignmentMgr.add_phone(testPhone2) testAssignmentMgr.add_phone(testPhone3) testAssignmentMgr.assign(testPhone1.id, test_employee1) testAssignmentMgr.assign(testPhone2.id, test_employee2) testAssignmentMgr.assign(testPhone3.id, test_employee3) self.assertTrue(testPhone1.is_assigned()) self.assertTrue(testPhone1.employee_id == test_employee1.id)
def main(): assignments = PhoneAssignments() phone1 = Phone(1, 'Samsung', 'Galaxy Note 7') phone2 = Phone(2, 'Samsung', 'Galaxy S III') phone3 = Phone(3, 'Samsung', 'Galaxy A7') assignments.add_phone(phone1) assignments.add_phone(phone2) assignments.add_phone(phone3) employee1 = Employee(1, 'Alice') employee2 = Employee(2, 'Bill') employee3 = Employee(3, 'Ted') assignments.add_employee(employee1) assignments.add_employee(employee2) assignments.add_employee(employee3) assignments.assign(phone1.id, employee2) # Assign phone 1 to employee 2 assignments.assign(phone2.id, employee3) # Assign phone 2 to employee 3 print( assignments.phone_info(employee1)) # Employee 1, no phone. Prints None print(assignments.phone_info(employee2)) # Employee 2, has Phone 1 print(assignments.phone_info(employee3)) # Employee 3 has Phone 2 assignments.un_assign( phone2.id) # un-assign phone 2 (which belonged to employee 3) print(assignments.phone_info(employee3)) # None assignments.assign(phone3.id, employee3) # Assign phone 3 to employee 3
def test_get_phone_info_for_employee(self): # TODO write this test and remove the self.fail() statement # Create some phones, and employees, assign a phone, # call phone_info and verify correct phone info is returned # TODO check that the method returns None if the employee does not have a phone # TODO check that the method raises an PhoneError if the employee does not exist testEmployee1 = Employee(1, 'Dani') testEmployee2 = Employee(2, 'Beryl') testEmployee3 = Employee(3, 'Archie') testEmployee4 = None testPhone1 = Phone(1, 'Apple', 'New iPhone 10 Pro XL lite++ Max') testPhone2 = Phone(2, 'Nintendo', 'Nintendo Switch Cell Phone') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_employee(testEmployee1) testAssignmentMgr.add_employee(testEmployee2) testAssignmentMgr.add_employee(testEmployee3) testAssignmentMgr.add_phone(testPhone1) testAssignmentMgr.add_phone(testPhone2) testAssignmentMgr.assign(testPhone1.id, testEmployee1) testAssignmentMgr.assign(testPhone2.id, testEmployee2) # self.assertEqual('ID: 1 Make: Apple Model: New iPhone 10 Pro XL lite++ Max Assigned to Employee ID: 1', testAssignmentMgr.phone_info(testEmployee1)) # self.assertEqual('ID: 2 Make: Nintendo Model: Nintendo Switch Cell Phone Assigned to Employee ID: 2', testAssignmentMgr.phone_info(testEmployee2)) with self.assertRaises(PhoneError): testAssignmentMgr.phone_info(testEmployee4)
def test_get_phone_info_for_employee(self): # TODO write this test and remove the self.fail() statement # Create some phones, and employees, assign a phone, # call phone_info and verify correct phone info is returned # TODO check that the method returns None if the employee does not have a phone # TODO check that the method raises an PhoneError if the employee does not exist assignments = PhoneAssignments() phone1 = Phone(1, 'Samsung', 'Galaxy Note 7') phone2 = Phone(2, 'Samsung', 'Galaxy S III') phone3 = Phone(3, 'Samsung', 'Galaxy A7') assignments.add_phone(phone1) assignments.add_phone(phone2) assignments.add_phone(phone3) employee1 = Employee(1, 'Alice') employee2 = Employee(2, 'Bill') employee3 = Employee(3, 'Ted') employee4 = Employee(4, 'Fred') assignments.add_employee(employee1) assignments.add_employee(employee2) assignments.add_employee(employee3) assignments.assign(phone1.id, employee2) # Assign phone 1 to employee 2 assignments.assign(phone2.id, employee3) # Assign phone 2 to employee 3 self.assertEqual(phone1, assignments.phone_info(employee2)) self.assertIsNone(assignments.phone_info(employee1)) with self.assertRaises(PhoneError): assignments.phone_info(employee4)
def test_get_phone_info_for_employee(self): # TODO write this test and remove the self.fail() statement # Create some phones, and employees, assign a phone, # call phone_info and verify correct phone info is returned # TODO check that the method returns None if the employee does not have a phone # TODO check that the method raises an PhoneError if the employee does not exist test_PhoneAssignments = PhoneAssignments() employee1 = Employee(1, 'Alice') employee2 = Employee(2, 'Bob') employee3 = Employee(3, 'Caitie') employee4 = Employee(4, 'Dan') phone1 = Phone(1, 'Samsung', 'Galaxy Note 15') phone2 = Phone(2, 'Samsung', 'Ultra HD') test_PhoneAssignments.add_employee(employee1) test_PhoneAssignments.add_employee(employee2) test_PhoneAssignments.add_employee(employee3) test_PhoneAssignments.add_phone(phone1) test_PhoneAssignments.add_phone(phone2) test_PhoneAssignments.assign(phone1.id, employee1) test_PhoneAssignments.assign(phone2.id, employee2) print(test_PhoneAssignments.phone_info(employee1)) print(test_PhoneAssignments.phone_info(employee2)) self.assertIsNone(test_PhoneAssignments.phone_info(employee3)) with self.assertRaises(PhoneError): test_PhoneAssignments.phone_info(employee4)
def test_create_and_add_phone_with_duplicate_id(self): test_phone1 = Phone(1, 'Apple', 'iPhone 6') test_phone2 = Phone(1, 'Apple', 'iPhone 5') test_assignment_mgr = PhoneAssignments() test_assignment_mgr.add_phone(test_phone1) with self.assertRaises(PhoneError): test_assignment_mgr.add_phone(test_phone2)
def test_create_and_add_phone_with_duplicate_id(self): # Adds a phone, adds another phone with the same id, and verifies an PhoneError exception is thrown testPhone1 = Phone(1, 'Apple', 'iPhone 6') testPhone2 = Phone(1, 'Apple', 'iPhone 5') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_phone(testPhone1) with self.assertRaises(PhoneError): testAssignmentMgr.add_phone(testPhone2)
def test_assign_phone_to_employee_who_already_has_a_phone(self): testEmployee1 = Employee(1, "Mark Hamil") testPhoneAssigmentsMgr = PhoneAssignments() testPhone2 = Phone(2, 'Apple', 'iPhone 5') testPhone1 = Phone(1, 'Apple', 'iPhone 6') testPhoneAssigmentsMgr.assign(testPhone1, testEmployee1) with self.assertRaises(PhoneError): testPhoneAssigmentsMgr.assign(testPhone2,testEmployee1)
def test_create_and_add_phone_with_duplicate_id(self): testPhone1 = Phone(1, 'Apple', 'iPhone 6') #testphone1 assigned values testPhone2 = Phone(1, 'Apple', 'iPhone 5') #testphone2 assigned values testAssignmentMgr = PhoneAssignments() #assigns new name testAssignmentMgr.add_phone(testPhone1) #adds phone 1 with self.assertRaises(PhoneError): #raises error when testphone2 is added testAssignmentMgr.add_phone(testPhone2)
def test_assign_phone_to_employee_who_already_has_a_phone(self): # TODO write this test and remove the self.fail() statement # TODO you'll need to fix the assign method in PhoneAssignments so it raises a PhoneError if the phone is alreaady assigned. testPhone1 = Phone(1, 'Apple', 'iPhone 6') #testphone1 assigned values testEmployee1 = Employee(1, 'John', 'Jacobs') #assigns employee1 data testPhone2 = Phone(2, 'Apple', 'iPhone 5') assign(self, testPhone1, testEmployee1) # assigns phone to employee with self.assertRaises(PhoneError): #raises error when phone is assigned to employee with phone
def test_create_and_add_new_employee(self): # TODO write this test and then remove the self.fail() statement testEmployee1 = Phone(1, 'John', 'Mary') testEmployee2 = Phone(2, 'Robert', 'Stedfeld') Employee = [testEmployee1, testEmployee2] testAssignmentMgr = Employee() testAssignmentMgr.add_Employee(testEmployee1) testAssignmentMgr.add_Employee(testEmployee2)
def test_assign_phone_to_employee(self): # TODO write this test and remove the self.fail() statement # TODO you'll need to fix the assign method in PhoneAssignments testEmployee = Employee(1, 'Qaalib') testPhone = Phone(1, 'Apple', 'IPhone 10') testPhone2 = Phone(2, 'Apple', 'IPhone X') testManager = PhoneAssignments() testManager.add_phone(testPhone2) testManager.add_phone(testPhone) testManager.add_employee(testEmployee) self.assertEqual(testPhone, testManager.assign(testPhone.id, testEmployee))
def test_create_and_add_phone_with_duplicate_id(self): # TODO add a phone, add another phone with the same id, and verify an PhoneError exception is thrown # TODO you'll need to modify PhoneAssignments.add_phone() to make this test pass testPhone1 = Phone(1, 'Apple', 'iPhone 6') testPhone2 = Phone(1, 'Apple', 'iPhone 5') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_phone(testPhone1) with self.assertRaises(PhoneError): testAssignmentMgr.add_phone(testPhone2)
def test_assign_phone_to_employee_who_already_has_a_phone(self): # TODO write this test and remove the self.fail() statement # TODO you'll need to fix the assign method in PhoneAssignments so it raises a PhoneError if the phone is already assigned. testEmployee1 = Employee(1, "Jim Carey") testPhoneAssigmentsMgr = PhoneAssignments() testPhone2 = Phone(2, 'Apple', 'iPhone 5') testPhone1 = Phone(1, 'Apple', 'iPhone 6') testPhoneAssigmentsMgr.assign(testPhone1, testEmployee1) with self.assertRaises(PhoneError): testPhoneAssigmentsMgr.assign(testPhone2,testEmployee1)
def test_assign_phone_to_employee(self): # TODO write this test and remove the self.fail() statement # TODO you'll need to fix the assign method in PhoneAssignments employee = Employee(1, 'John') testAssignmentMgr = PhoneAssignments() phone = Phone(1, 'Apple', 'iPhone 6') testAssignmentMgr.add_phone(phone) testAssignmentMgr.add_employee(employee) testAssignmentMgr.assign(phone.id, employee) self.assertIsNotNone(phone.is_assigned())
def test_assign_phone_to_employee_who_already_has_a_phone(self): test_phone1 = Phone(1, "Samsung", "Galaxy S2") test_phone2 = Phone(2, "Bedrock", "Pterodactyl") test_employee1 = Employee(1, "Fred Flintstone") test_assignments_mgr = PhoneAssignments() test_assignments_mgr.add_phone(test_phone1) test_assignments_mgr.add_employee(test_employee1) test_assignments_mgr.assign(test_phone1.id, test_employee1) with self.assertRaises(PhoneError): test_assignments_mgr.assign(test_phone2, test_employee1)
def test_assign_phone_to_employee_who_already_has_a_phone(self): # TODO write this test and remove the self.fail() statement # TODO you'll need to fix the assign method in PhoneAssignments so it raises a PhoneError if the phone is alreaady assigned. testEmployee = Employee(1, 'MC Bat Commander') testPhone = Phone(1, 'Apple', 'iPhone') testPhone2 = Phone(2, 'Dumb Apple', 'Dumb iPhone') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.assign(testPhone.id, testEmployee) with self.assertRaises(PhoneError): testAssignmentMgr.assign(testPhone2.id, testEmployee)
def test_assign_phone_to_employee(self): # TODO write this test and remove the self.fail() statement # TODO you'll need to fix the assign method in PhoneAssignments testAssigmentMgr = PhoneAssignments( ) # This is used for the phones and employees. testPhone1 = Phone(1, 'Apple', 'iPhone 6') testPhone3 = Phone(3, 'Apple', 'iPhone 7') testEmployee2 = Employee(4, 'Smith') # Had to modify this one to make it pass self.assertFalse(testAssigmentMgr.assign(testPhone3.id, testEmployee2))
def test_create_and_add_new_phone(self): testPhone1 = Phone(1, 'Apple', 'iPhone 6') testPhone2 = Phone(2, 'Apple', 'iPhone 5') testPhones = [testPhone1, testPhone2] testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_phone(testPhone1) testAssignmentMgr.add_phone(testPhone2) # assertCountEqual checks if two lists have the same items, in any order. # (Despite what the name implies) self.assertCountEqual(testPhones, testAssignmentMgr.phones)
def test_create_and_add_phone_with_duplicate_id(self): # Test raise PhoneError for adding the same phone ID testPhone1 = Phone(1, 'Apple', 'iPhone 6') testPhone2 = Phone(1, 'Apple', 'iPhone 5') testPhone3 = Phone(1, 'Apple', 'iPhone 7') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_phone(testPhone1) with self.assertRaises(PhoneError): testAssignmentMgr.add_phone(testPhone2) testAssignmentMgr.add_phone(testPhone3)
def test_create_and_add_phone_with_duplicate_id(self): # TODO add a phone, add another phone with the same id, and verify an PhoneError exception is thrown # TODO you'll need to modify PhoneAssignments.add_phone() to make this test pass #creating list of phones testPhone1 = Phone(1, 'Apple', 'iPhone 6') testPhone2 = Phone(2, 'Apple', 'iPhone 5') testPhone3 = Phone(2, 'Apple', 'iPhone 5') #adding phones testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_phone(testPhone1) testAssignmentMgr.add_phone(testPhone2) #testing if there is error when add phone that's already in the list with self.assertRaises(PhoneError): testAssignmentMgr.add_phone(testPhone3)
def test_assign_phone_to_employee_who_already_has_a_phone(self): # TODO write this test and remove the self.fail() statement # TODO you'll need to fix the assign method in PhoneAssignments so it raises a PhoneError if the phone is alreaady assigned. testAssignmentMgr = PhoneAssignments() employee1 = Employee(1, 'Yosemite') #create an employee testAssignmentMgr.add_employee(employee1) #add employee testPhone1 = Phone(1, 'Apple', 'iPhone 6') #create a phone testPhone2 = Phone(2, 'Apple', 'iPhone 5') testAssignmentMgr.add_phone(testPhone1) #add the phone testAssignmentMgr.add_phone(testPhone2) testAssignmentMgr.assign(testPhone1.id, employee1) #assign phoneID 1 to employee1 with self.assertRaises(PhoneError): testAssignmentMgr.assign(testPhone2.id, employee1) #try to assign phone 2 to empl1, who already has a phone should raise Error
def test_assign_phone_to_employee_who_already_has_a_phone(self): test_phone1 = Phone(1, 'Apple', 'iPhone 420') test_phone2 = Phone(2, 'Samsung', 'Galaxy 420') test_employee = Employee(1, 'Snoop Dogg') test_assignment_manager = PhoneAssignments() test_assignment_manager.add_phone(test_phone1) test_assignment_manager.add_phone(test_phone2) test_assignment_manager.add_employee(test_employee) test_assignment_manager.assign(1, test_employee) with self.assertRaises(PhoneError): test_assignment_manager.assign(2, test_employee)
def test_assign_phone_to_employee_who_already_has_a_phone(self): # TODO write this test and remove the self.fail() statement # TODO you'll need to fix the assign method in PhoneAssignments so it raises a PhoneError if the phone is alreaady assigned. testEmployee = Employee(1, 'Qaalib') testPhone = Phone(1, 'Apple', 'IPhone 10') testPhone2 = Phone(2, 'Apple', 'IPhone X') testManager = PhoneAssignments() testManager.add_phone(testPhone) testManager.add_phone(testPhone2) testManager.add_employee(testEmployee) testManager.assign(testPhone.id, testEmployee) with self.assertRaises(Exception): testManager.assign(testPhone2.id, testEmployee)
def test_assign_phone_to_employee_who_already_has_a_phone(self): # TODO write this test and remove the self.fail() statement # TODO you'll need to fix the assign method in PhoneAssignments so it raises a PhoneError if the phone is alreaady assigned. testEmployee1 = Employee(1, 'Mark') testPhone1 = Phone(21, 'Samsung', 'Galaxy S9') testPhone2 = Phone(43, 'Apple', 'iPhone 2') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_phone(testPhone1) testAssignmentMgr.add_phone(testPhone2) testAssignmentMgr.assign(43, testEmployee1) with self.assertRaises(PhoneError): testAssignmentMgr.assign(21, testEmployee1)
def test_assign_phone_to_employee_who_already_has_a_phone(self): # write this test and remove the self.fail() statement # you'll need to fix the assign method in PhoneAssignments so it raises a PhoneError if the phone is alreaady assigned. testAssignmentMgr = PhoneAssignments() test_employee = Employee(1, 'Noam Chomsky') test_phone_1 = Phone(1, 'Jitterbug', 'Flip') test_phone_2 = Phone(2, 'Campbell\'s', 'Two Cans and a String') testAssignmentMgr.add_employee(test_employee) testAssignmentMgr.add_phone(test_phone_1) testAssignmentMgr.add_phone(test_phone_2) testAssignmentMgr.assign(1, test_employee) with self.assertRaises(PhoneError): testAssignmentMgr.assign(2, test_employee)