-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemployee.py
More file actions
executable file
·35 lines (26 loc) · 1014 Bytes
/
employee.py
File metadata and controls
executable file
·35 lines (26 loc) · 1014 Bytes
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
import requests
from unittest.mock import patch #we can use patch as a decorater or as a context manager
# Patch wil allow us to mock a object during a test and then the
#object is atumatically restored after the test is run
class Employee:
raise_amount = 1.05
def __init__(self,first,last,pay):
self.first =first
self.last = last
self.pay = pay
@property
def fullname(self):
return '{} {}'.format(self.first,self.last)
@property
def email(self):
return '{}.{}@email.com'.format(self.first,self.last)
def apply_raise(self):
self.pay = int(self.pay * self.raise_amount)
# Mocking Method :
# you want to get some info from web but website is down so your function will fail, so to avoid this
def monthly_schedule(self, month):
response = requests.get(f'http://company.comm/{self.last}/{month}')
if response.ok:
return response.text
else:
return 'Bad Requests'