def test_applyRaise(self):
        e1 = Employee('Corey', 'Schafer', 50000)
        e2 = Employee('Sue', 'Smith', 60000)

        e1.applyRaise()
        e2.applyRaise()

        self.assertEqual(e1.pay, 52500)
        self.assertEqual(e2.pay, 63000)
Example #2
0
class TestEmployee(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        print('setUpClass')

    @classmethod
    def tearDownClass(cls):
        print('tearDownClass')

    #set up before each test
    def setUp(self):
        print('setUp')
        self.emp1 = Employee('Danny', 'Wu', 1000)
        self.emp2 = Employee('Henry', 'Huang', 2000)

    #tear down after each test
    def tearDown(self):
        print('tearDown')

    @unittest.skip("Don't run this case")
    def test_fullname(self):
        self.assertEqual(self.emp1.fullname, 'Danny Wu')
        self.assertEqual(self.emp2.fullname, 'Henry Huang')

    def test_applyRaise(self):
        self.emp1.applyRaise()
        self.emp2.applyRaise()
        self.assertEqual(self.emp1.pay, 1050)
        self.assertEqual(self.emp2.pay, 2100)

    def test_pos(self):
        self.emp1.setPos('CTO')
        self.assertEqual(self.emp1.getPos(), 'CTO')

        with self.assertRaises(ValueError):
            self.emp1.setPos(123)
Example #3
0
from employee import Employee

#Manual Test

emp1 = Employee(100, "John Smith", 45000)
print(emp1)
print("Id: " + str(emp1.getId()))
print("Name:" + emp1.getName())
print("Salary: " + str(emp1.getSalary()))
emp1.applyRaise()
print("New Salary: " + str(emp1.getSalary()))

for a in emp1.getName():
    print(a)

#unittest

import unittest


class test_Employee(unittest.TestCase):

    emp2 = Employee(101, "Mike Dane", 50000)

    def setUp(self):
        super().setUp()
        emp3 = Employee(101, "Mike Dane", 50000)

    def test_getName(self):
        self.assertEqual(self.emp2.getName(), "Mike Dane")
        self.assertIn("Mike", self.emp2.getName())
Example #4
0
class TestEmployee(unittest.TestCase):
    
    @classmethod
    def setUpClass(cls):
        print('setUp')
    
    @classmethod
    def tearDownClass(cls):
        print('tearDown')        
    
    
    def setUp(self):
        self.emp_1=Employee('Abhishek','Bhave',50000)
        self.emp_2=Employee('Rohan','Nayak',60000)
         
    def tearDown(self):
        pass
        
        
    
    def test_email(self):
        
        self.assertEqual(self.emp_1.email,'*****@*****.**')
        self.assertEqual(self.emp_2.email,'*****@*****.**')
        
        self.emp_1.first='Thomas'
        self.emp_2.first='Omkar'
        
        self.assertEqual(self.emp_1.email,'*****@*****.**')
        self.assertEqual(self.emp_2.email,'*****@*****.**')
        
    def test_fullname(self):
               
        self.assertEqual(self.emp_1.fullname,'Abhishek Bhave')
        self.assertEqual(self.emp_2.fullname,'Rohan Nayak')
        
        self.emp_1.last='Doe'
        self.emp_2.last='Nair'
        
        self.assertEqual(self.emp_1.fullname,'Abhishek Doe')
        self.assertEqual(self.emp_2.fullname,'Rohan Nair')
    
    def test_applyRaise(self):
        
        self.emp_1.applyRaise()
        self.emp_2.applyRaise()

        self.assertEqual(self.emp_1.pay,52500)
        self.assertEqual(self.emp_2.pay,63000)
        
    
    
    def test_monthly_schedule(self):
        with patch('employee.requests.get') as mocked_get:
           mocked_get.return_value.ok=True
           mocked_get.return_value.text='Success'
           
           schedule=self.emp_1.monthly_schedule('May')
           mocked_get.assert_called_with('http://company.com/Bhave/May')
           self.assertEqual(schedule,'Success')
           
           
           mocked_get.return_value.ok=False
           
           schedule=self.emp_2.monthly_schedule('June')
           mocked_get.assert_called_with('http://company.com/Nayak/June')
           self.assertEqual(schedule,'Bad Response')