GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — code_snippets/Python-Unit-Testing/test_employee.py at master · Roopa28/code_snippets Expand file tree/ Copy pathtest_employee.pyMore file actions 71 lines (51 loc) · 2.1 KB / Copy pathtest_employee.pyFile metadata and controls71 lines (51 loc) · 2.1 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 import unittest from unittest.mock import patch from employee import Employee 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.emp_1.first = 'John' self.emp_2.first = 'Jane' 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.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!') if __name__ == '__main__': unittest.main() |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |