Пример #1
0
class TestEmployee(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        print("\nInside 'setUpClass(cls)'")

    @classmethod
    def tearDownClass(cls):
        print("\nInside 'tearDownClass(cls)'")

    def setUp(self) -> None:
        print("\nInside 'setUp(self) ...'")
        self.emp1 = Employee('Jane', 'Doe', 100000)
        self.emp2 = Developer('John', 'Doe', 100000)

    def tearDown(self) -> None:
        print("Inside 'tearDown(self) ...'")
        pass

    def test_email(self):
        print("Inside 'test_email(self) ...'")
        self.assertEqual(self.emp1.email, '*****@*****.**')

        self.emp2.first = 'James'
        self.assertEqual(self.emp2.email, '*****@*****.**')

    def test_fullname(self):
        print("Inside 'test_fullname(self) ...'")
        self.assertEqual(self.emp1.fullname, 'Jane Doe')
        self.emp1.first = 'Lena'
        self.assertEqual(self.emp1.fullname, 'Lena Doe')

    def test_raise(self):
        print("Inside 'test_raise(self) ...'")
        self.emp1.apply_raise()
        self.emp2.apply_raise()
        self.assertEqual(self.emp1.pay, 120000)
        self.assertEqual(self.emp2.pay, 130000)

    def test_monthly_scheduled(self):
        # mock object where it's used (employee class)
        with patch('employee.requests.get') as mocked_get:
            mocked_get.return_value.ok = True
            mocked_get.return_value.text = 'Success'

            schedule = self.emp1.monthly_schedule('May')
            mocked_get.assert_called_with('http://company.com/Doe/May')
            self.assertEqual(schedule, 'Success')

            mocked_get.return_value.ok = False

            schedule = self.emp2.monthly_schedule('June')
            mocked_get.assert_called_with('http://company.com/Doe/June')
            self.assertEqual(schedule, 'Bad Response!')
class DeveloperTestCase(unittest.TestCase):
    """Class to Test Developer Class"""
    def setUp(self):
        self.developer = Developer('Test', 'Name', 100, 'Python')

    def test_developer_instance(self):
        self.assertEqual(self.developer.language, 'Python',
                         'Class not instantiating properly')

    def test_company_email(self):
        self.assertEqual(self.developer.company_email(),
                         '*****@*****.**',
                         'Something wrong with the company_email method')

    def test_encapsulation(self):
        with self.assertRaises(AttributeError):
            self.developer.__change_language('C++')
Пример #3
0
from employee import Employee, Developer, Manager

# Instantiate a new developer with Python as the coding language
dev_1 = Developer('Corey', 'Schafer', 50000, '*****@*****.**',
                  'Python')

# Instantiate a new manager as a manager of dev_1
mgr_1 = Manager('Sue', 'Smith', 90000, '', [dev_1])

# print the employees array assigned to mgr_1
print(mgr_1.employees)

# print the email attribute of mgr_1, this is empty
print(mgr_1.email)

# print the entire list of employees assigned to manager 1
mgr_1.print_emps()

# Print a True/False statement to test if Manager is a subclass of the Employee class
print(issubclass(Manager, Employee))
Пример #4
0
print("\n Creating employee instance using classmethod: ")
emp3_str = 'Steve-Smith-120000'
print("String being passed: {}".format(emp3_str))
emp3 = Employee.from_string(emp3_str)
print(f'New employee full name: {emp3.full_name}')

# Looking at static methods
print("\n Using static method to check weekday: ")
import datetime
today = datetime.datetime.now()
print(f'Today\'s date: {today}')
print(f'Is today a weekday?  Computer says: {Employee.is_workday(today)}')

# Create developer
dev1 = Developer('Childish', 'Gambino', '1000000', 'fortran')
print("\n New dev has joined the dev team: ")
print(f'Name: {dev1.full_name}')
print(f'Email: {dev1.email}')
print(f'Salary: {dev1.salary}')
print(f'Language: {dev1.language}')
print(f'Employee Count: {Developer.num_of_emps}')
print(f'Number of Devs: {Developer.num_of_devs}')

dev2 = Developer('Paul', 'Kalkbrenner', '150000', 'C++')
print("\n New dev has joined the dev team: ")
print(f'Name: {dev2.full_name}')
print(f'Email: {dev2.email}')
print(f'Salary: {dev2.salary}')
print(f'Language: {dev2.language}')
print(f'Employee Count: {Developer.num_of_emps}')
Пример #5
0
 def setUp(self) -> None:
     print("\nInside 'setUp(self) ...'")
     self.emp1 = Employee('Jane', 'Doe', 100000)
     self.emp2 = Developer('John', 'Doe', 100000)
 def setUp(self):
     self.developer = Developer('Test', 'Name', 100, 'Python')
 def setUp(self):
     self.manager = Manager('Test', 'Name', 100)
     self.employee = Developer('Test1', 'Name1', 100, 'Java')
Пример #8
0
from employee import Employee, Developer

# Instantiate two employees
emp_1 = Employee('Corey', 'Schafer', 50000, '*****@*****.**')
emp_2 = Employee('Test', 'User', 60000, '*****@*****.**')

# Instantiate two new developers (Developer is a subclass of Employee)
dev_1 = Developer('Corey', 'Schafer', 50000, '*****@*****.**',
                  'Python')
dev_2 = Developer('Test', 'User', 60000, '*****@*****.**', 'Java')

# Print the programming language for dev_1
print(dev_1.prog_lang)

# Print a True/False statement to test if mgr_1 is an instance of the Developer class
print(isinstance(mgr_1, Developer))