def setUp(self): """ Any code we want to run at the beginning of each test. """ print('setUp') self.emp_1 = Employee('Corey', 'Schafer', 50000) self.emp_2 = Employee('Sue', 'Smith', 60000)
def test_rent(self): item = Employee.searchItem(self, 1) client = Employee.searchClient(self, '118.008.212-66') r1 = Employee.rent(self, item, client) r2 = Employee.rent(self, item, client) self.assertEqual(r1, True) self.assertEqual(r2, False)
def test_searchClient(self): client = Employee.searchClient(self, "888.225.763-72") client2 = Employee.searchClient(self, "212") self.assertNotEqual(client, None) self.assertIn(client, globalContent.database.clientContainer) self.assertEqual(client2, None) self.assertNotIn(client2, globalContent.database.clientContainer)
def test_searchItem(self): item = Employee.searchItem(self, 1) item2 = Employee.searchItem(self, 999) self.assertNotEqual(item, None) self.assertIn(item, globalContent.database.itemsContainer) self.assertEqual(item2, None) self.assertNotIn(item2, globalContent.database.itemsContainer)
def setUp(self): self.emp1 = Employee('Jan', 'Bo', 2000) self.emp2 = Employee('Zenon', 'Nowak', 2000) self.mng = Manager('Zdzisław', 'Iksiński', 2000, employes=[ self.emp1, ])
def test_if_workday(self): workday = datetime.date(2019, 7, 12) weekend = datetime.date(2019, 7, 13) self.assertTrue( Employee.is_workday(workday) ) self.assertFalse( Employee.is_workday(weekend) )
def setUp(self): test_name = self.shortDescription() # load specific test fixture according to test routine's ShortDescription emp = Employee(self.load_fixtures()[test_name]) person_info_set = emp.get_personal_info() self.inst = Payslip(person_info_set) tax_rate_file_path = os.path.join( settings.TAX_RATE_BACKUP_PATH, settings.TAX_RATE_DEFAULT_FILENAME) self.tax = TaxRate(tax_rate_file_path).calculate_tax(emp.get_salary())
def setUp(self): self.instance = Employee( { 'first_name':'John', 'last_name':'Smith', 'annual_salary':'60012', 'super_rate':'9', 'start_date':'1/1/85'} ) test_name = self.shortDescription() print 'outstanding test= ', test_name
def test_createClient(self): Employee.createClient(self, first_name="Julia", last_name="Pereira", email="*****@*****.**", cpf="133.666.662-99", phone="986326282") client = Employee.searchClient(self, "133.666.662-99") self.assertNotEqual(client, None) self.assertIn(client, globalContent.database.clientContainer) self.assertEqual(client.first_name, "Julia") self.assertEqual(client.last_name, "Pereira") self.assertEqual(client.email, "*****@*****.**") self.assertEqual(client.phone, "986326282")
def test_updateItem(self): item = Employee.searchItem(self, 1) Employee.updateItem(self, item=item, item_name="item X", id_item=955, value=998, description="item X é bom", status="rented") item = Employee.searchItem(self, 955) self.assertEqual(item.item_name, "item X") self.assertEqual(item.id_item, 955) self.assertEqual(item.value, 998) self.assertEqual(item.description, "item X é bom") self.assertEqual(item.status, "rented")
def test_deleteClient(self): Employee.createClient(self, first_name="Julia", last_name="Pereira", email="*****@*****.**", cpf="133.666.662-99", phone="986326282") client = Employee.searchClient(self, "133.666.662-99") client2 = Employee.searchClient(self, "000.000.000-00") result1 = Employee.deleteClient(self, cpf="133.666.662-99") result2 = Employee.deleteClient(self, cpf="000.000.000-00") self.assertEqual(result1, True) self.assertEqual(result2, False) self.assertNotIn(client, globalContent.database.clientContainer) self.assertNotIn(client2, globalContent.database.clientContainer)
def test_updateClient(self): Employee.createClient(self, first_name="Julia", last_name="Pereira", email="*****@*****.**", cpf="133.666.662-99", phone="986326282") client = Employee.searchClient(self, "133.666.662-99") Employee.updateClient(self, client=client, first_name="Janaina", last_name="Pereira", email="*****@*****.**", cpf="444.444.222-88", phone="882211334") client = Employee.searchClient(self, "444.444.222-88") self.assertEqual(client.first_name, "Janaina") self.assertEqual(client.last_name, "Pereira") self.assertEqual(client.email, "*****@*****.**") self.assertEqual(client.cpf, "444.444.222-88") self.assertEqual(client.phone, "882211334")
class TestEmployee(unittest.TestCase): """desc!""" def setUp(self): self.instance = Employee( { 'first_name':'John', 'last_name':'Smith', 'annual_salary':'60012', 'super_rate':'9', 'start_date':'1/1/85'} ) test_name = self.shortDescription() print 'outstanding test= ', test_name def test_is_instance(self): """test if the instance exists""" self.assertIsInstance(self.instance,Employee) def test_assemble_full_name(self): """assemble_full_name should assemble the full name""" assert self.instance.assemble_full_name(self.instance.person,'.') == 'John.Smith' def test_assemble_full_name_default_delimeter(self): """assemble_full_name should assemble the full name and handle default delimeter""" assert self.instance.assemble_full_name(self.instance.person) == 'John.Smith' def test_assemble_full_name_missing_last_name(self): """assemble_full_name should assemble the full name and handle missing lastname""" test_fixture_1 = self.instance.person test_fixture_1['last_name'] = '' assert self.instance.assemble_full_name(test_fixture_1,'.') == 'John' def test_getting_personal_info(self): """correct info can be retrieved from the object""" assert self.instance.get_personal_info() == { 'first_name': 'John', 'last_name': 'Smith', 'super_rate': '9', 'annual_salary': 60012.0, 'full_name': 'John.Smith', 'start_date': '1/1/85'} def test_get_salary(self): """should be able to get correct salary from input object""" assert self.instance.get_salary() == float(self.instance.person['annual_salary']) def test_convert_salary(self): """should return: float format of the input salary""" input_salary = '50021' assert self.instance.convert_salary(input_salary) == float('50021') def test_compile_personal_info(self): """ it should take raw input data, and convert data in relevant fields to desirable formats.""" assert self.instance._compile_personal_info(self.instance.person) == { 'first_name': 'John', 'last_name': 'Smith', 'super_rate': '9', 'annual_salary': 60012.0, 'full_name': 'John.Smith', 'start_date': '1/1/85'}
def execute(self): e = Employee(self.emp_id, self.name, self.address) e.classification = self.make_classification() e.schedule = self.make_schedule() e.method = HoldMethod() PayrollDatabase.add_employee(self.emp_id, e)
def setUp(self): self.emp = Employee('Jan', 'Testowy', 3000) print( 'Initializing Employee Test object ', )
def setUp(self): self.emp = Employee('Jan', 'Testowy', 3000)
def change(self, employee: Employee): self.record_membership(employee) employee.affiliation = self.get_affiliation()
def __init__(self, first, last, pay, prog_lang): Employee.__init__(self, first, last, pay) self.prog_lang = prog_lang
class TestEmployee(unittest.TestCase): ### SET UP / TEAR DOWN ### @classmethod def setUpClass(cls): """ Any code we want to run just once upfront for entire set of tests. """ print('setupClass ') @classmethod def tearDownClass(cls): """ Any code we want to run just once upon finishing entire set of tests. """ print('teardownClass') def setUp(self): """ Any code we want to run at the beginning of each test. """ print('setUp') self.emp_1 = Employee('Corey', 'Schafer', 50000) self.emp_2 = Employee('Sue', 'Smith', 60000) def tearDown(self): """ Any code we want to run at the end of each test. """ print('tearDown\n') ### TESTS ### 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_fullname_setter(self): print('test_fullname_setter') self.emp_1.fullname = 'Jane Smith' self.emp_2.fullname = 'John Schafer' self.assertEqual(self.emp_1.fullname, 'Jane Smith') self.assertEqual(self.emp_2.fullname, 'John Schafer') def test_fullname_deleter(self): print('test_fullname_deleter') del self.emp_1.fullname del self.emp_2.fullname self.assertEqual(self.emp_1.fullname, 'None None') self.assertEqual(self.emp_2.fullname, 'None None') 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): """ Because this function depends on output of a get request, we don't want the test to fail if the website is down (or any reason other than our code being broken). Thus, we use the patch function as a context manager to generate a mocked result from the get request. """ with patch('src.employee.requests.get') as mocked_get: ### TRUE CASE ### 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') ### FALSE CASE ### 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!')
from src.developer import Developer from src.employee import Employee from src.manager import Manager dev_1 = Developer('Jianwei', 'Zhang', 40000, 'Python') mgr_1 = Manager('BJ', 'Lee', 100000, [dev_1]) dev_2 = Employee('First', "Last", 10000) print(isinstance(mgr_1, Employee))