Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
    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)
Esempio n. 4
0
    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
        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)
Esempio n. 6
0
    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))
Esempio n. 7
0
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
Esempio n. 8
0
    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)
Esempio n. 9
0
    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)
Esempio n. 10
0
    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)
Esempio n. 11
0
    def test_assign_phone_that_has_already_been_assigned_to_employee(self):
       
		testPhone1 = Phone(1, 'Apple', 'iPhone 6') #testphone1 assigned values
		testEmployee1 = Employee(1, 'John', 'Jacobs') #assigns employee1 data
		testEmployee2 = Employee(2, 'Jenny', 'Jenson') #assigns employee2 data but same ID

		assign(self, testPhone1, testEmployee1) # assigns phone to employee
		 with self.assertRaises(PhoneError): #raises error when phone is assigned to extra employee
Esempio n. 12
0
    def test_create_and_add_employee_with_duplicate_id(self):
        test_employee1 = Employee(1, 'Colin Jost')
        test_employee2 = Employee(1, 'Michael Che')

        test_assignment_manager = PhoneAssignments()
        test_assignment_manager.add_employee(test_employee1)

        with self.assertRaises(PhoneError):
            test_assignment_manager.add_employee(test_employee2)
Esempio n. 13
0
    def test_create_and_add_employee_with_duplicate_id(self):
        test_assignment_mgr = PhoneAssignments()

        test_employee1 = Employee(1, 'Kitty')
        test_employee2 = Employee(1, 'Puppy')

        test_assignment_mgr.add_employee(test_employee1)
        with self.assertRaises(PhoneError):
            test_assignment_mgr.add_employee(test_employee2)
Esempio n. 14
0
    def test_create_and_add_employee_with_duplicate_id(self):
        test_assignment_mgr = PhoneAssignments()

        emp_1 = Employee(1, "John Locke")
        emp_2 = Employee(1, "Jack Sheppard")

        test_assignment_mgr.add_employee(emp_1)
        with self.assertRaises(EmployeeError):
            test_assignment_mgr.add_employee(emp_2)
Esempio n. 15
0
    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
        testAssignmentMgr = PhoneAssignments()
        testAssignmentMgr.add_employee(Employee(1, 'TestEmployee1'))

        with self.assertRaises(PhoneError):
            testAssignmentMgr.add_phone(Employee(1, 'TestEmployee2'))
Esempio n. 16
0
 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
     testEmployee1 = Employee(1, 'Taylor Swift')
     testEmployee2 = Employee(2, 'Kanye West')
     testAssignmentMgr = PhoneAssignments()
     testAssignmentMgr.add_employee(testEmployee1)
     testAssignmentMgr.add_employee(testEmployee2)
     self.assertTrue(testEmployee1, testAssignmentMgr.employees)
     self.assertTrue(testEmployee2, testAssignmentMgr.employees)
 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
     employee_a = Employee(12345, 'Bill')
     employee_b = Employee(12345, 'Bob')
     test_assignment = PhoneAssignments()
     test_assignment.add_employee(employee_a)
     with self.assertRaises(PhoneError):
         test_assignment.add_employee(employee_b)
    def test_create_and_add_employee_with_duplicate_id(self):
        #Tests that duplicate IDs raises error.
        testEmployee1 = Employee(1, 'Test Name 1')
        testEmployee2 = Employee(1, 'Test Name 2')

        testAssignmentMgr = PhoneAssignments()
        testAssignmentMgr.add_employee(testEmployee1)

        with self.assertRaises(PhoneError):
            testAssignmentMgr.add_employee(testEmployee2)
Esempio n. 19
0
 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
     testAssignmentMgr = PhoneAssignments()
     employee1 = Employee(1, 'Zion') #create employee 1
     testAssignmentMgr.add_employee(employee1) #add employee 1
     employee2 = Employee(1, 'Acadia') #this employee has same ID as empl 1
     with self.assertRaises(PhoneError):#trying to add an employee w/ dupl Id should raise a Phone Error
         testAssignmentMgr.add_employee(employee2)
Esempio n. 20
0
    def test_create_and_add_employee_with_duplicate_id(self):

        testEmployee1 = Employee(1, 'Mark')
        testEmployee2 = Employee(1, 'Ingrid')

        testAssignmentMgr = PhoneAssignments()
        testAssignmentMgr.add_employee(testEmployee1)

        with self.assertRaises(PhoneError):
            testAssignmentMgr.add_employee(testEmployee2)
Esempio n. 21
0
    def test_create_and_add_new_employee(self):
		
		testEmployee1 = Employee(1, 'John', 'Jacobs') #assigns employee1 data
		testEmployee2 = Employee(2, 'Jenny', 'Jenson') #assigns employee2 data
		
		testAssignmentMgr = EmployeeAssignments() #assigns name
		testAssignmentMgr.add_employee(testEmployee1) #adds employee1
		testAssignmentMgr.add_employee(testEmployee2) #adds employee2
		
		self.assertIn(testEmployee1, EmployeeAssignments) #makes sure employee1 is in employee assignments	
		self.assertIn(testEmployee2, EmployeeAssignments) #makes sure employee 2 is in employee assignments
Esempio n. 22
0
    def test_create_and_add_employee_with_duplicate_id(self):
        # write this test and then remove the self.fail() statement
        # 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
        testAssignmentMgr = PhoneAssignments()
        test_employee_1 = Employee(1, 'Isaac Asimov')
        test_employee_2 = Employee(1, 'Arthur C. Clarke')

        testAssignmentMgr.add_employee(test_employee_1)
        with self.assertRaises(PhoneError):
            testAssignmentMgr.add_employee(test_employee_2)
Esempio n. 23
0
    def test_create_and_add_employee_with_duplicate_id(self):

        # Test raise PhoneError for adding the same employee ID
        testEmployee1 = Employee(1, 'Marissa')
        testEmployee2 = Employee(1, 'Christine')

        testAssignmentMgr = PhoneAssignments()
        testAssignmentMgr.add_employee(testEmployee1)

        with self.assertRaises(PhoneError):
            testAssignmentMgr.add_employee(testEmployee2)
    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
        test_employee1 = Employee(1, 'David Hasselhoff')
        test_employee2 = Employee(1, 'Gary Coleman')
        test_PhoneAssignments = PhoneAssignments()
        test_PhoneAssignments.add_employee(test_employee1)

        with self.assertRaises(PhoneError):
            test_PhoneAssignments.add_employee(test_employee2)
Esempio n. 25
0
    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)
Esempio n. 26
0
    def test_create_and_add_new_employee(self):
        # Add some employees and verify they are present in the PhoneAssignments.employees list
        testEmployee1 = Employee(1, "Mark Hamil")
        testEmployee2 = Employee(2, "Carrie Fisher")
        testEmployee3 = Employee(3, "Harrison Ford")
        testPhoneAssigmentsMgr = PhoneAssignments()
        testPhoneAssigmentsMgr.add_employee(testEmployee3)

        testEmployees = [ testEmployee1, testEmployee2 ]

        self.assertCountEqual(testEmployees, testPhoneAssigmentsMgr.employees)
Esempio n. 27
0
    def test_create_and_add_new_employee(self):
        test_assignment_mgr = PhoneAssignments()

        test_employee1 = Employee(1, 'Kitty')
        test_employee2 = Employee(2, 'Puppy')

        test_assignment_mgr.add_employee(test_employee1)
        test_assignment_mgr.add_employee(test_employee2)

        self.assertTrue(test_employee1 in test_assignment_mgr.employees)
        self.assertTrue(test_employee2 in test_assignment_mgr.employees)
Esempio n. 28
0
    def test_create_and_add_employee_with_duplicate_id(self):
        # This method will be similar to test_create_and_add_phone_with_duplicate_id

        testPhoneAssigmentsMgr = PhoneAssignments()
        testEmployee3 = Employee(1, "Harrison Ford")
        testEmployee1 = Employee(1, "Mark Hamil")

        with self.assertRaises(PhoneError):
            testPhoneAssigmentsMgr.add_employee(testEmployee1)
        with self.assertRaises(PhoneError):
            testPhoneAssigmentsMgr.add_employee(testEmployee3)
    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
        employee1 = Employee(1, 'Qaalib')
        employee2 = Employee(2, 'Snoop Dog')

        testAssignmentmgr = PhoneAssignments()
        testAssignmentmgr.add_employee(employee1)
        testAssignmentmgr.add_employee(employee2)
        self.assertIs(0, testAssignmentmgr.employees.index(employee1))
        self.assertIs(1, testAssignmentmgr.employees.index(employee2))
    def test_create_and_add_new_employee(self):
        # TODO write this test and then remove the self.fail() statement
        testEmployee1 = Employee(1, 'Kobe')
        testEmployee2 = Employee(2, 'Simpson')

        testAssignmentmgr = PhoneAssignments()
        testAssignmentmgr.add_employee(testEmployee1)
        testAssignmentmgr.add_employee(testEmployee2)

        self.assertIn(testEmployee1, testAssignmentmgr.employees)
        self.assertIn(testEmployee2, testAssignmentmgr.employees)