def test_max_length_on_employee_skills(self): test_employee = Employee(last_name='test', first_name='test', job_title='test', job_description='test', bio='test', skills='test') test_employee.skills = 't' * 1001 with self.assertRaises(ValidationError): test_employee.full_clean() test_employee.save()
def test_no_empty_strings_in_employee_skills(self): test_employee = Employee(last_name='test', first_name='test', job_title='test', job_description='test', bio='test', skills='test') test_employee.skills = '' with self.assertRaises(ValidationError): test_employee.full_clean() test_employee.save()
def test_can_create_employee(self): # arrange test_employee = Employee(last_name='test', first_name='test', job_title='test', job_description='test', bio='test', skills='test') # act test_employee.full_clean() test_employee.save() test_employee_from_db = Employee.objects.get(pk=1) # assert self.assertIsInstance(test_employee_from_db, Employee)
def test_employee_job_title_can_be_overwritten(self): test_employee = Employee(last_name='test', first_name='test', job_title='test', job_description='test', bio='test', skills='test') test_employee.full_clean() test_employee.save() changed_string = "CHANGED" expected = changed_string test_employee.job_title = changed_string test_employee.full_clean test_employee.save() test_employee_from_db = Employee.objects.get(pk=1) self.assertEqual(expected, test_employee_from_db.job_title)
def test_employee_data_inserts_correctly(self): test_employee = Employee(last_name='test', first_name='test', job_title='test', job_description='test', bio='test', skills='test') test_employee.full_clean() test_employee.save() expected = 'test' test_employee_from_db = Employee.objects.get(pk=1) for attr, value in test_employee_from_db.__dict__.items(): if attr == '_state' or attr == 'id': # Exclude auto generated attributes continue else: self.assertEqual(expected, value)
def test_employee_duplicate_last_name_different_first_name_passes(self): test_employee_1 = Employee(last_name='LAST', first_name='FIRST', job_title='test', job_description='test', bio='test', skills='test') test_employee_1.full_clean() test_employee_1.save() test_employee_2 = Employee(last_name='LAST', first_name='DIFFERENT', job_title='test', job_description='test', bio='test', skills='test') with self.assertRaises(ValidationError): test_employee_2.full_clean() test_employee_2.save()