Beispiel #1
0
class TestingEmployee(unittest.TestCase):
    i = 1

    @classmethod
    def setUpClass(cls):
        print("setUpClass -> Appears at the top\n")

    @classmethod
    def tearDownClass(cls):
        print("tearDownClass -> Appears at the bottom\n")

    def setUp(self):
        self.emp_1 = Employee('Pareksha', 'Manchanda', 100)
        self.emp_2 = Employee('Bhaiya', 'Manchanda', 200)

    def tearDown(self):
        print('Test {} passed'.format(TestingEmployee.i))
        TestingEmployee.i += 1

    def test_fullname(self):
        print("Running test on fullname method")
        self.assertEqual(self.emp_1.full_name, 'Pareksha Manchanda')
        self.assertEqual(self.emp_2.full_name, 'Bhaiya Manchanda')

    def test_email(self):
        print('Running test on email method')
        self.assertEqual(self.emp_1.email, '*****@*****.**')
        self.assertEqual(self.emp_2.email, '*****@*****.**')

    def test_raise(self):
        print('Running test on raise amount method')
        self.assertEqual(self.emp_1.apply_raise(), 105)
        self.assertEqual(self.emp_2.apply_raise(), 210)
Beispiel #2
0
class SimpleTestCase(unittest.TestCase):
    def setUp(self):
        """Call before every test case."""
        self.emp = Employee("Lin", 10000)
        self.emp2 = Employee("Jun", 20000)

    def tearDown(self):
        """Call after every test case."""
        del self.emp
        del self.emp2

    def testGetName(self):
        """Test case A. note that all test method names must begin with 'test.'"""
        self.assertEqual(self.emp.getName(), "Lin")  # test getName() whether return correct answer"
        self.assertNotEqual(self.emp2.getName(), "Lin")

    def testGetSalary(self):
        """test case B"""
        self.assertEqual(self.emp2.getSalary(), 20000)  # test getSalary() whether return correct answer
        self.assertNotEqual(self.emp.getSalary(), 20000)
Beispiel #3
0
class SimpleTestCase(unittest.TestCase):
    def setUp(self):
        """Call before every test case."""
        self.emp = Employee('Lin', 10000)
        self.emp2 = Employee('Jun', 20000)

    def tearDown(self):
        """Call after every test case."""
        del self.emp
        del self.emp2

    def testGetName(self):
        """Test case A. note that all test method names must begin with 'test.'"""
        self.assertEqual(
            self.emp.getName(),
            'Lin')  # test getName() whether return correct answer"
        self.assertNotEqual(self.emp2.getName(), 'Lin')

    def testGetSalary(self):
        """test case B"""
        self.assertEqual(
            self.emp2.getSalary(),
            20000)  # test getSalary() whether return correct answer
        self.assertNotEqual(self.emp.getSalary(), 20000)
Beispiel #4
0
class TestEmployee(unittest.TestCase):
    """for Emplyee_class"""
    def setUp(self):
        self.my_information = Employee('lay', 'chow', 10000)

    def test_give_default_raise(self):

        self.my_information.give_raise()

        self.assertEqual(self.my_information.information_display(),
                         '\nName: Lay Chow 15000')

    def test_give_custon_raise(self):
        self.my_information.give_raise(10000)
        self.assertEqual(self.my_information.information_display(),
                         "\nName: Lay Chow 20000")
Beispiel #5
0
 def setUp(self):
     self.my_information = Employee('lay', 'chow', 10000)
Beispiel #6
0
import sqlite3
from Employee_class import Employee
conn = sqlite3.connect(':memory:')
# conn = sqlite3.connect('employee.db')
c = conn.cursor()
c.execute("""CREATE  TABLE employees(
             first text,
             last text,
             pay integer
            )""")

emp_1 = Employee('John', 'Doe', 80000)
emp_2 = Employee('Jane', 'Doe', 90000)
print(emp_1.first)
print(emp_1.last)
# c.execute("INSERT INTO employees VALUES ('Mary', 'Schafer', 20000)")
# c.execute("INSERT INTO employees VALUES ('{}', '{}', {})".format(emp_1.first,emp_1.last,emp_1.pay))
c.execute("INSERT INTO employees VALUES (?, ?, ?)",
          (emp_1.first, emp_1.last, emp_1.pay))
conn.commit()
c.execute("INSERT INTO employees VALUES (:first, :last, :pay)", {
    'first': emp_2.first,
    'last': emp_2.last,
    'pay': emp_2.pay
})
conn.commit()
# c.execute("SELECT * FROM employees WHERE last = 'Doe'")
# c.execute("SELECT * FROM employees WHERE last = ?",('Schafer',))
c.execute("SELECT * FROM employees WHERE last = :l1", {'l1': 'Doe'})
print(c.fetchall())
conn.commit()
Beispiel #7
0
 def setUp(self):
     self.emp_1 = Employee('Pareksha', 'Manchanda', 100)
     self.emp_2 = Employee('Bhaiya', 'Manchanda', 200)
Beispiel #8
0
 def setUp(self):
     """Call before every test case."""
     self.emp = Employee('Lin', 10000)
     self.emp2 = Employee('Jun', 20000)
Beispiel #9
0
 def testGetEmpCount(self):
     """ getEmpCount() is a static method """
     self.assertEqual(Employee.getEmpCount(),
                      1)  # test getEmpCount() whether return correct answer
Beispiel #10
0
 def setUp(self):
     self.emp3 = Employee('jiang', 30000)
Beispiel #11
0
 def setUp(self):
     """Call before every test case."""
     self.emp = Employee("Lin", 10000)
     self.emp2 = Employee("Jun", 20000)
Beispiel #12
0
 def testGetEmpCount(self):
     """ getEmpCount() is a static method """
     self.assertEqual(Employee.getEmpCount(), 1)  # test getEmpCount() whether return correct answer
class TestEmployee(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        print('setupClass')

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

    def setUp(self):
        print('setUp')
        self.emp_1 = Employee('Corey', 'Schafer', 50000)
        self.emp_2 = Employee('Sue', 'Smith', 60000)

    def tearDown(self):
        print('tearDown\n')

    def test_email(self):
        print('test_email')
        self.assertEqual(self.emp_1.email, '*****@*****.**')
        self.assertEqual(self.emp_2.email, '*****@*****.**')

        self.emp_1.first = 'John'
        self.emp_2.first = 'Jane'

        self.assertEqual(self.emp_1.email, '*****@*****.**')
        self.assertEqual(self.emp_2.email, '*****@*****.**')

    def test_fullname(self):
        print('test_fullname')
        self.assertEqual(self.emp_1.fullname, 'Corey Schafer')
        self.assertEqual(self.emp_2.fullname, 'Sue Smith')

        self.emp_1.first = 'John'
        self.emp_2.first = 'Jane'

        self.assertEqual(self.emp_1.fullname, 'John Schafer')
        self.assertEqual(self.emp_2.fullname, 'Jane Smith')

    def test_apply_raise(self):
        print('test_apply_raise')
        self.emp_1.apply_raise()
        self.emp_2.apply_raise()

        self.assertEqual(self.emp_1.pay, 52500)
        self.assertEqual(self.emp_2.pay, 63000)

    def test_monthly_schedule(self):
        with patch('Employee_class.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/Schafer/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/Smith/June')
            self.assertEqual(schedule, 'Bad Response!')
 def setUp(self):
     print('setUp')
     self.emp_1 = Employee('Corey', 'Schafer', 50000)
     self.emp_2 = Employee('Sue', 'Smith', 60000)