snippets.txt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import unittest
  2. from employee import Employee
  3. class TestEmployee(unittest.TestCase):
  4. def test_email(self):
  5. emp_1 = Employee('Corey', 'Schafer', 50000)
  6. emp_2 = Employee('Sue', 'Smith', 60000)
  7. self.assertEqual(emp_1.email, 'Corey.Schafer@email.com')
  8. self.assertEqual(emp_2.email, 'Sue.Smith@email.com')
  9. emp_1.first = 'John'
  10. emp_2.first = 'Jane'
  11. self.assertEqual(emp_1.email, 'John.Schafer@email.com')
  12. self.assertEqual(emp_2.email, 'Jane.Smith@email.com')
  13. def test_fullname(self):
  14. emp_1 = Employee('Corey', 'Schafer', 50000)
  15. emp_2 = Employee('Sue', 'Smith', 60000)
  16. self.assertEqual(emp_1.fullname, 'Corey Schafer')
  17. self.assertEqual(emp_2.fullname, 'Sue Smith')
  18. emp_1.first = 'John'
  19. emp_2.first = 'Jane'
  20. self.assertEqual(emp_1.fullname, 'John Schafer')
  21. self.assertEqual(emp_2.fullname, 'Jane Smith')
  22. def test_apply_raise(self):
  23. emp_1 = Employee('Corey', 'Schafer', 50000)
  24. emp_2 = Employee('Sue', 'Smith', 60000)
  25. emp_1.apply_raise()
  26. emp_2.apply_raise()
  27. self.assertEqual(emp_1.pay, 52500)
  28. self.assertEqual(emp_2.pay, 63000)
  29. if __name__ == '__main__':
  30. unittest.main()
  31. ###### With Prints ######
  32. import unittest
  33. from employee import Employee
  34. class TestEmployee(unittest.TestCase):
  35. def setUp(self):
  36. print('setUp')
  37. self.emp_1 = Employee('Corey', 'Schafer', 50000)
  38. self.emp_2 = Employee('Sue', 'Smith', 60000)
  39. def tearDown(self):
  40. print('tearDown\n')
  41. def test_email(self):
  42. print('test_email')
  43. self.assertEqual(self.emp_1.email, 'Corey.Schafer@email.com')
  44. self.assertEqual(self.emp_2.email, 'Sue.Smith@email.com')
  45. self.emp_1.first = 'John'
  46. self.emp_2.first = 'Jane'
  47. self.assertEqual(self.emp_1.email, 'John.Schafer@email.com')
  48. self.assertEqual(self.emp_2.email, 'Jane.Smith@email.com')
  49. def test_fullname(self):
  50. print('test_fullname')
  51. self.assertEqual(self.emp_1.fullname, 'Corey Schafer')
  52. self.assertEqual(self.emp_2.fullname, 'Sue Smith')
  53. self.emp_1.first = 'John'
  54. self.emp_2.first = 'Jane'
  55. self.assertEqual(self.emp_1.fullname, 'John Schafer')
  56. self.assertEqual(self.emp_2.fullname, 'Jane Smith')
  57. def test_apply_raise(self):
  58. print('test_apply_raise')
  59. self.emp_1.apply_raise()
  60. self.emp_2.apply_raise()
  61. self.assertEqual(self.emp_1.pay, 52500)
  62. self.assertEqual(self.emp_2.pay, 63000)
  63. if __name__ == '__main__':
  64. unittest.main()
  65. ###### setUpClass and tearDownClass ######
  66. @classmethod
  67. def setUpClass(cls):
  68. print('setupClass')
  69. @classmethod
  70. def tearDownClass(cls):
  71. print('teardownClass')
  72. ##### Mocking #####
  73. def monthly_schedule(self, month):
  74. response = requests.get(f'http://company.com/{self.last}/{month}')
  75. if response.ok:
  76. return response.text
  77. else:
  78. return 'Bad Response!'