def test_line_obtain_subs() -> None:
    o = Organization()
    e1 = Employee(1, '', '', 1, 1)
    o.add_employee(e1)
    e2 = Employee(2, '', '', 1, 1)
    o.add_employee(e2, 1)
    e3 = Employee(3, '', '', 1, 1)
    o.add_employee(e3, 1)
    e4 = Employee(4, '', '', 1, 1)
    o.add_employee(e4, 3)
    e5 = Employee(5, '', '', 1, 1)
    o.add_employee(e5, 4)
    assert e2 in e1.get_direct_subordinates()
    assert e3 in e1.get_direct_subordinates()
    assert not e5 in e1.get_direct_subordinates()
    assert e5 in e1.get_all_subordinates()
    assert len(e2.get_all_subordinates()) == 0
    e2.obtain_subordinates([3, 4])
    assert not e3 in e1.get_direct_subordinates()
    assert e2 in e1.get_direct_subordinates()
    assert e3 in e2.get_direct_subordinates()
    assert e4 in e2.get_direct_subordinates()
    assert e5 in e1.get_direct_subordinates()
    assert e3 in e2.get_direct_subordinates()
    assert e4 in e2.get_direct_subordinates()
def test_obtain_employees() -> None:
    o = Organization()
    e1 = Leader(1, 'Holly', '', 1, 1, 'Department')
    o.add_employee(e1)
    e2 = Employee(2, 'Ivan', '', 1, 1)
    o.add_employee(e2, 1)
    e3 = Employee(3, 'Kevin', '', 1, 1)
    o.add_employee(e3, 2)
    e4 = Employee(4, 'Joe', 'Mama', 1, 100)
    o.add_employee(e4, 2)
    e5 = Employee(5, 'Linda', '', 1, 1)
    o.add_employee(e5, 4)
    assert e1.get_direct_subordinates() == [e2]
    assert e2.get_superior() == e1
    assert e2.get_direct_subordinates() == [e3, e4]
    assert e3.get_superior() == e2
    assert e4.get_superior() == e2
    assert e3.get_direct_subordinates() == []
    assert e4.get_direct_subordinates() == [e5]
    assert e5.get_superior() == e4
    e4.obtain_subordinates([2])
    assert o.get_head() == e1
    assert e1.get_direct_subordinates() == [e3, e4]
    assert e3.get_superior() == e1
    assert e4.get_superior() == e1
    assert e3.get_direct_subordinates() == []
    assert e4.get_direct_subordinates() == [e2, e5]
    assert e2.get_superior() == e4
    assert e5.get_superior() == e4
Example #3
0
def test_obtain_sub_head_being_obtained() -> None:
    e1 = Employee(1, "e1", "a", 1, 1)
    e2 = Employee(2, "e2", "a", 1, 2)
    e3 = Employee(3, "e3", "a", 1, 3)
    e4 = Employee(4, "e4", "a", 1, 4)
    e5 = Employee(5, "e5", "a", 1, 5)
    e6 = Employee(6, "e6", "a", 1, 6)
    e2.become_subordinate(e1)
    e3.become_subordinate(e1)
    e4.become_subordinate(e3)
    e5.become_subordinate(e3)
    e6.become_subordinate(e5)
    assert e5.obtain_subordinates([1, 3]) == e5
    assert e5.get_direct_subordinates() == [e1, e2, e3, e4, e6]
Example #4
0
def test_obtain_sub_already_sub_anotha_one() -> None: #dj khaled
    e1 = Employee(1, "e1", "a", 1, 50)
    e2 = Employee(2, "e2", "a", 1, 50)
    e3 = Employee(3, "e3", "a", 1, 50)
    e4 = Employee(4, "e4", "a", 1, 50)
    e5 = Employee(5, "e5", "a", 1, 50)
    e6 = Employee(6, "e6", "a", 1, 50)
    e7 = Employee(7, "e7", "a", 1, 50)
    e2.become_subordinate(e1)
    e3.become_subordinate(e2)
    e4.become_subordinate(e2)
    e5.become_subordinate(e4)
    e6.become_subordinate(e4)
    e7.become_subordinate(e5)
    assert e2.obtain_subordinates([4, 6]) == e1
    assert e2.get_direct_subordinates() == [e3, e4, e5, e6]
def test_obtain_subordinates_1_2() -> None:
    e1 = Employee(1, "1", "CEO", 15000, 1)
    e2 = Employee(2, "2", "Sub", 25000, 2)
    e3 = Employee(3, "3", "Sub", 50000, 3)
    e5 = Employee(5, "5", "Sub", 15000, 5)
    e6 = Employee(6, "6", "Sub", 30000, 6)
    e40 = Employee(40, "40", "Sub", 30000, 40)
    e2.become_subordinate(e1)
    e3.become_subordinate(e1)
    e6.become_subordinate(e3)
    e40.become_subordinate(e2)
    e5.become_subordinate(e2)
    head = e6.obtain_subordinates([1, 2])
    assert head.name == '3'
    assert len(head.get_direct_subordinates()) == 3
    assert head.get_direct_subordinates()[0].eid == 5
    assert head.get_direct_subordinates()[1].eid == 6
    assert head.get_direct_subordinates()[2].eid == 40
Example #6
0
def test_obtain_subordinates_simple() -> None:
    e1 = Leader(1, "Sarah", "CEO", 500000, 30, "Some Corp.")
    e2 = Employee(2, "Sandra", "Secretary", 20000, 30)
    e3 = Employee(3, "Sofia", "Manager", 25000, 40)
    e4 = Employee(4, "Senya", "Grunt", 5000, 30)
    e5 = Employee(5, "Sylvia", "Grunt", 5000, 40)
    e2.become_subordinate(e1)
    e3.become_subordinate(e1)
    e4.become_subordinate(e3)
    e5.become_subordinate(e3)
    new_head = e2.obtain_subordinates([3, 5])
    assert new_head == e1
    assert e2.get_direct_subordinates() == [e3, e5]
    assert e1.get_direct_subordinates() == [e2, e4]
    assert e3.get_superior() == e2
    assert e5.get_superior() == e2
    assert e2.get_superior() == e1
    assert e4.get_superior() == e1
Example #7
0
def test_obtain_subordinates_different_head() -> None:
    e1 = Leader(1, "Sarah", "CEO", 500000, 30, "Some Corp.")
    e2 = Employee(2, "Sandra", "Secretary", 20000, 30)
    e3 = Employee(3, "Sofia", "Manager", 25000, 40)
    e4 = Employee(4, "Senya", "Grunt", 5000, 30)
    e5 = Employee(5, "Sylvia", "Grunt", 5000, 40)
    e2.become_subordinate(e1)
    e3.become_subordinate(e1)
    e4.become_subordinate(e3)
    e5.become_subordinate(e3)
    new_head = e2.obtain_subordinates([1, 3])
    assert new_head.eid == 5
    # assert isinstance(new_head, Leader)
    new_subs = e2.get_direct_subordinates()
    assert new_subs[0].eid == 1
    assert new_subs[1].eid == 3
    assert new_head.get_direct_subordinates() == [e2, e4]
    assert new_subs[0].get_superior() == e2
    assert new_subs[1].get_superior() == e2
    assert e4.get_superior() == new_head
    assert e2.get_superior() == new_head