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_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): # 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): # 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 # check that the method returns None if the employee does not have a phone # check that the method raises an PhoneError if the employee does not exist testAssignmentMgr = PhoneAssignments() employee_with_phone = Employee(1, 'Chimamanda Ngozi Adichie') employee_without_phone = Employee(2, 'William Goldman') nonexistent_employee = Employee(3, 'S. Morgenstern') test_phone = Phone(1, 'Danger', 'Hiptop') testAssignmentMgr.add_employee(employee_with_phone) testAssignmentMgr.add_employee(employee_without_phone) testAssignmentMgr.add_phone(test_phone) testAssignmentMgr.assign(1, employee_with_phone) self.assertEquals( testAssignmentMgr.phone_info(employee_with_phone), test_phone) # test that we can get employee_with_phone's phone self.assertIsNone( testAssignmentMgr.phone_info(employee_without_phone) ) # test that getting phone info for employee_without_phone returns None with self.assertRaises( PhoneError ): # test that getting phone info for a nonexistent_employee raises an exception testAssignmentMgr.phone_info(nonexistent_employee)
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): # 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 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_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_assign_phone_to_employee(self): testPhone1 = Phone(1, 'Apple', 'iPhone 6') testEmployee1 = Employee(1, "Mark Hamil") testPhoneAssigmentsMgr = PhoneAssignments() testPhoneAssigmentsMgr.assign(testPhone1, testEmployee1) self.assertTrue(testPhone1.employee_id == testEmployee1.id)
def test_un_assign_phone(self): # Assign a phone, unasign the phone, verify the employee_id is None testPhone1 = Phone(1, 'Apple', 'iPhone 6') testEmployee1 = Employee(1, "Mark Hamil") testPhoneAssigmentsMgr = PhoneAssignments() testPhoneAssigmentsMgr.assign(testPhone1, testEmployee1) testPhoneAssigmentsMgr.un_assign(testPhone1) self.assertTrue(testPhone1.employee_id == None)
def test_assign_phone_to_the_employee_who_already_has_this_phone(self): # TODO The method should not make any changes but NOT raise a PhoneError if a phone # is assigned to the same user it is currenly assigned to. testEmployee = Employee(1, 'Danzig') testPhone = Phone(1, 'Metalocalypse', 'Dethphone') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.assign(testPhone.id, testEmployee)
def test_assign_phone_to_employee(self): test_phone1 = Phone(1, "Samsung", "Galaxy S2") test_employee1 = Employee(1, "Kitty Cat") 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) self.assertEqual(test_phone1.employee_id, test_employee1.id)
def test_un_assign_phone(self): testEmployee1 = Employee(1, 'Mark') testPhone1 = Phone(21, 'Samsung', 'Galaxy S3') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.assign(21, testEmployee1) testAssignmentMgr.un_assign(21) self.assertEquals(None, testPhone1.employee_id)
def test_assign_phone_to_the_employee_who_already_has_this_phone(self): test_phone1 = Phone(1, "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) self.assertIsNone(test_assignments_mgr.assign(test_phone1, test_employee1))
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 testPhone1 = Phone(1, 'Apple', 'iPhone 6') testEmployee1 = Employee(1, "Jim Carey") testPhoneAssigmentsMgr = PhoneAssignments() testPhoneAssigmentsMgr.assign(testPhone1, testEmployee1) self.assertTrue(testPhone1.employee_id == testEmployee1.id)
def test_assign_phone_to_the_employee_who_already_has_this_phone(self): # TODO The method should not make any changes but NOT raise a PhoneError if a phone # is assigned to the same user it is currently assigned to. testEmployee1 = Employee(1, "Jim Carey") testPhone1 = Phone(1, 'Apple', 'iPhone 6') testPhoneAssigmentsMgr = PhoneAssignments() testPhoneAssigmentsMgr.assign(testPhone1, testEmployee1) self.assertTrue(testPhone1.employee_id == testEmployee1.id))
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_assign_phone_to_the_employee_who_already_has_this_phone(self): # TODO The method should not make any changes but NOT raise a PhoneError if a phone # is assigned to the same user it is currenly assigned to. testEmployee1 = Employee(1, 'Taylor Swift') testPhone1 = Phone(1, 'Apple', 'iPhone 6') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_employee(testEmployee1) testAssignmentMgr.add_phone(testPhone1) testAssignmentMgr.assign(testPhone1.id, testEmployee1) testAssignmentMgr.assign(testPhone1.id, testEmployee1) self.assertEquals(testEmployee1.id, testPhone1.employee_id)
def test_un_assign_phone(self): test_phone1 = Phone(1, "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) test_assignments_mgr.un_assign(test_phone1.id) self.assertIsNone(test_assignments_mgr.phones[0].employee_id)
def test_assign_phone_to_employee(self): test_phone = Phone(1, 'Apple', 'iPhone 420') test_employee = Employee(1, 'Snoop Dogg') test_assignment_manager = PhoneAssignments() test_assignment_manager.add_phone(test_phone) test_assignment_manager.add_employee(test_employee) test_assignment_manager.assign(1, test_employee) self.assertEqual(test_employee.id, test_phone.employee_id)
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 testEmployee = Employee(1, 'Qaalib') testPhone = Phone(1, 'Apple', 'IPhone 10') testManager = PhoneAssignments() testManager.add_phone(testPhone) testManager.add_employee(testEmployee) testManager.assign(testPhone.id, testEmployee) testManager.un_assign(testPhone.id) self.assertIsNone(testPhone.employee_id)
def test_un_assign_phone(self): # TODO write this test and remove the self.fail() statement # Assign a phone, un-assign the phone, verify the employee_id is None testPhone1 = Phone(1, 'Apple', 'iPhone 6') testEmployee1 = Employee(1, "Jim Carey") testPhoneAssigmentsMgr = PhoneAssignments() testPhoneAssigmentsMgr.assign(testPhone1, testEmployee1) testPhoneAssigmentsMgr.un_assign(testPhone1) self.assertTrue(testPhone1.employee_id == None)
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 testEmployee1 = Employee(1, 'Taylor Swift') testPhone1 = Phone(1, 'Apple', 'iPhone 6') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_employee(testEmployee1) testAssignmentMgr.add_phone(testPhone1) testAssignmentMgr.assign(testPhone1.id, testEmployee1) testAssignmentMgr.unassign(testPhone1.id, testEmployee1) self.assertFalse(testEmployee1.id, testPhone1.employee_id)
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 testEmployee1 = Employee(1, 'Taylor Swift') testPhone1 = Phone(1, 'Apple', 'iPhone 6') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_employee(testEmployee1) testAssignmentMgr.add_phone(testPhone1) testAssignmentMgr.assign(testPhone1.id, testEmployee1) self.assertEquals(testEmployee1.id, testPhone1.employee_id)
def test_assign_phone_to_employee(self): testEmployee1 = Employee(1, 'Mark') testPhone1 = Phone(43, 'Apple', 'iPhone 2') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_employee(testEmployee1) testAssignmentMgr.add_phone(testPhone1) testAssignmentMgr.assign(43, testEmployee1) self.assertTrue(testPhone1.employee_id == 1)
def test_assign_phone_to_the_employee_who_already_has_this_phone(self): # TODO The method should not make any changes but NOT raise a PhoneError if a phone # is assigned to the same user it is currenly assigned to. employee = Employee(1, 'Jack') phone = Phone(1, 'Apple', 'iPhone 6') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_employee(employee) testAssignmentMgr.add_phone(phone) testAssignmentMgr.assign(phone.id, employee) self.assertEqual(phone, testAssignmentMgr.assign(phone.id, employee))
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 testPhone1 = Phone(1, 'Apple', 'iPhone 6') #create a phone object testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_phone(testPhone1) #add phone employee1 = Employee(1, 'Zion') #create and add an employee testAssignmentMgr.add_employee(employee1) testAssignmentMgr.assign(testPhone1.employee_id,employee1) #assign phone ID 1 to employee1 testAssignmentMgr.un_assign(testPhone1.id) #unassign phone ID 1 self.assertIsNone(testAssignmentMgr.un_assign(testPhone1.id)) #assert that emp_id is None for phone 1
def test_assign_phone_to_employee(self): testEmployee = Employee(1, 'Test Name 1') testPhone = Phone(1, 'Test Brand', 'Test Model') testAssignmentMgr = PhoneAssignments() testAssignmentMgr.add_employee(testEmployee) testAssignmentMgr.add_phone(testPhone) testAssignmentMgr.assign(1, testEmployee) self.assertTrue(testPhone.employee_id == testEmployee.id)