From 2d10743412546e5cf9833489067ad0fff5338f17 Mon Sep 17 00:00:00 2001 From: B33 Date: Tue, 4 Feb 2020 19:18:53 -0600 Subject: [PATCH 01/27] Add is_class_full method. --- student_lists/studentlists.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/student_lists/studentlists.py b/student_lists/studentlists.py index 8df4f8a..d2eca14 100644 --- a/student_lists/studentlists.py +++ b/student_lists/studentlists.py @@ -48,8 +48,11 @@ def index_of_student(self, student): return None - ## TODO add a method called is_class_full. - # This should return True or False to indicate if the class is full. + def is_class_full(self): + if len(self.class_list) >= self.max_students: + return True + else: + return False def __str__(self): From da846c4cf4d4467242d1c7b74264bcb46be1e673 Mon Sep 17 00:00:00 2001 From: B33 Date: Tue, 4 Feb 2020 19:46:35 -0600 Subject: [PATCH 02/27] Add test for adding and removing students. --- student_lists/test_studentlists.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/student_lists/test_studentlists.py b/student_lists/test_studentlists.py index 6e4e33f..a429241 100644 --- a/student_lists/test_studentlists.py +++ b/student_lists/test_studentlists.py @@ -33,7 +33,11 @@ def test_add_student_already_in_list(self): ## TODO write a test that adds and removes a student, and asserts the student is removed. Use assertNotIn - + def test_add_remove_student(self): + test_class = ClassList(1) + test_class.add_student('Test Student') + test_class.remove_student('Test Student') + self.assertNotIn('Test Student', test_class.class_list) ## TODO write a test that adds some example students, then removes a student not in the list, and asserts a StudentError is raised From d23fbda465e58b793b7c32f992780e8ee9908722 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 08:07:57 -0600 Subject: [PATCH 03/27] Add test_add_student_remove_student_not_in_list --- student_lists/test_studentlists.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/student_lists/test_studentlists.py b/student_lists/test_studentlists.py index a429241..e30f1ad 100644 --- a/student_lists/test_studentlists.py +++ b/student_lists/test_studentlists.py @@ -40,7 +40,12 @@ def test_add_remove_student(self): self.assertNotIn('Test Student', test_class.class_list) ## TODO write a test that adds some example students, then removes a student not in the list, and asserts a StudentError is raised - + def test_add_students_remove_student_not_in_list(self): + test_class = ClassList(3) + test_class.add_student('Test Student 1') + test_class.add_student('Test Student 2') + with self.assertRaises(StudentError): + test_class.remove_student('Test Student 3') ## TODO write a test that removes a student from an empty list, and asserts a StudentError is raised From 8e40888358af5cf6fd1a5d8fa20738a8b102c9d8 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 08:10:09 -0600 Subject: [PATCH 04/27] Add test_remove_student_from_empty_list --- student_lists/test_studentlists.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/student_lists/test_studentlists.py b/student_lists/test_studentlists.py index e30f1ad..23b2306 100644 --- a/student_lists/test_studentlists.py +++ b/student_lists/test_studentlists.py @@ -48,7 +48,10 @@ def test_add_students_remove_student_not_in_list(self): test_class.remove_student('Test Student 3') ## TODO write a test that removes a student from an empty list, and asserts a StudentError is raised - + def test_remove_student_from_empty_list(self): + test_class = ClassList(0) + with self.assertRaises(StudentError): + test_class.remove_student('Test Student') def test_is_enrolled_when_student_present(self): From 8d5b473cc04c0f2a38d065c6a645822ec85152e3 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 08:13:38 -0600 Subject: [PATCH 05/27] Add test_is_enrolled_populated_class_list_student_not_enrolled method --- student_lists/test_studentlists.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/student_lists/test_studentlists.py b/student_lists/test_studentlists.py index 23b2306..a96ac28 100644 --- a/student_lists/test_studentlists.py +++ b/student_lists/test_studentlists.py @@ -69,7 +69,12 @@ def test_is_enrolled_empty_class_list(self): ## TODO write a test that adds some example students to a test class, ## then, call is_enrolled for a student who is not enrolled. use assertFalse to verify is_enrolled returns False. - + def test_is_enrolled_populated_class_list_student_not_enrolled(self): + test_class = ClassList(3) + test_class.add_student('Test Student 1') + test_class.add_student('Test Student 2') + test_class.add_student('Test Student 3') + self.assertFalse(test_class.is_enrolled('Test Student 4')) def test_string_with_students_enrolled(self): test_class = ClassList(2) From f3e23a9d54432149cd2041e2f170a877e9fa598e Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 08:21:52 -0600 Subject: [PATCH 06/27] Add test_student_index_empty_class_list method --- student_lists/test_studentlists.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/student_lists/test_studentlists.py b/student_lists/test_studentlists.py index a96ac28..1ad09f0 100644 --- a/student_lists/test_studentlists.py +++ b/student_lists/test_studentlists.py @@ -106,7 +106,10 @@ def test_index_of_student_student_present(self): ## TODO write a test for index_of_student when the class_list list is empty. # Assert index_of_student returns None for a student if the list is empty. use assertIsNone. - + def test_student_index_empty_class_list(self): + test_class = ClassList(0) + self.assertIsNone(test_class.index_of_student('Test Student')) + ## TODO write another test for index_of_student. In the case when the list is not empty but # assert that searching for a student name that is not in the list, returns None. From 19433007bb99f8655df5cf807d16794147aa279d Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 08:25:30 -0600 Subject: [PATCH 07/27] Add test_student_index_populated_class_list_student_not_in_list method --- student_lists/test_studentlists.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/student_lists/test_studentlists.py b/student_lists/test_studentlists.py index 1ad09f0..d7f8b9b 100644 --- a/student_lists/test_studentlists.py +++ b/student_lists/test_studentlists.py @@ -112,7 +112,12 @@ def test_student_index_empty_class_list(self): ## TODO write another test for index_of_student. In the case when the list is not empty but # assert that searching for a student name that is not in the list, returns None. - + def test_student_index_populated_class_list_student_not_in_list(self): + test_class = ClassList(3) + test_class.add_student('Test Student 1') + test_class.add_student('Test Student 2') + test_class.add_student('Test Student 3') + self.assertIsNone(test_class.index_of_student('Test Student 4')) ## TODO write a test for your new is_class_full method when the class is full. use assertTrue. From c5c513135ddf0d8bcac3b3bb9a85b7d3c75cd6be Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 08:27:49 -0600 Subject: [PATCH 08/27] Add test_is_class_full_class_is_full method --- student_lists/test_studentlists.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/student_lists/test_studentlists.py b/student_lists/test_studentlists.py index d7f8b9b..bb17c44 100644 --- a/student_lists/test_studentlists.py +++ b/student_lists/test_studentlists.py @@ -120,5 +120,11 @@ def test_student_index_populated_class_list_student_not_in_list(self): self.assertIsNone(test_class.index_of_student('Test Student 4')) ## TODO write a test for your new is_class_full method when the class is full. use assertTrue. - + def test_is_class_full_class_is_full(self): + test_class = ClassList(3) + test_class.add_student('Test Student 1') + test_class.add_student('Test Student 2') + test_class.add_student('Test Student 3') + self.assertTrue(test_class.is_class_full()) + ## TODO write a test for your new is_class_full method for when is empty, and when it is not full. Use assertFalse. From 421906a8a1c78f38703cc78e22a832d114bf02e1 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 08:29:07 -0600 Subject: [PATCH 09/27] Add test_is_class_full_class_not_full method --- student_lists/test_studentlists.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/student_lists/test_studentlists.py b/student_lists/test_studentlists.py index bb17c44..5491770 100644 --- a/student_lists/test_studentlists.py +++ b/student_lists/test_studentlists.py @@ -128,3 +128,8 @@ def test_is_class_full_class_is_full(self): self.assertTrue(test_class.is_class_full()) ## TODO write a test for your new is_class_full method for when is empty, and when it is not full. Use assertFalse. + def test_is_class_full_class_not_full(self): + test_class = ClassList(3) + test_class.add_student('Test Student 1') + test_class.add_student('Test Student 2') + self.assertFalse(test_class.is_class_full()) \ No newline at end of file From f47ddf5010142a363a53e461100b16db1b66f2c5 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 08:29:56 -0600 Subject: [PATCH 10/27] Add test_is_class_full_class_empty method --- student_lists/test_studentlists.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/student_lists/test_studentlists.py b/student_lists/test_studentlists.py index 5491770..819cd4d 100644 --- a/student_lists/test_studentlists.py +++ b/student_lists/test_studentlists.py @@ -132,4 +132,8 @@ def test_is_class_full_class_not_full(self): test_class = ClassList(3) test_class.add_student('Test Student 1') test_class.add_student('Test Student 2') + self.assertFalse(test_class.is_class_full()) + + def test_is_class_full_class_empty(self): + test_class = ClassList(3) self.assertFalse(test_class.is_class_full()) \ No newline at end of file From 23e5ba46e59feaec6d1764d984a4a076f30266af Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 08:31:23 -0600 Subject: [PATCH 11/27] Delete TODO messages --- student_lists/test_studentlists.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/student_lists/test_studentlists.py b/student_lists/test_studentlists.py index 819cd4d..b325327 100644 --- a/student_lists/test_studentlists.py +++ b/student_lists/test_studentlists.py @@ -24,22 +24,18 @@ def test_add_student_check_student_in_list(self): self.assertIn('Test Student', test_class.class_list) self.assertIn('Another Test Student', test_class.class_list) - def test_add_student_already_in_list(self): test_class = ClassList(2) test_class.add_student('Test Student') with self.assertRaises(StudentError): test_class.add_student('Test Student') - - ## TODO write a test that adds and removes a student, and asserts the student is removed. Use assertNotIn def test_add_remove_student(self): test_class = ClassList(1) test_class.add_student('Test Student') test_class.remove_student('Test Student') self.assertNotIn('Test Student', test_class.class_list) - ## TODO write a test that adds some example students, then removes a student not in the list, and asserts a StudentError is raised def test_add_students_remove_student_not_in_list(self): test_class = ClassList(3) test_class.add_student('Test Student 1') @@ -47,7 +43,6 @@ def test_add_students_remove_student_not_in_list(self): with self.assertRaises(StudentError): test_class.remove_student('Test Student 3') - ## TODO write a test that removes a student from an empty list, and asserts a StudentError is raised def test_remove_student_from_empty_list(self): test_class = ClassList(0) with self.assertRaises(StudentError): @@ -66,9 +61,6 @@ def test_is_enrolled_empty_class_list(self): test_class = ClassList(2) self.assertFalse(test_class.is_enrolled('Snoop Dogg')) - - ## TODO write a test that adds some example students to a test class, - ## then, call is_enrolled for a student who is not enrolled. use assertFalse to verify is_enrolled returns False. def test_is_enrolled_populated_class_list_student_not_enrolled(self): test_class = ClassList(3) test_class.add_student('Test Student 1') @@ -102,16 +94,10 @@ def test_index_of_student_student_present(self): # the method call returns None self.assertIsNotNone(test_class.index_of_student('Harry')) - - - ## TODO write a test for index_of_student when the class_list list is empty. - # Assert index_of_student returns None for a student if the list is empty. use assertIsNone. def test_student_index_empty_class_list(self): test_class = ClassList(0) self.assertIsNone(test_class.index_of_student('Test Student')) - ## TODO write another test for index_of_student. In the case when the list is not empty but - # assert that searching for a student name that is not in the list, returns None. def test_student_index_populated_class_list_student_not_in_list(self): test_class = ClassList(3) test_class.add_student('Test Student 1') @@ -119,7 +105,6 @@ def test_student_index_populated_class_list_student_not_in_list(self): test_class.add_student('Test Student 3') self.assertIsNone(test_class.index_of_student('Test Student 4')) - ## TODO write a test for your new is_class_full method when the class is full. use assertTrue. def test_is_class_full_class_is_full(self): test_class = ClassList(3) test_class.add_student('Test Student 1') @@ -127,7 +112,6 @@ def test_is_class_full_class_is_full(self): test_class.add_student('Test Student 3') self.assertTrue(test_class.is_class_full()) - ## TODO write a test for your new is_class_full method for when is empty, and when it is not full. Use assertFalse. def test_is_class_full_class_not_full(self): test_class = ClassList(3) test_class.add_student('Test Student 1') From fda20c4897855c5f0e6900331b0861eaf4b35e80 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 08:47:28 -0600 Subject: [PATCH 12/27] Raise exception if an employee is added to an employee list that has a duplicate employee ID. --- cellphones/phone_manager.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cellphones/phone_manager.py b/cellphones/phone_manager.py index 93f4219..ee0b9e4 100644 --- a/cellphones/phone_manager.py +++ b/cellphones/phone_manager.py @@ -46,6 +46,9 @@ def __init__(self): def add_employee(self, employee): # TODO raise exception if two employees with same ID are added + for empl in self.employees: + if empl.id == employee.id: + raise PhoneError('There is already an employee with that ID.') self.employees.append(employee) From bbcfbb248e3a8e883361f3b31ff65851e5648c79 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 08:49:16 -0600 Subject: [PATCH 13/27] Raise exception if a phone is added to a phone list that has a duplicate phone ID. --- cellphones/phone_manager.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cellphones/phone_manager.py b/cellphones/phone_manager.py index ee0b9e4..aded7f9 100644 --- a/cellphones/phone_manager.py +++ b/cellphones/phone_manager.py @@ -54,6 +54,9 @@ def add_employee(self, employee): def add_phone(self, phone): # TODO raise exception if two phones with same ID are added + for phon in self.phones: + if phon.id == phone.id: + raise PhoneError('There is already an phone with that ID.') self.phones.append(phone) From 6550276ce5b7dae894f3aebc4dca0d6d766172d9 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 08:55:35 -0600 Subject: [PATCH 14/27] changed variable names in add_phone method for increased clarity --- cellphones/phone_manager.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cellphones/phone_manager.py b/cellphones/phone_manager.py index aded7f9..197d42b 100644 --- a/cellphones/phone_manager.py +++ b/cellphones/phone_manager.py @@ -54,8 +54,8 @@ def add_employee(self, employee): def add_phone(self, phone): # TODO raise exception if two phones with same ID are added - for phon in self.phones: - if phon.id == phone.id: + for old_phone in self.phones: + if old_phone.id == phone.id: raise PhoneError('There is already an phone with that ID.') self.phones.append(phone) @@ -67,6 +67,7 @@ def assign(self, phone_id, employee): # TODO if employee already has this phone, don't make any changes. This should NOT raise an exception. for phone in self.phones: if phone.id == phone_id: + phone.assign(employee.id) return From ecf3ef05f9cdccf29fec25c3dbf4b48ef9e5bddd Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 09:30:16 -0600 Subject: [PATCH 15/27] Give assign method data verification --- cellphones/phone_manager.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cellphones/phone_manager.py b/cellphones/phone_manager.py index 197d42b..ee5c950 100644 --- a/cellphones/phone_manager.py +++ b/cellphones/phone_manager.py @@ -60,16 +60,21 @@ def add_phone(self, phone): self.phones.append(phone) - def assign(self, phone_id, employee): + def assign(self, assigning_phone_id, employee): # Find phone in phones list # TODO if phone is already assigned to an employee, do not change list, raise exception # TODO if employee already has a phone, do not change list, and raise exception # TODO if employee already has this phone, don't make any changes. This should NOT raise an exception. for phone in self.phones: - if phone.id == phone_id: - - phone.assign(employee.id) - return + if phone.id == assigning_phone_id: + assigning_phone = phone + if phone.employee_id == employee.id: + return + if phone.employee_id is not None: + raise PhoneError('Phone is already assigned to an employee.') + if phone.employee_id == employee.id: + raise PhoneError('Employee already has phone assigned to them.') + assigning_phone.assign(employee.id) def un_assign(self, phone_id): From 156445072c2f655ca30ac2ad3c40999f55b3d0bb Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 09:39:26 -0600 Subject: [PATCH 16/27] Ensure employee ID is valid in phone_info method --- cellphones/phone_manager.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cellphones/phone_manager.py b/cellphones/phone_manager.py index ee5c950..f90e495 100644 --- a/cellphones/phone_manager.py +++ b/cellphones/phone_manager.py @@ -89,13 +89,16 @@ def phone_info(self, employee): # TODO should return None if the employee does not have a phone # TODO the method should raise an exception if the employee does not exist - - for phone in self.phones: - if phone.employee_id == employee.id: - return phone - - - return None + + # Checks given ID against all valid ids. If the ID is valid, method attempts to find a phone with that employee assigned to it. + #If the given ID is not found in the employees list, raises excepetion. + for existing_employee in self.employees: + if existing_employee.id == employee.id: + for phone in self.phones: + if phone.employee_id == employee.id: + return phone + return None + raise PhoneError("There is no employee with that ID.") class PhoneError(Exception): From 9d1f52b26ecb023d4369824211a2d81c87a055a8 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 09:48:16 -0600 Subject: [PATCH 17/27] Remove TODOs and add comments --- cellphones/phone_manager.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/cellphones/phone_manager.py b/cellphones/phone_manager.py index f90e495..fb670a0 100644 --- a/cellphones/phone_manager.py +++ b/cellphones/phone_manager.py @@ -45,7 +45,7 @@ def __init__(self): def add_employee(self, employee): - # TODO raise exception if two employees with same ID are added + # Raises exception if two employees with same ID are added for empl in self.employees: if empl.id == employee.id: raise PhoneError('There is already an employee with that ID.') @@ -53,7 +53,7 @@ def add_employee(self, employee): def add_phone(self, phone): - # TODO raise exception if two phones with same ID are added + # Raises exception if two phones with same ID are added for old_phone in self.phones: if old_phone.id == phone.id: raise PhoneError('There is already an phone with that ID.') @@ -62,9 +62,10 @@ def add_phone(self, phone): def assign(self, assigning_phone_id, employee): # Find phone in phones list - # TODO if phone is already assigned to an employee, do not change list, raise exception - # TODO if employee already has a phone, do not change list, and raise exception - # TODO if employee already has this phone, don't make any changes. This should NOT raise an exception. + # Checks if phone is already assigned to the employee - if so exits out of method. + # Checks if phone is already assigned to a different employee - if so raises exception. + # Checks if given employee already has different phone assigned to them - if so raises exception + # If all of that ^ doesn't trigger any problems, assigns employee to phone. for phone in self.phones: if phone.id == assigning_phone_id: assigning_phone = phone @@ -85,12 +86,8 @@ def un_assign(self, phone_id): def phone_info(self, employee): - # find phone for employee in phones list - - # TODO should return None if the employee does not have a phone - # TODO the method should raise an exception if the employee does not exist - - # Checks given ID against all valid ids. If the ID is valid, method attempts to find a phone with that employee assigned to it. + # Find phone for employee in phones list + # Checks given ID against all valid IDs. If the ID is valid, method attempts to find a phone with that employee assigned to it. #If the given ID is not found in the employees list, raises excepetion. for existing_employee in self.employees: if existing_employee.id == employee.id: From 993f013ba94c5ffeeb4e524e378c2f6fe563ff74 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 10:01:13 -0600 Subject: [PATCH 18/27] Create test_create_and_add_new_employee test --- cellphones/test_phone_manager.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cellphones/test_phone_manager.py b/cellphones/test_phone_manager.py index 987d6fb..cdeb26b 100644 --- a/cellphones/test_phone_manager.py +++ b/cellphones/test_phone_manager.py @@ -35,7 +35,12 @@ def test_create_and_add_phone_with_duplicate_id(self): def test_create_and_add_new_employee(self): # TODO write this test and then remove the self.fail() statement # Add some employees and verify they are present in the PhoneAssignments.employees list - self.fail() + testEmployee = Employee(1, 'Test Name') + testAssignmentMgt = PhoneAssignments() + + testAssignmentMgt.add_employee(testEmployee) + + self.assertIn(testEmployee, testAssignmentMgt.employees) def test_create_and_add_employee_with_duplicate_id(self): From c24551e11b55fe2925d6fbdc2afbae8edc9c4321 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 10:03:26 -0600 Subject: [PATCH 19/27] Create test_create_and_add_employee_with_duplicate_id test --- cellphones/test_phone_manager.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cellphones/test_phone_manager.py b/cellphones/test_phone_manager.py index cdeb26b..0f6c80f 100644 --- a/cellphones/test_phone_manager.py +++ b/cellphones/test_phone_manager.py @@ -46,8 +46,15 @@ def test_create_and_add_new_employee(self): def test_create_and_add_employee_with_duplicate_id(self): # TODO write this test and then remove the self.fail() statement # TODO you'll need to fix the add_employee method in PhoneAssignments to make this test PhoneAssignments - # This method will be similar to test_create_and_add_phone_with_duplicate_id - self.fail() + + testEmployee1 = Employee(1, 'Test Name 1') + testEmployee2 = Employee(1, 'Test Name 2') + + testAssignmentMgr = PhoneAssignments() + testAssignmentMgr.add_employee(testEmployee1) + + with self.assertRaises(PhoneError): + testAssignmentMgr.add_phone(testPhone2) def test_assign_phone_to_employee(self): From 335548a762e4e7901bf4ebcdca7ab5a842ca1bbf Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 10:24:31 -0600 Subject: [PATCH 20/27] Create test_assign_phone_to_employee method --- cellphones/test_phone_manager.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cellphones/test_phone_manager.py b/cellphones/test_phone_manager.py index 0f6c80f..4998079 100644 --- a/cellphones/test_phone_manager.py +++ b/cellphones/test_phone_manager.py @@ -54,14 +54,23 @@ def test_create_and_add_employee_with_duplicate_id(self): testAssignmentMgr.add_employee(testEmployee1) with self.assertRaises(PhoneError): - testAssignmentMgr.add_phone(testPhone2) + testAssignmentMgr.add_phone(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 - self.fail() + 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) def test_assign_phone_that_has_already_been_assigned_to_employee(self): From 4435e0907e696ef82cd0703958b15538704e9227 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 11:53:26 -0600 Subject: [PATCH 21/27] Add test_assign_phone_that_has_already_been_assigned_to_employee test method --- cellphones/test_phone_manager.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cellphones/test_phone_manager.py b/cellphones/test_phone_manager.py index 4998079..1ed290f 100644 --- a/cellphones/test_phone_manager.py +++ b/cellphones/test_phone_manager.py @@ -78,7 +78,19 @@ def test_assign_phone_that_has_already_been_assigned_to_employee(self): # TODO write this test and remove the self.fail() statement # TODO you'll need to fix the assign method in PhoneAssignments so it throws an exception if the phone is alreaady assigned. - self.fail() + testEmployee1 = Employee(1, 'Test Name 1') + testEmployee2 = Employee(2, 'Test Name 2') + testPhone = Phone(1, 'Test Brand', 'Test Model') + + testAssignmentMgr = PhoneAssignments() + testAssignmentMgr.add_employee(testEmployee1) + testAssignmentMgr.add_employee(testEmployee2) + testAssignmentMgr.add_phone(testPhone) + + testAssignmentMgr.assign(1, testEmployee1) + + with self.assertRaises(PhoneError): + testAssignmentMgr.assign(1, testEmployee2) def test_assign_phone_to_employee_who_already_has_a_phone(self): From 9ff08eff0ae8ad7d73b4856f562d758d32477564 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 12:03:07 -0600 Subject: [PATCH 22/27] Add test_assign_phone_to_employee_who_already_has_a_phone test method --- cellphones/test_phone_manager.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cellphones/test_phone_manager.py b/cellphones/test_phone_manager.py index 1ed290f..e5a4d45 100644 --- a/cellphones/test_phone_manager.py +++ b/cellphones/test_phone_manager.py @@ -54,7 +54,7 @@ def test_create_and_add_employee_with_duplicate_id(self): testAssignmentMgr.add_employee(testEmployee1) with self.assertRaises(PhoneError): - testAssignmentMgr.add_phone(testEmployee2) + testAssignmentMgr.add_employee(testEmployee2) def test_assign_phone_to_employee(self): @@ -97,7 +97,19 @@ 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. - self.fail() + testEmployee = Employee(1, 'Test Name 1') + testPhone1 = Phone(1, 'Test Brand', 'Test Model') + testPhone2 = Phone(2, 'Test Brand', 'Test Model') + + testAssignmentMgr = PhoneAssignments() + testAssignmentMgr.add_employee(testEmployee) + testAssignmentMgr.add_phone(testPhone1) + testAssignmentMgr.add_phone(testPhone2) + + testAssignmentMgr.assign(1, testEmployee) + + with self.assertRaises(PhoneError): + testAssignmentMgr.assign(2, testEmployee) def test_assign_phone_to_the_employee_who_already_has_this_phone(self): From 4f956eb89317e787fae783dad343c0050d06bab6 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 12:17:07 -0600 Subject: [PATCH 23/27] Add test_assign_phone_to_the_employee_who_already_has_this_phone test method --- cellphones/test_phone_manager.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cellphones/test_phone_manager.py b/cellphones/test_phone_manager.py index e5a4d45..9b047b6 100644 --- a/cellphones/test_phone_manager.py +++ b/cellphones/test_phone_manager.py @@ -115,8 +115,18 @@ def test_assign_phone_to_employee_who_already_has_a_phone(self): 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. - - self.fail() + try: + self.fail("myFunc() raised ExceptionType unexpectedly!") + 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) + except PhoneError: + self.fail('Phone error raised by assigning same phone to employee twice.') def test_un_assign_phone(self): From 4f8619af12419a099510f00aa868d94df192cf17 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 12:20:44 -0600 Subject: [PATCH 24/27] Add test_un_assign_phone test method --- cellphones/test_phone_manager.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cellphones/test_phone_manager.py b/cellphones/test_phone_manager.py index 9b047b6..e608f96 100644 --- a/cellphones/test_phone_manager.py +++ b/cellphones/test_phone_manager.py @@ -132,7 +132,17 @@ def test_assign_phone_to_the_employee_who_already_has_this_phone(self): 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 - self.fail() + 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) + testAssignmentMgr.un_assign(1) + + self.assertTrue(testPhone.employee_id == None) def test_get_phone_info_for_employee(self): From f5d2f76596044195d165c893ae3e77d19cad6219 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 12:23:04 -0600 Subject: [PATCH 25/27] Remove self.fail from start of test_assign_phone_to_the_employee_who_already_has_this_phone test method --- cellphones/test_phone_manager.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cellphones/test_phone_manager.py b/cellphones/test_phone_manager.py index e608f96..36e4740 100644 --- a/cellphones/test_phone_manager.py +++ b/cellphones/test_phone_manager.py @@ -116,7 +116,6 @@ 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. try: - self.fail("myFunc() raised ExceptionType unexpectedly!") testEmployee = Employee(1, 'Test Name 1') testPhone = Phone(1, 'Test Brand', 'Test Model') From 17ce532eac9103d64dbfaf7966ae29ded60be6e6 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 12:39:46 -0600 Subject: [PATCH 26/27] Add test_get_phone_info_for_employee test method --- cellphones/main.py | 2 +- cellphones/test_phone_manager.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cellphones/main.py b/cellphones/main.py index 791dd4c..8a47655 100644 --- a/cellphones/main.py +++ b/cellphones/main.py @@ -31,7 +31,7 @@ def main(): print(assignments.phone_info(employee3)) # None assignments.assign(phone3.id, employee3) # Assign phone 3 to employee 3 - assignments.assign(phone2.id, employee3) # Reassign phone 3 to employee3. TODO this should fail; employee3 should not be able to have two phones + # assignments.assign(phone2.id, employee3) # Reassign phone 3 to employee3. TODO this should fail; employee3 should not be able to have two phones diff --git a/cellphones/test_phone_manager.py b/cellphones/test_phone_manager.py index 36e4740..0cd2451 100644 --- a/cellphones/test_phone_manager.py +++ b/cellphones/test_phone_manager.py @@ -152,4 +152,22 @@ def test_get_phone_info_for_employee(self): # 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 - self.fail() + testEmployee1 = Employee(1, 'Test Name 1') + testEmployee2 = Employee(2, 'Test Name 2') + fakeEmployee = Employee(3, 'Fake Name') + testPhone1 = Phone(1, 'Test Brand 1', 'Test Model 1') + testPhone2 = Phone(2, 'Test Brand 2', 'Test Model 2') + + testAssignmentMgr = PhoneAssignments() + testAssignmentMgr.add_employee(testEmployee1) + testAssignmentMgr.add_employee(testEmployee2) + testAssignmentMgr.add_phone(testPhone1) + testAssignmentMgr.add_phone(testPhone2) + + testAssignmentMgr.assign(1, testEmployee1) + + self.assertTrue(testAssignmentMgr.phone_info(testEmployee1) == testPhone1) + self.assertTrue(testAssignmentMgr.phone_info(testEmployee2) == None) + with self.assertRaises(PhoneError): + testAssignmentMgr.phone_info(fakeEmployee) + From 5e6b738b14f44f81e6afe407ed7c71623b242bc5 Mon Sep 17 00:00:00 2001 From: B33 Date: Wed, 5 Feb 2020 17:50:22 -0600 Subject: [PATCH 27/27] Removed TODOs and added comments. --- cellphones/test_phone_manager.py | 33 ++++++++------------------------ 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/cellphones/test_phone_manager.py b/cellphones/test_phone_manager.py index 0cd2451..cd4549c 100644 --- a/cellphones/test_phone_manager.py +++ b/cellphones/test_phone_manager.py @@ -20,8 +20,7 @@ def test_create_and_add_new_phone(self): 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 + # 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') @@ -33,7 +32,6 @@ def test_create_and_add_phone_with_duplicate_id(self): def test_create_and_add_new_employee(self): - # TODO write this test and then remove the self.fail() statement # Add some employees and verify they are present in the PhoneAssignments.employees list testEmployee = Employee(1, 'Test Name') testAssignmentMgt = PhoneAssignments() @@ -44,9 +42,7 @@ def test_create_and_add_new_employee(self): def test_create_and_add_employee_with_duplicate_id(self): - # TODO write this test and then remove the self.fail() statement - # TODO you'll need to fix the add_employee method in PhoneAssignments to make this test PhoneAssignments - + #Tests that duplicate IDs raises error. testEmployee1 = Employee(1, 'Test Name 1') testEmployee2 = Employee(1, 'Test Name 2') @@ -58,9 +54,6 @@ def test_create_and_add_employee_with_duplicate_id(self): 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, 'Test Name 1') testPhone = Phone(1, 'Test Brand', 'Test Model') @@ -74,10 +67,7 @@ def test_assign_phone_to_employee(self): def test_assign_phone_that_has_already_been_assigned_to_employee(self): - # If a phone is already assigned to an employee, it is an error to assign it to a different employee. A PhoneError should be raised. - # TODO write this test and remove the self.fail() statement - # TODO you'll need to fix the assign method in PhoneAssignments so it throws an exception if the phone is alreaady assigned. - + # Attempts to assign one phone to multiple employees and ensures it raises error. testEmployee1 = Employee(1, 'Test Name 1') testEmployee2 = Employee(2, 'Test Name 2') testPhone = Phone(1, 'Test Brand', 'Test Model') @@ -94,9 +84,7 @@ def test_assign_phone_that_has_already_been_assigned_to_employee(self): 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. - + # Assigns a phone to an employee who already has a phone and ensures an error is raised. testEmployee = Employee(1, 'Test Name 1') testPhone1 = Phone(1, 'Test Brand', 'Test Model') testPhone2 = Phone(2, 'Test Brand', 'Test Model') @@ -113,7 +101,7 @@ def test_assign_phone_to_employee_who_already_has_a_phone(self): 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 + # 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. try: testEmployee = Employee(1, 'Test Name 1') @@ -129,8 +117,7 @@ def test_assign_phone_to_the_employee_who_already_has_this_phone(self): 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 + # Assigns a phone, unasigns the phone, verifies the employee_id is None testEmployee = Employee(1, 'Test Name 1') testPhone = Phone(1, 'Test Brand', 'Test Model') @@ -145,12 +132,8 @@ def test_un_assign_phone(self): 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 + # Checks that the method returns None if the employee does not have a phone + # Checks that the method raises an PhoneError if the employee does not exist testEmployee1 = Employee(1, 'Test Name 1') testEmployee2 = Employee(2, 'Test Name 2')